universal-audit-logs 1.0.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- universal_audit_logs-1.0.2/LICENSE +21 -0
- universal_audit_logs-1.0.2/PKG-INFO +225 -0
- universal_audit_logs-1.0.2/README.md +177 -0
- universal_audit_logs-1.0.2/audit_sdk/__init__.py +67 -0
- universal_audit_logs-1.0.2/audit_sdk/audit.py +544 -0
- universal_audit_logs-1.0.2/audit_sdk/config/__init__.py +10 -0
- universal_audit_logs-1.0.2/audit_sdk/config/settings.py +224 -0
- universal_audit_logs-1.0.2/audit_sdk/core/__init__.py +12 -0
- universal_audit_logs-1.0.2/audit_sdk/core/event_bus.py +130 -0
- universal_audit_logs-1.0.2/audit_sdk/core/exceptions.py +209 -0
- universal_audit_logs-1.0.2/audit_sdk/core/interfaces.py +251 -0
- universal_audit_logs-1.0.2/audit_sdk/middleware/__init__.py +38 -0
- universal_audit_logs-1.0.2/audit_sdk/middleware/auto_audit.py +781 -0
- universal_audit_logs-1.0.2/audit_sdk/middleware/base.py +11 -0
- universal_audit_logs-1.0.2/audit_sdk/middleware/enhanced.py +673 -0
- universal_audit_logs-1.0.2/audit_sdk/middleware/fastapi.py +782 -0
- universal_audit_logs-1.0.2/audit_sdk/models/__init__.py +23 -0
- universal_audit_logs-1.0.2/audit_sdk/models/audit_event.py +545 -0
- universal_audit_logs-1.0.2/audit_sdk/models/enums.py +76 -0
- universal_audit_logs-1.0.2/audit_sdk/plugins/__init__.py +28 -0
- universal_audit_logs-1.0.2/audit_sdk/plugins/base.py +11 -0
- universal_audit_logs-1.0.2/audit_sdk/plugins/registry.py +183 -0
- universal_audit_logs-1.0.2/audit_sdk/py.typed +0 -0
- universal_audit_logs-1.0.2/audit_sdk/security/__init__.py +25 -0
- universal_audit_logs-1.0.2/audit_sdk/security/encryption.py +138 -0
- universal_audit_logs-1.0.2/audit_sdk/security/signing.py +133 -0
- universal_audit_logs-1.0.2/audit_sdk/transport/__init__.py +21 -0
- universal_audit_logs-1.0.2/audit_sdk/transport/base.py +11 -0
- universal_audit_logs-1.0.2/audit_sdk/transport/database.py +425 -0
- universal_audit_logs-1.0.2/audit_sdk/transport/kafka.py +130 -0
- universal_audit_logs-1.0.2/audit_sdk/transport/mongodb.py +240 -0
- universal_audit_logs-1.0.2/audit_sdk/transport/rest.py +274 -0
- universal_audit_logs-1.0.2/audit_sdk/transport/simple_database.py +200 -0
- universal_audit_logs-1.0.2/audit_sdk/utils/__init__.py +12 -0
- universal_audit_logs-1.0.2/audit_sdk/utils/logger.py +130 -0
- universal_audit_logs-1.0.2/audit_sdk/utils/retry.py +117 -0
- universal_audit_logs-1.0.2/audit_sdk/utils/retry_manager.py +485 -0
- universal_audit_logs-1.0.2/audit_sdk/utils/serializer.py +177 -0
- universal_audit_logs-1.0.2/pyproject.toml +151 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Sumanth <sumanth6633@gmail.com>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: universal-audit-logs
|
|
3
|
+
Version: 1.0.2
|
|
4
|
+
Summary: Universal Audit Framework (UAF) — A production-ready, framework-agnostic audit logging SDK for Python.
|
|
5
|
+
License: MIT
|
|
6
|
+
License-File: LICENSE
|
|
7
|
+
Keywords: audit,logging,sdk,fastapi,middleware,postgresql,observability
|
|
8
|
+
Author: Sumanth
|
|
9
|
+
Author-email: sumanth6633@gmail.com
|
|
10
|
+
Requires-Python: >=3.12,<4.0
|
|
11
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
12
|
+
Classifier: Framework :: FastAPI
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
19
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
20
|
+
Classifier: Topic :: System :: Logging
|
|
21
|
+
Classifier: Typing :: Typed
|
|
22
|
+
Provides-Extra: all
|
|
23
|
+
Provides-Extra: fastapi
|
|
24
|
+
Provides-Extra: kafka
|
|
25
|
+
Provides-Extra: mongodb
|
|
26
|
+
Provides-Extra: postgres
|
|
27
|
+
Provides-Extra: sqlite
|
|
28
|
+
Requires-Dist: aiokafka (>=0.9,<0.10) ; extra == "kafka" or extra == "all"
|
|
29
|
+
Requires-Dist: aiosqlite (>=0.20,<0.21) ; extra == "sqlite" or extra == "all"
|
|
30
|
+
Requires-Dist: asyncpg (>=0.29,<0.30) ; extra == "postgres" or extra == "all"
|
|
31
|
+
Requires-Dist: cryptography (>=42.0,<43.0)
|
|
32
|
+
Requires-Dist: fastapi (>=0.100,<0.101) ; extra == "fastapi" or extra == "all"
|
|
33
|
+
Requires-Dist: httpx (>=0.27,<0.28)
|
|
34
|
+
Requires-Dist: motor (>=3.3,<4.0) ; extra == "mongodb" or extra == "all"
|
|
35
|
+
Requires-Dist: pydantic (>=2.7,<3.0)
|
|
36
|
+
Requires-Dist: pydantic-settings (>=2.3,<3.0)
|
|
37
|
+
Requires-Dist: sqlalchemy[asyncio] (>=2.0,<3.0) ; extra == "postgres" or extra == "sqlite" or extra == "all"
|
|
38
|
+
Requires-Dist: starlette (>=0.27) ; extra == "fastapi" or extra == "all"
|
|
39
|
+
Requires-Dist: structlog (>=24.1,<25.0)
|
|
40
|
+
Requires-Dist: tenacity (>=8.3,<9.0)
|
|
41
|
+
Project-URL: Bug Tracker, https://github.com/rakurthisumanth/audit_logs/issues
|
|
42
|
+
Project-URL: Changelog, https://github.com/rakurthisumanth/audit_logs/blob/main/CHANGELOG.md
|
|
43
|
+
Project-URL: Documentation, https://github.com/rakurthisumanth/audit_logs#readme
|
|
44
|
+
Project-URL: Homepage, https://github.com/rakurthisumanth/audit_logs
|
|
45
|
+
Project-URL: Repository, https://github.com/rakurthisumanth/audit_logs
|
|
46
|
+
Description-Content-Type: text/markdown
|
|
47
|
+
|
|
48
|
+
# Universal Audit Framework (UAF) SDK
|
|
49
|
+
|
|
50
|
+
[](https://pypi.org/project/universal-audit-logs/)
|
|
51
|
+
[](https://www.python.org/downloads/)
|
|
52
|
+
[](https://opensource.org/licenses/MIT)
|
|
53
|
+
|
|
54
|
+
A production-ready audit logging SDK for Python. Auto-captures WHO did WHAT, WHEN — with zero code in your endpoints.
|
|
55
|
+
|
|
56
|
+
---
|
|
57
|
+
|
|
58
|
+
## Installation
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
# With FastAPI middleware + PostgreSQL (most common)
|
|
62
|
+
pip install universal-audit-logs[fastapi,postgres]
|
|
63
|
+
|
|
64
|
+
# Core only (REST transport)
|
|
65
|
+
pip install universal-audit-logs
|
|
66
|
+
|
|
67
|
+
# All transports
|
|
68
|
+
pip install universal-audit-logs[all]
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
---
|
|
72
|
+
|
|
73
|
+
## FastAPI Middleware Setup (Recommended)
|
|
74
|
+
|
|
75
|
+
```python
|
|
76
|
+
from fastapi import FastAPI
|
|
77
|
+
from starlette.middleware.sessions import SessionMiddleware
|
|
78
|
+
from audit_sdk.middleware.enhanced import (
|
|
79
|
+
EnhancedAuditMiddleware,
|
|
80
|
+
EnhancedAuditConfig,
|
|
81
|
+
)
|
|
82
|
+
from audit_sdk.transport.simple_database import SimpleAuditTransport
|
|
83
|
+
|
|
84
|
+
app = FastAPI()
|
|
85
|
+
|
|
86
|
+
# 1. Configure audit transport (writes to PostgreSQL)
|
|
87
|
+
transport = SimpleAuditTransport.for_postgres(
|
|
88
|
+
host="localhost",
|
|
89
|
+
port=5432,
|
|
90
|
+
database="audit_db",
|
|
91
|
+
username="your_user",
|
|
92
|
+
password="your_password",
|
|
93
|
+
)
|
|
94
|
+
|
|
95
|
+
# 2. Add audit middleware
|
|
96
|
+
app.add_middleware(
|
|
97
|
+
EnhancedAuditMiddleware,
|
|
98
|
+
transport=transport,
|
|
99
|
+
config=EnhancedAuditConfig(
|
|
100
|
+
capture_request_body=True,
|
|
101
|
+
excluded_paths=frozenset({"/health", "/docs", "/openapi.json"}),
|
|
102
|
+
),
|
|
103
|
+
)
|
|
104
|
+
|
|
105
|
+
# 3. Add session middleware (for user tracking)
|
|
106
|
+
app.add_middleware(SessionMiddleware, secret_key="your-secret-key")
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
**Done.** Every endpoint is now automatically audited. No `audit.log()` calls needed anywhere.
|
|
110
|
+
|
|
111
|
+
---
|
|
112
|
+
|
|
113
|
+
## User Detection
|
|
114
|
+
|
|
115
|
+
The middleware auto-detects the logged-in user. Provide a `UserProvider`:
|
|
116
|
+
|
|
117
|
+
```python
|
|
118
|
+
from audit_sdk.middleware.enhanced import EnhancedAuditMiddleware
|
|
119
|
+
|
|
120
|
+
class SessionUserProvider:
|
|
121
|
+
async def get_user(self, request) -> dict | None:
|
|
122
|
+
user = request.session.get("current_user")
|
|
123
|
+
if user:
|
|
124
|
+
return {
|
|
125
|
+
"user_id": user["id"],
|
|
126
|
+
"username": user["username"],
|
|
127
|
+
"email": user.get("email", ""),
|
|
128
|
+
"roles": user.get("roles", []),
|
|
129
|
+
}
|
|
130
|
+
return None
|
|
131
|
+
|
|
132
|
+
app.add_middleware(
|
|
133
|
+
EnhancedAuditMiddleware,
|
|
134
|
+
transport=transport,
|
|
135
|
+
user_provider=SessionUserProvider(),
|
|
136
|
+
config=EnhancedAuditConfig(capture_request_body=True),
|
|
137
|
+
)
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
---
|
|
141
|
+
|
|
142
|
+
## What Gets Captured Automatically
|
|
143
|
+
|
|
144
|
+
| Field | Example |
|
|
145
|
+
|-------|---------|
|
|
146
|
+
| `performed_by` | `Sumanth` |
|
|
147
|
+
| `action` | `CREATE`, `UPDATE`, `DELETE`, `LOGIN` |
|
|
148
|
+
| `action_message` | `Sumanth created Employee John` |
|
|
149
|
+
| `functionality` | `Employee Management` |
|
|
150
|
+
| `performed_on` | `Employee #1` |
|
|
151
|
+
| `performed_at` | `2025-07-08 10:30:00+00` |
|
|
152
|
+
| `previous_state` | `{"salary": 100000}` |
|
|
153
|
+
| `current_state` | `{"salary": 120000}` |
|
|
154
|
+
| `changed_fields` | `{"salary": {"old": 100000, "new": 120000}}` |
|
|
155
|
+
|
|
156
|
+
---
|
|
157
|
+
|
|
158
|
+
## Transport Options
|
|
159
|
+
|
|
160
|
+
### PostgreSQL (recommended)
|
|
161
|
+
|
|
162
|
+
```python
|
|
163
|
+
from audit_sdk.transport.simple_database import SimpleAuditTransport
|
|
164
|
+
|
|
165
|
+
transport = SimpleAuditTransport.for_postgres(
|
|
166
|
+
host="localhost", port=5432,
|
|
167
|
+
database="audit_db", username="user", password="pass",
|
|
168
|
+
)
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
### SQLite
|
|
172
|
+
|
|
173
|
+
```python
|
|
174
|
+
transport = SimpleAuditTransport.for_sqlite(path="./audit.db")
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
### MongoDB
|
|
178
|
+
|
|
179
|
+
```bash
|
|
180
|
+
pip install universal-audit-logs[mongodb]
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
```python
|
|
184
|
+
from audit_sdk.transport.mongodb import MongoDBTransport
|
|
185
|
+
|
|
186
|
+
transport = MongoDBTransport(uri="mongodb://localhost:27017", database="audit_db")
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
### REST (HTTP collector)
|
|
190
|
+
|
|
191
|
+
```python
|
|
192
|
+
from audit_sdk import AuditClient, AuditSettings
|
|
193
|
+
|
|
194
|
+
settings = AuditSettings(endpoint="https://audit.example.com/api/v1/events")
|
|
195
|
+
audit = AuditClient(settings=settings)
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
---
|
|
199
|
+
|
|
200
|
+
## Audit Log Table (auto-created)
|
|
201
|
+
|
|
202
|
+
```sql
|
|
203
|
+
CREATE TABLE audit_log (
|
|
204
|
+
id VARCHAR(36) PRIMARY KEY,
|
|
205
|
+
performed_by TEXT NOT NULL,
|
|
206
|
+
action VARCHAR(100) NOT NULL,
|
|
207
|
+
action_message TEXT,
|
|
208
|
+
functionality VARCHAR(200) NOT NULL,
|
|
209
|
+
performed_on TEXT NOT NULL,
|
|
210
|
+
performed_at TIMESTAMPTZ NOT NULL,
|
|
211
|
+
previous_state JSONB,
|
|
212
|
+
current_state JSONB,
|
|
213
|
+
changed_fields JSONB,
|
|
214
|
+
http_context JSONB
|
|
215
|
+
);
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
---
|
|
219
|
+
|
|
220
|
+
## License
|
|
221
|
+
|
|
222
|
+
MIT - see [LICENSE](LICENSE)
|
|
223
|
+
|
|
224
|
+
Copyright (c) 2025 Sumanth
|
|
225
|
+
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
# Universal Audit Framework (UAF) SDK
|
|
2
|
+
|
|
3
|
+
[](https://pypi.org/project/universal-audit-logs/)
|
|
4
|
+
[](https://www.python.org/downloads/)
|
|
5
|
+
[](https://opensource.org/licenses/MIT)
|
|
6
|
+
|
|
7
|
+
A production-ready audit logging SDK for Python. Auto-captures WHO did WHAT, WHEN — with zero code in your endpoints.
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
# With FastAPI middleware + PostgreSQL (most common)
|
|
15
|
+
pip install universal-audit-logs[fastapi,postgres]
|
|
16
|
+
|
|
17
|
+
# Core only (REST transport)
|
|
18
|
+
pip install universal-audit-logs
|
|
19
|
+
|
|
20
|
+
# All transports
|
|
21
|
+
pip install universal-audit-logs[all]
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
## FastAPI Middleware Setup (Recommended)
|
|
27
|
+
|
|
28
|
+
```python
|
|
29
|
+
from fastapi import FastAPI
|
|
30
|
+
from starlette.middleware.sessions import SessionMiddleware
|
|
31
|
+
from audit_sdk.middleware.enhanced import (
|
|
32
|
+
EnhancedAuditMiddleware,
|
|
33
|
+
EnhancedAuditConfig,
|
|
34
|
+
)
|
|
35
|
+
from audit_sdk.transport.simple_database import SimpleAuditTransport
|
|
36
|
+
|
|
37
|
+
app = FastAPI()
|
|
38
|
+
|
|
39
|
+
# 1. Configure audit transport (writes to PostgreSQL)
|
|
40
|
+
transport = SimpleAuditTransport.for_postgres(
|
|
41
|
+
host="localhost",
|
|
42
|
+
port=5432,
|
|
43
|
+
database="audit_db",
|
|
44
|
+
username="your_user",
|
|
45
|
+
password="your_password",
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
# 2. Add audit middleware
|
|
49
|
+
app.add_middleware(
|
|
50
|
+
EnhancedAuditMiddleware,
|
|
51
|
+
transport=transport,
|
|
52
|
+
config=EnhancedAuditConfig(
|
|
53
|
+
capture_request_body=True,
|
|
54
|
+
excluded_paths=frozenset({"/health", "/docs", "/openapi.json"}),
|
|
55
|
+
),
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
# 3. Add session middleware (for user tracking)
|
|
59
|
+
app.add_middleware(SessionMiddleware, secret_key="your-secret-key")
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
**Done.** Every endpoint is now automatically audited. No `audit.log()` calls needed anywhere.
|
|
63
|
+
|
|
64
|
+
---
|
|
65
|
+
|
|
66
|
+
## User Detection
|
|
67
|
+
|
|
68
|
+
The middleware auto-detects the logged-in user. Provide a `UserProvider`:
|
|
69
|
+
|
|
70
|
+
```python
|
|
71
|
+
from audit_sdk.middleware.enhanced import EnhancedAuditMiddleware
|
|
72
|
+
|
|
73
|
+
class SessionUserProvider:
|
|
74
|
+
async def get_user(self, request) -> dict | None:
|
|
75
|
+
user = request.session.get("current_user")
|
|
76
|
+
if user:
|
|
77
|
+
return {
|
|
78
|
+
"user_id": user["id"],
|
|
79
|
+
"username": user["username"],
|
|
80
|
+
"email": user.get("email", ""),
|
|
81
|
+
"roles": user.get("roles", []),
|
|
82
|
+
}
|
|
83
|
+
return None
|
|
84
|
+
|
|
85
|
+
app.add_middleware(
|
|
86
|
+
EnhancedAuditMiddleware,
|
|
87
|
+
transport=transport,
|
|
88
|
+
user_provider=SessionUserProvider(),
|
|
89
|
+
config=EnhancedAuditConfig(capture_request_body=True),
|
|
90
|
+
)
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
---
|
|
94
|
+
|
|
95
|
+
## What Gets Captured Automatically
|
|
96
|
+
|
|
97
|
+
| Field | Example |
|
|
98
|
+
|-------|---------|
|
|
99
|
+
| `performed_by` | `Sumanth` |
|
|
100
|
+
| `action` | `CREATE`, `UPDATE`, `DELETE`, `LOGIN` |
|
|
101
|
+
| `action_message` | `Sumanth created Employee John` |
|
|
102
|
+
| `functionality` | `Employee Management` |
|
|
103
|
+
| `performed_on` | `Employee #1` |
|
|
104
|
+
| `performed_at` | `2025-07-08 10:30:00+00` |
|
|
105
|
+
| `previous_state` | `{"salary": 100000}` |
|
|
106
|
+
| `current_state` | `{"salary": 120000}` |
|
|
107
|
+
| `changed_fields` | `{"salary": {"old": 100000, "new": 120000}}` |
|
|
108
|
+
|
|
109
|
+
---
|
|
110
|
+
|
|
111
|
+
## Transport Options
|
|
112
|
+
|
|
113
|
+
### PostgreSQL (recommended)
|
|
114
|
+
|
|
115
|
+
```python
|
|
116
|
+
from audit_sdk.transport.simple_database import SimpleAuditTransport
|
|
117
|
+
|
|
118
|
+
transport = SimpleAuditTransport.for_postgres(
|
|
119
|
+
host="localhost", port=5432,
|
|
120
|
+
database="audit_db", username="user", password="pass",
|
|
121
|
+
)
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
### SQLite
|
|
125
|
+
|
|
126
|
+
```python
|
|
127
|
+
transport = SimpleAuditTransport.for_sqlite(path="./audit.db")
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
### MongoDB
|
|
131
|
+
|
|
132
|
+
```bash
|
|
133
|
+
pip install universal-audit-logs[mongodb]
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
```python
|
|
137
|
+
from audit_sdk.transport.mongodb import MongoDBTransport
|
|
138
|
+
|
|
139
|
+
transport = MongoDBTransport(uri="mongodb://localhost:27017", database="audit_db")
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
### REST (HTTP collector)
|
|
143
|
+
|
|
144
|
+
```python
|
|
145
|
+
from audit_sdk import AuditClient, AuditSettings
|
|
146
|
+
|
|
147
|
+
settings = AuditSettings(endpoint="https://audit.example.com/api/v1/events")
|
|
148
|
+
audit = AuditClient(settings=settings)
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
---
|
|
152
|
+
|
|
153
|
+
## Audit Log Table (auto-created)
|
|
154
|
+
|
|
155
|
+
```sql
|
|
156
|
+
CREATE TABLE audit_log (
|
|
157
|
+
id VARCHAR(36) PRIMARY KEY,
|
|
158
|
+
performed_by TEXT NOT NULL,
|
|
159
|
+
action VARCHAR(100) NOT NULL,
|
|
160
|
+
action_message TEXT,
|
|
161
|
+
functionality VARCHAR(200) NOT NULL,
|
|
162
|
+
performed_on TEXT NOT NULL,
|
|
163
|
+
performed_at TIMESTAMPTZ NOT NULL,
|
|
164
|
+
previous_state JSONB,
|
|
165
|
+
current_state JSONB,
|
|
166
|
+
changed_fields JSONB,
|
|
167
|
+
http_context JSONB
|
|
168
|
+
);
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
---
|
|
172
|
+
|
|
173
|
+
## License
|
|
174
|
+
|
|
175
|
+
MIT - see [LICENSE](LICENSE)
|
|
176
|
+
|
|
177
|
+
Copyright (c) 2025 Sumanth
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Universal Audit Framework (UAF) SDK
|
|
3
|
+
====================================
|
|
4
|
+
|
|
5
|
+
A production-ready, framework-agnostic audit logging SDK for Python 3.12+.
|
|
6
|
+
|
|
7
|
+
Quick-start — REST transport::
|
|
8
|
+
|
|
9
|
+
from audit_sdk import AuditClient, AuditSettings
|
|
10
|
+
|
|
11
|
+
settings = AuditSettings(endpoint="https://audit.example.com/api/v1/events")
|
|
12
|
+
audit = AuditClient(settings=settings)
|
|
13
|
+
|
|
14
|
+
Quick-start — Database transport::
|
|
15
|
+
|
|
16
|
+
from audit_sdk import AuditClient
|
|
17
|
+
from audit_sdk.transport.database import DatabaseTransport
|
|
18
|
+
|
|
19
|
+
transport = DatabaseTransport.for_postgres(
|
|
20
|
+
host="localhost", database="audit_db",
|
|
21
|
+
username="user", password="pass",
|
|
22
|
+
)
|
|
23
|
+
audit = AuditClient(transport=transport)
|
|
24
|
+
|
|
25
|
+
Quick-start — FastAPI middleware::
|
|
26
|
+
|
|
27
|
+
from audit_sdk.middleware.fastapi import AuditMiddleware, AuditMiddlewareConfig
|
|
28
|
+
|
|
29
|
+
app.add_middleware(AuditMiddleware, audit_client=audit, config=AuditMiddlewareConfig(...))
|
|
30
|
+
"""
|
|
31
|
+
|
|
32
|
+
from audit_sdk.audit import AuditClient
|
|
33
|
+
from audit_sdk.config.settings import AuditSettings
|
|
34
|
+
from audit_sdk.core.exceptions import QueueFullError, TransportError
|
|
35
|
+
from audit_sdk.models.audit_event import AuditEvent
|
|
36
|
+
from audit_sdk.utils.retry_manager import RetryManager, RetryMetrics
|
|
37
|
+
|
|
38
|
+
__all__: list[str] = [
|
|
39
|
+
# Core
|
|
40
|
+
"AuditClient",
|
|
41
|
+
"AuditSettings",
|
|
42
|
+
"AuditEvent",
|
|
43
|
+
# Retry
|
|
44
|
+
"RetryManager",
|
|
45
|
+
"RetryMetrics",
|
|
46
|
+
# Exceptions
|
|
47
|
+
"QueueFullError",
|
|
48
|
+
"TransportError",
|
|
49
|
+
]
|
|
50
|
+
|
|
51
|
+
# Optional: FastAPI middleware (requires `pip install universal-audit-logs[fastapi]`)
|
|
52
|
+
try:
|
|
53
|
+
from audit_sdk.middleware.fastapi import AuditMiddleware, AuditMiddlewareConfig
|
|
54
|
+
|
|
55
|
+
__all__ += ["AuditMiddleware", "AuditMiddlewareConfig"]
|
|
56
|
+
except ImportError:
|
|
57
|
+
pass
|
|
58
|
+
|
|
59
|
+
# Optional: Database transport (requires `pip install universal-audit-logs[postgres]` or `[sqlite]`)
|
|
60
|
+
try:
|
|
61
|
+
from audit_sdk.transport.database import DatabaseTransport
|
|
62
|
+
|
|
63
|
+
__all__ += ["DatabaseTransport"]
|
|
64
|
+
except ImportError:
|
|
65
|
+
pass
|
|
66
|
+
|
|
67
|
+
__version__: str = "1.0.2"
|