litesoc 1.0.0__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.
litesoc-1.0.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 LiteSOC
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.
litesoc-1.0.0/PKG-INFO ADDED
@@ -0,0 +1,386 @@
1
+ Metadata-Version: 2.4
2
+ Name: litesoc
3
+ Version: 1.0.0
4
+ Summary: Official Python SDK for LiteSOC - Security event tracking and threat detection
5
+ Author-email: LiteSOC <support@litesoc.io>
6
+ Maintainer-email: LiteSOC <support@litesoc.io>
7
+ License: MIT
8
+ Project-URL: Homepage, https://www.litesoc.io
9
+ Project-URL: Documentation, https://www.litesoc.io/docs/api
10
+ Project-URL: Repository, https://github.com/LiteSOC/litesoc-python
11
+ Project-URL: Issues, https://github.com/LiteSOC/litesoc-python/issues
12
+ Keywords: litesoc,security,soc,security-events,threat-detection,brute-force,audit-log,authentication,monitoring
13
+ Classifier: Development Status :: 5 - Production/Stable
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: License :: OSI Approved :: MIT License
16
+ Classifier: Operating System :: OS Independent
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3.8
19
+ Classifier: Programming Language :: Python :: 3.9
20
+ Classifier: Programming Language :: Python :: 3.10
21
+ Classifier: Programming Language :: Python :: 3.11
22
+ Classifier: Programming Language :: Python :: 3.12
23
+ Classifier: Topic :: Security
24
+ Classifier: Topic :: System :: Logging
25
+ Classifier: Topic :: System :: Monitoring
26
+ Classifier: Typing :: Typed
27
+ Requires-Python: >=3.8
28
+ Description-Content-Type: text/markdown
29
+ License-File: LICENSE
30
+ Requires-Dist: requests>=2.25.0
31
+ Provides-Extra: dev
32
+ Requires-Dist: pytest>=7.0.0; extra == "dev"
33
+ Requires-Dist: pytest-asyncio>=0.21.0; extra == "dev"
34
+ Requires-Dist: responses>=0.23.0; extra == "dev"
35
+ Requires-Dist: mypy>=1.0.0; extra == "dev"
36
+ Requires-Dist: black>=23.0.0; extra == "dev"
37
+ Requires-Dist: isort>=5.12.0; extra == "dev"
38
+ Requires-Dist: flake8>=6.0.0; extra == "dev"
39
+ Dynamic: license-file
40
+
41
+ # LiteSOC Python SDK
42
+
43
+ Official Python SDK for [LiteSOC](https://www.litesoc.io) - Security event tracking and threat detection for your applications.
44
+
45
+ [![PyPI version](https://badge.fury.io/py/litesoc.svg)](https://badge.fury.io/py/litesoc)
46
+ [![Python Version](https://img.shields.io/pypi/pyversions/litesoc.svg)](https://pypi.org/project/litesoc/)
47
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
48
+
49
+ ## Installation
50
+
51
+ ```bash
52
+ pip install litesoc
53
+ ```
54
+
55
+ ## Quick Start
56
+
57
+ ```python
58
+ from litesoc import LiteSOC
59
+
60
+ # Initialize the SDK
61
+ litesoc = LiteSOC(api_key="your-api-key")
62
+
63
+ # Track a login failure
64
+ litesoc.track("auth.login_failed",
65
+ actor_id="user_123",
66
+ actor_email="user@example.com",
67
+ user_ip="192.168.1.1",
68
+ metadata={"reason": "invalid_password"}
69
+ )
70
+
71
+ # Flush remaining events before shutdown
72
+ litesoc.flush()
73
+ ```
74
+
75
+ ## Features
76
+
77
+ - ✅ **50+ pre-defined security event types** - Authentication, authorization, data access, and more
78
+ - ✅ **Automatic batching** - Events are batched for efficient delivery
79
+ - ✅ **Retry logic** - Failed events are automatically retried
80
+ - ✅ **Type hints** - Full type annotations for IDE support
81
+ - ✅ **Thread-safe** - Safe to use across multiple threads
82
+ - ✅ **Context manager support** - Use with `with` statement for automatic cleanup
83
+
84
+ ## Configuration Options
85
+
86
+ ```python
87
+ from litesoc import LiteSOC
88
+
89
+ litesoc = LiteSOC(
90
+ api_key="your-api-key", # Required
91
+ endpoint="https://...", # Custom API endpoint
92
+ batching=True, # Enable event batching (default: True)
93
+ batch_size=10, # Events before auto-flush (default: 10)
94
+ flush_interval=5.0, # Seconds between auto-flushes (default: 5.0)
95
+ debug=False, # Enable debug logging (default: False)
96
+ silent=True, # Fail silently on errors (default: True)
97
+ timeout=30.0, # Request timeout in seconds (default: 30.0)
98
+ )
99
+ ```
100
+
101
+ ## Tracking Events
102
+
103
+ ### Basic Usage
104
+
105
+ ```python
106
+ # Track any event type
107
+ litesoc.track("auth.login_failed",
108
+ actor_id="user_123",
109
+ actor_email="user@example.com",
110
+ user_ip="192.168.1.1"
111
+ )
112
+ ```
113
+
114
+ ### Using Actor Object
115
+
116
+ ```python
117
+ from litesoc import LiteSOC, Actor
118
+
119
+ litesoc = LiteSOC(api_key="your-api-key")
120
+
121
+ actor = Actor(id="user_123", email="user@example.com")
122
+ litesoc.track("auth.login_success", actor=actor, user_ip="192.168.1.1")
123
+ ```
124
+
125
+ ### With Severity Level
126
+
127
+ ```python
128
+ from litesoc import EventSeverity
129
+
130
+ litesoc.track("security.suspicious_activity",
131
+ actor_id="user_123",
132
+ user_ip="192.168.1.1",
133
+ severity=EventSeverity.CRITICAL,
134
+ metadata={"reason": "impossible travel detected"}
135
+ )
136
+ ```
137
+
138
+ ### With Metadata
139
+
140
+ ```python
141
+ litesoc.track("data.export",
142
+ actor_id="user_123",
143
+ user_ip="192.168.1.1",
144
+ metadata={
145
+ "file_type": "csv",
146
+ "record_count": 1000,
147
+ "export_reason": "monthly_report"
148
+ }
149
+ )
150
+ ```
151
+
152
+ ## Convenience Methods
153
+
154
+ The SDK provides convenience methods for common security events:
155
+
156
+ ```python
157
+ # Track login failures
158
+ litesoc.track_login_failed("user_123", user_ip="192.168.1.1")
159
+
160
+ # Track login successes
161
+ litesoc.track_login_success("user_123", user_ip="192.168.1.1")
162
+
163
+ # Track privilege escalation (critical severity)
164
+ litesoc.track_privilege_escalation("admin_user", user_ip="192.168.1.1")
165
+
166
+ # Track sensitive data access (high severity)
167
+ litesoc.track_sensitive_access("user_123", "customer_pii_table", user_ip="192.168.1.1")
168
+
169
+ # Track bulk deletions (high severity)
170
+ litesoc.track_bulk_delete("admin_user", record_count=500, user_ip="192.168.1.1")
171
+
172
+ # Track role changes
173
+ litesoc.track_role_changed("user_123", old_role="viewer", new_role="admin", user_ip="192.168.1.1")
174
+
175
+ # Track access denied
176
+ litesoc.track_access_denied("user_123", resource="/admin/settings", user_ip="192.168.1.1")
177
+ ```
178
+
179
+ ## Event Types
180
+
181
+ ### Authentication Events
182
+ - `auth.login_success`
183
+ - `auth.login_failed`
184
+ - `auth.logout`
185
+ - `auth.password_changed`
186
+ - `auth.password_reset_requested`
187
+ - `auth.password_reset_completed`
188
+ - `auth.mfa_enabled`
189
+ - `auth.mfa_disabled`
190
+ - `auth.mfa_challenge_success`
191
+ - `auth.mfa_challenge_failed`
192
+ - `auth.session_created`
193
+ - `auth.session_revoked`
194
+ - `auth.token_refreshed`
195
+
196
+ ### User Events
197
+ - `user.created`
198
+ - `user.updated`
199
+ - `user.deleted`
200
+ - `user.email_changed`
201
+ - `user.email_verified`
202
+ - `user.profile_updated`
203
+
204
+ ### Authorization Events
205
+ - `authz.role_assigned`
206
+ - `authz.role_removed`
207
+ - `authz.role_changed`
208
+ - `authz.permission_granted`
209
+ - `authz.permission_revoked`
210
+ - `authz.access_denied`
211
+ - `authz.access_granted`
212
+
213
+ ### Admin Events
214
+ - `admin.privilege_escalation`
215
+ - `admin.user_impersonation`
216
+ - `admin.settings_changed`
217
+ - `admin.api_key_created`
218
+ - `admin.api_key_revoked`
219
+ - `admin.invite_sent`
220
+ - `admin.invite_accepted`
221
+ - `admin.member_removed`
222
+
223
+ ### Data Events
224
+ - `data.export`
225
+ - `data.import`
226
+ - `data.bulk_delete`
227
+ - `data.bulk_update`
228
+ - `data.sensitive_access`
229
+ - `data.download`
230
+ - `data.upload`
231
+ - `data.shared`
232
+ - `data.unshared`
233
+
234
+ ### Security Events
235
+ - `security.suspicious_activity`
236
+ - `security.rate_limit_exceeded`
237
+ - `security.ip_blocked`
238
+ - `security.ip_unblocked`
239
+ - `security.account_locked`
240
+ - `security.account_unlocked`
241
+ - `security.brute_force_detected`
242
+ - `security.impossible_travel`
243
+ - `security.geo_anomaly`
244
+
245
+ ### API Events
246
+ - `api.key_used`
247
+ - `api.rate_limited`
248
+ - `api.error`
249
+ - `api.webhook_sent`
250
+ - `api.webhook_failed`
251
+
252
+ ### Billing Events
253
+ - `billing.subscription_created`
254
+ - `billing.subscription_updated`
255
+ - `billing.subscription_cancelled`
256
+ - `billing.payment_succeeded`
257
+ - `billing.payment_failed`
258
+
259
+ ## Framework Integration
260
+
261
+ ### Flask
262
+
263
+ ```python
264
+ from flask import Flask, request, g
265
+ from litesoc import LiteSOC
266
+
267
+ app = Flask(__name__)
268
+ litesoc = LiteSOC(api_key="your-api-key")
269
+
270
+ @app.route("/login", methods=["POST"])
271
+ def login():
272
+ user_ip = request.headers.get("X-Forwarded-For", request.remote_addr)
273
+
274
+ # Attempt authentication
275
+ user = authenticate(request.form["email"], request.form["password"])
276
+
277
+ if user:
278
+ litesoc.track_login_success(user.id, actor_email=user.email, user_ip=user_ip)
279
+ return {"success": True}
280
+ else:
281
+ litesoc.track_login_failed(request.form["email"], user_ip=user_ip)
282
+ return {"success": False}, 401
283
+ ```
284
+
285
+ ### Django
286
+
287
+ ```python
288
+ from django.contrib.auth.signals import user_logged_in, user_login_failed
289
+ from django.dispatch import receiver
290
+ from litesoc import LiteSOC
291
+
292
+ litesoc = LiteSOC(api_key="your-api-key")
293
+
294
+ @receiver(user_logged_in)
295
+ def track_login_success(sender, request, user, **kwargs):
296
+ user_ip = request.META.get("HTTP_X_FORWARDED_FOR", request.META.get("REMOTE_ADDR"))
297
+ litesoc.track_login_success(str(user.id), actor_email=user.email, user_ip=user_ip)
298
+
299
+ @receiver(user_login_failed)
300
+ def track_login_failure(sender, credentials, request, **kwargs):
301
+ user_ip = request.META.get("HTTP_X_FORWARDED_FOR", request.META.get("REMOTE_ADDR"))
302
+ litesoc.track_login_failed(credentials.get("username", "unknown"), user_ip=user_ip)
303
+ ```
304
+
305
+ ### FastAPI
306
+
307
+ ```python
308
+ from fastapi import FastAPI, Request, Depends
309
+ from litesoc import LiteSOC
310
+
311
+ app = FastAPI()
312
+ litesoc = LiteSOC(api_key="your-api-key")
313
+
314
+ @app.post("/login")
315
+ async def login(request: Request, credentials: LoginRequest):
316
+ user_ip = request.headers.get("X-Forwarded-For", request.client.host)
317
+
318
+ user = await authenticate(credentials.email, credentials.password)
319
+
320
+ if user:
321
+ litesoc.track_login_success(user.id, actor_email=user.email, user_ip=user_ip)
322
+ return {"success": True}
323
+ else:
324
+ litesoc.track_login_failed(credentials.email, user_ip=user_ip)
325
+ raise HTTPException(status_code=401)
326
+ ```
327
+
328
+ ## Context Manager Support
329
+
330
+ ```python
331
+ from litesoc import LiteSOC
332
+
333
+ with LiteSOC(api_key="your-api-key") as litesoc:
334
+ litesoc.track("auth.login_success", actor_id="user_123")
335
+ # Events are automatically flushed when exiting the context
336
+ ```
337
+
338
+ ## Queue Management
339
+
340
+ ```python
341
+ # Get current queue size
342
+ queue_size = litesoc.get_queue_size()
343
+
344
+ # Manually flush all events
345
+ litesoc.flush()
346
+
347
+ # Clear queue without sending
348
+ litesoc.clear_queue()
349
+
350
+ # Graceful shutdown
351
+ litesoc.shutdown()
352
+ ```
353
+
354
+ ## Error Handling
355
+
356
+ By default, the SDK fails silently (`silent=True`). To catch errors:
357
+
358
+ ```python
359
+ litesoc = LiteSOC(api_key="your-api-key", silent=False)
360
+
361
+ try:
362
+ litesoc.track("auth.login_failed", actor_id="user_123")
363
+ litesoc.flush()
364
+ except Exception as e:
365
+ print(f"Failed to track event: {e}")
366
+ ```
367
+
368
+ ## Debug Mode
369
+
370
+ Enable debug logging to troubleshoot issues:
371
+
372
+ ```python
373
+ litesoc = LiteSOC(api_key="your-api-key", debug=True)
374
+ # Logs will be printed to stdout
375
+ ```
376
+
377
+ ## License
378
+
379
+ MIT License - see [LICENSE](LICENSE) for details.
380
+
381
+ ## Links
382
+
383
+ - [LiteSOC Website](https://www.litesoc.io)
384
+ - [Documentation](https://www.litesoc.io/docs)
385
+ - [API Reference](https://www.litesoc.io/docs/api)
386
+ - [GitHub Repository](https://github.com/LiteSOC/litesoc-python)