debugbundle-python 0.1.6__tar.gz → 0.1.9__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.
Files changed (45) hide show
  1. debugbundle_python-0.1.9/PKG-INFO +348 -0
  2. debugbundle_python-0.1.9/README.md +309 -0
  3. {debugbundle_python-0.1.6 → debugbundle_python-0.1.9}/pyproject.toml +1 -1
  4. debugbundle_python-0.1.9/src/debugbundle/integrations/__init__.py +31 -0
  5. {debugbundle_python-0.1.6 → debugbundle_python-0.1.9}/src/debugbundle/integrations/relay_django.py +7 -2
  6. {debugbundle_python-0.1.6 → debugbundle_python-0.1.9}/src/debugbundle/integrations/relay_fastapi.py +3 -3
  7. {debugbundle_python-0.1.6 → debugbundle_python-0.1.9}/src/debugbundle/integrations/relay_flask.py +2 -1
  8. {debugbundle_python-0.1.6 → debugbundle_python-0.1.9}/src/debugbundle/relay.py +39 -19
  9. debugbundle_python-0.1.9/src/debugbundle_python.egg-info/PKG-INFO +348 -0
  10. {debugbundle_python-0.1.6 → debugbundle_python-0.1.9}/src/debugbundle_python.egg-info/SOURCES.txt +1 -0
  11. debugbundle_python-0.1.9/tests/test_optional_imports.py +27 -0
  12. {debugbundle_python-0.1.6 → debugbundle_python-0.1.9}/tests/test_relay.py +23 -0
  13. {debugbundle_python-0.1.6 → debugbundle_python-0.1.9}/tests/test_repository_metadata.py +2 -2
  14. debugbundle_python-0.1.6/PKG-INFO +0 -102
  15. debugbundle_python-0.1.6/README.md +0 -63
  16. debugbundle_python-0.1.6/src/debugbundle/integrations/__init__.py +0 -16
  17. debugbundle_python-0.1.6/src/debugbundle_python.egg-info/PKG-INFO +0 -102
  18. {debugbundle_python-0.1.6 → debugbundle_python-0.1.9}/LICENSE +0 -0
  19. {debugbundle_python-0.1.6 → debugbundle_python-0.1.9}/setup.cfg +0 -0
  20. {debugbundle_python-0.1.6 → debugbundle_python-0.1.9}/src/debugbundle/__init__.py +0 -0
  21. {debugbundle_python-0.1.6 → debugbundle_python-0.1.9}/src/debugbundle/config.py +0 -0
  22. {debugbundle_python-0.1.6 → debugbundle_python-0.1.9}/src/debugbundle/core.py +0 -0
  23. {debugbundle_python-0.1.6 → debugbundle_python-0.1.9}/src/debugbundle/integrations/common.py +0 -0
  24. {debugbundle_python-0.1.6 → debugbundle_python-0.1.9}/src/debugbundle/integrations/django.py +0 -0
  25. {debugbundle_python-0.1.6 → debugbundle_python-0.1.9}/src/debugbundle/integrations/fastapi.py +0 -0
  26. {debugbundle_python-0.1.6 → debugbundle_python-0.1.9}/src/debugbundle/integrations/flask.py +0 -0
  27. {debugbundle_python-0.1.6 → debugbundle_python-0.1.9}/src/debugbundle/logger_integrations.py +0 -0
  28. {debugbundle_python-0.1.6 → debugbundle_python-0.1.9}/src/debugbundle/py.typed +0 -0
  29. {debugbundle_python-0.1.6 → debugbundle_python-0.1.9}/src/debugbundle/redaction.py +0 -0
  30. {debugbundle_python-0.1.6 → debugbundle_python-0.1.9}/src/debugbundle/relay_delivery.py +0 -0
  31. {debugbundle_python-0.1.6 → debugbundle_python-0.1.9}/src/debugbundle/suppression.py +0 -0
  32. {debugbundle_python-0.1.6 → debugbundle_python-0.1.9}/src/debugbundle/transport.py +0 -0
  33. {debugbundle_python-0.1.6 → debugbundle_python-0.1.9}/src/debugbundle/trigger_token.py +0 -0
  34. {debugbundle_python-0.1.6 → debugbundle_python-0.1.9}/src/debugbundle_python.egg-info/dependency_links.txt +0 -0
  35. {debugbundle_python-0.1.6 → debugbundle_python-0.1.9}/src/debugbundle_python.egg-info/requires.txt +0 -0
  36. {debugbundle_python-0.1.6 → debugbundle_python-0.1.9}/src/debugbundle_python.egg-info/top_level.txt +0 -0
  37. {debugbundle_python-0.1.6 → debugbundle_python-0.1.9}/tests/test_contracts.py +0 -0
  38. {debugbundle_python-0.1.6 → debugbundle_python-0.1.9}/tests/test_framework_integrations.py +0 -0
  39. {debugbundle_python-0.1.6 → debugbundle_python-0.1.9}/tests/test_hooks.py +0 -0
  40. {debugbundle_python-0.1.6 → debugbundle_python-0.1.9}/tests/test_http_integration.py +0 -0
  41. {debugbundle_python-0.1.6 → debugbundle_python-0.1.9}/tests/test_relay_delivery.py +0 -0
  42. {debugbundle_python-0.1.6 → debugbundle_python-0.1.9}/tests/test_remote_config.py +0 -0
  43. {debugbundle_python-0.1.6 → debugbundle_python-0.1.9}/tests/test_schema_validation.py +0 -0
  44. {debugbundle_python-0.1.6 → debugbundle_python-0.1.9}/tests/test_sdk.py +0 -0
  45. {debugbundle_python-0.1.6 → debugbundle_python-0.1.9}/tests/test_trigger_token.py +0 -0
@@ -0,0 +1,348 @@
1
+ Metadata-Version: 2.4
2
+ Name: debugbundle-python
3
+ Version: 0.1.9
4
+ Summary: DebugBundle SDK for Python
5
+ Author: DebugBundle
6
+ License-Expression: AGPL-3.0-only
7
+ Project-URL: Homepage, https://debugbundle.com/docs/sdks/python
8
+ Project-URL: Repository, https://github.com/debugbundle/debugbundle-python
9
+ Project-URL: Issues, https://github.com/debugbundle/debugbundle-python/issues
10
+ Keywords: debugbundle,debugging,ai-agent,error-tracking
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Framework :: Django
13
+ Classifier: Framework :: FastAPI
14
+ Classifier: Framework :: Flask
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3 :: Only
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Typing :: Typed
21
+ Requires-Python: >=3.10
22
+ Description-Content-Type: text/markdown
23
+ License-File: LICENSE
24
+ Requires-Dist: httpx<0.29,>=0.27
25
+ Provides-Extra: dev
26
+ Requires-Dist: build<2,>=1; extra == "dev"
27
+ Requires-Dist: django<6,>=5; extra == "dev"
28
+ Requires-Dist: fastapi<1,>=0.115; extra == "dev"
29
+ Requires-Dist: flask<4,>=3; extra == "dev"
30
+ Requires-Dist: jsonschema<5,>=4.23; extra == "dev"
31
+ Requires-Dist: loguru<1,>=0.7; extra == "dev"
32
+ Requires-Dist: mypy<2,>=1.15; extra == "dev"
33
+ Requires-Dist: pytest<9,>=8.3; extra == "dev"
34
+ Requires-Dist: pytest-cov<7,>=5; extra == "dev"
35
+ Requires-Dist: ruff<0.12,>=0.11; extra == "dev"
36
+ Requires-Dist: structlog<26,>=24; extra == "dev"
37
+ Requires-Dist: twine<7,>=5; extra == "dev"
38
+ Dynamic: license-file
39
+
40
+ # debugbundle-python
41
+
42
+ Python SDK for DebugBundle.
43
+
44
+ ![PyPI](https://img.shields.io/pypi/v/debugbundle-python?label=pypi)
45
+ ![CI](https://img.shields.io/github/actions/workflow/status/debugbundle/debugbundle-python/ci.yml?branch=main&label=ci)
46
+ ![License](https://img.shields.io/badge/license-AGPL--3.0--only-blue)
47
+
48
+ Use this package to capture Python backend exceptions, request metadata, structured logs, runtime context, and probe data. It supports vanilla Python plus Django, Flask, FastAPI, Python logging, structlog, loguru, and browser relay helpers.
49
+
50
+ Requires Python 3.10 or newer.
51
+
52
+ ## Installation
53
+
54
+ ```bash
55
+ pip install debugbundle-python
56
+ ```
57
+
58
+ Install the SDK alongside the framework you actually run:
59
+
60
+ ```bash
61
+ pip install debugbundle-python django
62
+ pip install debugbundle-python flask
63
+ pip install debugbundle-python fastapi uvicorn
64
+ ```
65
+
66
+ For local development:
67
+
68
+ ```bash
69
+ pip install -e ".[dev]"
70
+ ```
71
+
72
+ ## Quick Start
73
+
74
+ ```python
75
+ import os
76
+ import debugbundle
77
+
78
+ debugbundle.init(
79
+ project_token=os.environ["DEBUGBUNDLE_PROJECT_TOKEN"],
80
+ service="checkout-api",
81
+ environment="production",
82
+ )
83
+
84
+ debugbundle.capture_exceptions()
85
+ debugbundle.capture_logging()
86
+ ```
87
+
88
+ Capture handled errors, logs, messages, and probes explicitly:
89
+
90
+ ```python
91
+ debugbundle.capture_exception(error)
92
+ debugbundle.capture_log("payment retry failed", level="warning", context={"order_id": order_id})
93
+ debugbundle.capture_message("worker started")
94
+ debugbundle.probe("checkout.cart", {"item_count": len(cart.items)})
95
+
96
+ debugbundle.flush()
97
+ ```
98
+
99
+ ## Framework Integrations
100
+
101
+ | Framework | Integration |
102
+ | --- | --- |
103
+ | Django | `DebugBundleDjangoMiddleware` |
104
+ | Flask | `instrument_flask(app)` |
105
+ | FastAPI | `DebugBundleFastAPIMiddleware` or `instrument_fastapi(app)` |
106
+ | Python logging | `capture_logging()` |
107
+ | asyncio | `capture_async()` |
108
+ | structlog/loguru | Auto-detected when log capture is enabled and the libraries are installed |
109
+
110
+ ## Browser Relay
111
+
112
+ Python backends can host the browser relay endpoint used by `@debugbundle/sdk-browser`.
113
+
114
+ | Framework | Helper |
115
+ | --- | --- |
116
+ | Django | `create_django_relay_view()` |
117
+ | Flask | `create_flask_relay_handler()` |
118
+ | FastAPI | `create_fastapi_relay_handler()` |
119
+
120
+ The relay validates JSON batches, enforces same-origin or allowed origins, strips trust-sensitive browser fields, keeps the server-side project token private, and supports both local-only file writes and connected forwarding.
121
+
122
+ Relay defaults and limits:
123
+
124
+ - Same-origin requests are allowed by default when `allowed_origins` is omitted.
125
+ - Split frontend/backend deployments should set explicit `allowed_origins` values.
126
+ - Relay requests must use `Content-Type: application/json` and stay below `max_body_bytes` (default `262144`).
127
+ - Relay rate limiting defaults to `60` requests per IP per minute.
128
+ - `project_mode="local-only"` writes accepted browser events to `.debugbundle/local/events` or your configured `local_events_dir`.
129
+ - `project_mode="connected"` writes durable spool files by default and forwards with the server-side `project_token` only.
130
+ - Leaving relay `project_mode` unset disables local writes and forwarding; accepted batches are only surfaced through `on_accept`.
131
+ - Connected relay mode without a usable `project_token` keeps accepting and optionally spooling events, but forwarding remains disabled until the server provides credentials.
132
+
133
+ ## Configuration Reference
134
+
135
+ Configuration sources and precedence:
136
+
137
+ - The SDK only reads the keyword arguments passed to `debugbundle.init(...)`.
138
+ - Environment variables, Django settings, Flask config, or FastAPI settings are convenience sources that your application maps into `debugbundle.init(...)`; the SDK does not read them directly.
139
+ - Explicit `debugbundle.init(...)` arguments always win because they are the only configuration source the runtime consumes.
140
+ - Capture-policy fields are server-owned and are not accepted in local SDK config. The SDK learns capture policy through `GET /v1/sdk/config` and applies it locally before transport.
141
+
142
+ | Option | Default | Purpose |
143
+ | --- | --- | --- |
144
+ | `project_token` | required for connected capture | Write-only DebugBundle project token. Blank or missing tokens disable connected capture and leave the SDK status at `disconnected`. |
145
+ | `service` | auto/default service | Service name shown on incidents and bundles. |
146
+ | `environment` | `development` | Runtime environment such as `production`, `staging`, or `development`. |
147
+ | `endpoint` | `https://api.debugbundle.com/v1/events` | Ingestion endpoint for connected mode or self-hosting. |
148
+ | `enabled` | `True` | Disable all capture without removing instrumentation. |
149
+ | `log_level` | `warning` | Minimum captured log severity. |
150
+ | `sample_rate` | `1.0` | Fraction of events to keep before transport. |
151
+ | `batch_size` | `25` | Events per batch before flushing. |
152
+ | `flush_interval` | `5.0` | Flush interval in seconds. |
153
+ | `redact_fields` | common sensitive fields | Additional field names to redact. |
154
+ | `max_probe_labels` | `50` | Maximum distinct probe labels buffered in memory. |
155
+ | `max_probe_entries_per_label` | `10` | Maximum entries retained per probe label. |
156
+ | `probe_flush_on_error` | `True` | Attach buffered probe data to captured exceptions. |
157
+ | `probes_poll_interval` | `60000` | Remote probe config poll interval in milliseconds. |
158
+ | `fetch_impl` | internal HTTP fetch | Custom remote-config fetch function for tests or advanced routing. |
159
+ | `on_diagnostic` | none | Callback for SDK internal diagnostics. |
160
+
161
+ Framework-native wiring:
162
+
163
+ - Django: initialize the SDK during startup, then add `DebugBundleDjangoMiddleware` to `MIDDLEWARE`.
164
+ - Flask: initialize the SDK during app creation, then call `instrument_flask(app)`.
165
+ - FastAPI: initialize the SDK during startup, then add `DebugBundleFastAPIMiddleware` or call `instrument_fastapi(app)`.
166
+ - There is no separate package-manager plugin, settings loader, or framework-only config surface in V1.
167
+
168
+ ## Install Examples by Mode
169
+
170
+ Vanilla Python:
171
+
172
+ ```python
173
+ import os
174
+ import debugbundle
175
+
176
+ debugbundle.init(
177
+ project_token=os.environ["DEBUGBUNDLE_PROJECT_TOKEN"],
178
+ service="worker",
179
+ environment="production",
180
+ )
181
+
182
+ debugbundle.capture_exceptions()
183
+ debugbundle.capture_logging()
184
+ ```
185
+
186
+ Flask:
187
+
188
+ ```python
189
+ import os
190
+ from flask import Flask
191
+ import debugbundle
192
+
193
+ app = Flask(__name__)
194
+ debugbundle.init(
195
+ project_token=os.environ["DEBUGBUNDLE_PROJECT_TOKEN"],
196
+ service="checkout-api",
197
+ environment="production",
198
+ )
199
+ debugbundle.instrument_flask(app)
200
+ ```
201
+
202
+ FastAPI:
203
+
204
+ ```python
205
+ import os
206
+ from fastapi import FastAPI
207
+ import debugbundle
208
+
209
+ app = FastAPI()
210
+ debugbundle.init(
211
+ project_token=os.environ["DEBUGBUNDLE_PROJECT_TOKEN"],
212
+ service="checkout-api",
213
+ environment="production",
214
+ )
215
+ debugbundle.instrument_fastapi(app)
216
+ ```
217
+
218
+ Logger integration:
219
+
220
+ ```python
221
+ import logging
222
+ import debugbundle
223
+
224
+ debugbundle.capture_logging(logging.getLogger("checkout"))
225
+ ```
226
+
227
+ Connected browser relay:
228
+
229
+ ```python
230
+ from flask import Flask
231
+ import debugbundle
232
+
233
+ app = Flask(__name__)
234
+ debugbundle.create_flask_relay_handler(
235
+ allowed_origins=["https://app.example.com"],
236
+ project_mode="connected",
237
+ project_token="dbundle_proj_...",
238
+ endpoint="https://api.debugbundle.com/v1/events",
239
+ )(app)
240
+ ```
241
+
242
+ Local-only browser relay:
243
+
244
+ ```python
245
+ from flask import Flask
246
+ import debugbundle
247
+
248
+ app = Flask(__name__)
249
+ debugbundle.create_flask_relay_handler(
250
+ allowed_origins=["http://localhost:3000"],
251
+ project_mode="local-only",
252
+ local_events_dir=".debugbundle/local/events",
253
+ )(app)
254
+ ```
255
+
256
+ There is no zero-install fallback for the Python SDK itself in V1. The nearest low-friction path is the browser relay mounted on an existing Python web app.
257
+
258
+ ## Runtime and Framework Support
259
+
260
+ | Surface | Minimum compatibility version | Recommended production version | Installed-base compatibility lane | Rolling CI lane | Out of scope |
261
+ | --- | --- | --- | --- | --- | --- |
262
+ | Python runtime | 3.10 | 3.12 | 3.10 and 3.11 remain supported for installed-base coverage | 3.12 | 3.9 and older |
263
+ | Django | 5.x | latest 5.x patch | 5.x compatibility support | repo release smoke and tests install Django 5.x | Django 4.x and older |
264
+ | Flask | 3.x | latest 3.x patch | 3.x compatibility support | repo release smoke installs Flask 3.x | Flask 2.x and older |
265
+ | FastAPI | 0.115+ | latest 0.115+ patch line | 0.115+ compatibility support | repo tests install FastAPI 0.115+ | standalone Starlette, older FastAPI lines |
266
+
267
+ Post-V1 planned expansions from `spec/sdk-language-targets.md` remain out of scope here: Celery, RQ, Dramatiq, standalone Starlette, Gunicorn/Uvicorn server hooks, and AWS Lambda Python.
268
+
269
+ ## Dependency Alignment
270
+
271
+ `debugbundle-python` ships as one package in V1, so there is no multi-package version-alignment step like a BOM or plugin family lock.
272
+
273
+ - Pin one `debugbundle-python` version across your service and worker repos when you want identical SDK behavior everywhere.
274
+ - Keep framework dependencies inside the supported lanes above: Django 5.x, Flask 3.x, and FastAPI 0.115+.
275
+ - The packaged HTTP client dependency is `httpx>=0.27,<0.29`; if you override transport behavior in tests or wrappers, stay inside that range unless you retest the SDK.
276
+
277
+ ## Safety Defaults
278
+
279
+ - SDK failures are caught internally and do not crash the host process.
280
+ - Sensitive fields are redacted before transport.
281
+ - Duplicate event storms are suppressed locally.
282
+ - Runtime context excludes environment variables.
283
+ - Browser relay requests cannot smuggle server-side credentials.
284
+
285
+ ## Service Naming
286
+
287
+ - Use one stable backend service name per deployable, such as `checkout-api`, `billing-worker`, or `admin-api`.
288
+ - Keep browser relay traffic on the browser-owned service name by default, for example `checkout-web`; the Python relay preserves the browser service unless you explicitly override `service=` or `environment=` on the relay helper.
289
+ - When multiple Python deployables share one DebugBundle project, give each deployable its own `service` value instead of reusing one generic name.
290
+ - Reuse the same environment label across related surfaces, for example `production` on both `checkout-web` and `checkout-api`, so incident and bundle correlation stays readable.
291
+
292
+ ## Safe Startup and Status
293
+
294
+ - The SDK never crashes the host process when configuration is invalid, transport calls fail, or remote config responses are malformed.
295
+ - `debugbundle.init(project_token="")` or any missing/blank connected token leaves capture disabled and `debugbundle.get_status()` returns `disconnected`.
296
+ - Rate-limited transports move the status to `degraded` until the retry window expires.
297
+ - Three consecutive transport failures also move the status to `disconnected` until a later successful flush.
298
+ - `debugbundle.get_last_event_at()` returns the Unix timestamp of the last successful delivery, or `None` before the first success.
299
+
300
+ ## First-Event Verification
301
+
302
+ Use the repo-local smoke target to prove a fresh install end to end against a mock ingestion endpoint:
303
+
304
+ ```bash
305
+ make smoke
306
+ ```
307
+
308
+ That command builds the wheel, installs it into a fresh virtualenv, runs a Flask app that emits an application-owned `capture_message()` event, sends a browser relay batch through `/debugbundle/browser`, validates the emitted Python events against the SDK event-envelope fixture, and confirms both paths reach the mock ingestion endpoint with the expected `service`, `environment`, SDK metadata, and correlation fields.
309
+
310
+ For a manual verification snippet inside your own app:
311
+
312
+ ```python
313
+ import os
314
+ import debugbundle
315
+
316
+ debugbundle.init(
317
+ project_token=os.environ["DEBUGBUNDLE_PROJECT_TOKEN"],
318
+ service="checkout-api",
319
+ environment="staging",
320
+ )
321
+
322
+ debugbundle.capture_message("debugbundle first-event verification", level="error")
323
+ debugbundle.flush()
324
+ print(debugbundle.get_status(), debugbundle.get_last_event_at())
325
+ ```
326
+
327
+ ## Development
328
+
329
+ ```bash
330
+ pip install -e ".[dev]"
331
+ ruff check .
332
+ mypy src
333
+ pytest
334
+ python -m build
335
+ ```
336
+
337
+ CI validates Ruff, mypy, pytest, package build, event schema fixtures, and coverage gates.
338
+
339
+ ## Documentation
340
+
341
+ - Python SDK docs: <https://debugbundle.com/docs/sdks/python>
342
+ - SDK overview: <https://debugbundle.com/docs/sdks>
343
+ - Browser relay: <https://debugbundle.com/docs/sdks/browser-relay>
344
+ - Repository: <https://github.com/debugbundle/debugbundle-python>
345
+
346
+ ## License
347
+
348
+ AGPL-3.0-only. See `LICENSE`.
@@ -0,0 +1,309 @@
1
+ # debugbundle-python
2
+
3
+ Python SDK for DebugBundle.
4
+
5
+ ![PyPI](https://img.shields.io/pypi/v/debugbundle-python?label=pypi)
6
+ ![CI](https://img.shields.io/github/actions/workflow/status/debugbundle/debugbundle-python/ci.yml?branch=main&label=ci)
7
+ ![License](https://img.shields.io/badge/license-AGPL--3.0--only-blue)
8
+
9
+ Use this package to capture Python backend exceptions, request metadata, structured logs, runtime context, and probe data. It supports vanilla Python plus Django, Flask, FastAPI, Python logging, structlog, loguru, and browser relay helpers.
10
+
11
+ Requires Python 3.10 or newer.
12
+
13
+ ## Installation
14
+
15
+ ```bash
16
+ pip install debugbundle-python
17
+ ```
18
+
19
+ Install the SDK alongside the framework you actually run:
20
+
21
+ ```bash
22
+ pip install debugbundle-python django
23
+ pip install debugbundle-python flask
24
+ pip install debugbundle-python fastapi uvicorn
25
+ ```
26
+
27
+ For local development:
28
+
29
+ ```bash
30
+ pip install -e ".[dev]"
31
+ ```
32
+
33
+ ## Quick Start
34
+
35
+ ```python
36
+ import os
37
+ import debugbundle
38
+
39
+ debugbundle.init(
40
+ project_token=os.environ["DEBUGBUNDLE_PROJECT_TOKEN"],
41
+ service="checkout-api",
42
+ environment="production",
43
+ )
44
+
45
+ debugbundle.capture_exceptions()
46
+ debugbundle.capture_logging()
47
+ ```
48
+
49
+ Capture handled errors, logs, messages, and probes explicitly:
50
+
51
+ ```python
52
+ debugbundle.capture_exception(error)
53
+ debugbundle.capture_log("payment retry failed", level="warning", context={"order_id": order_id})
54
+ debugbundle.capture_message("worker started")
55
+ debugbundle.probe("checkout.cart", {"item_count": len(cart.items)})
56
+
57
+ debugbundle.flush()
58
+ ```
59
+
60
+ ## Framework Integrations
61
+
62
+ | Framework | Integration |
63
+ | --- | --- |
64
+ | Django | `DebugBundleDjangoMiddleware` |
65
+ | Flask | `instrument_flask(app)` |
66
+ | FastAPI | `DebugBundleFastAPIMiddleware` or `instrument_fastapi(app)` |
67
+ | Python logging | `capture_logging()` |
68
+ | asyncio | `capture_async()` |
69
+ | structlog/loguru | Auto-detected when log capture is enabled and the libraries are installed |
70
+
71
+ ## Browser Relay
72
+
73
+ Python backends can host the browser relay endpoint used by `@debugbundle/sdk-browser`.
74
+
75
+ | Framework | Helper |
76
+ | --- | --- |
77
+ | Django | `create_django_relay_view()` |
78
+ | Flask | `create_flask_relay_handler()` |
79
+ | FastAPI | `create_fastapi_relay_handler()` |
80
+
81
+ The relay validates JSON batches, enforces same-origin or allowed origins, strips trust-sensitive browser fields, keeps the server-side project token private, and supports both local-only file writes and connected forwarding.
82
+
83
+ Relay defaults and limits:
84
+
85
+ - Same-origin requests are allowed by default when `allowed_origins` is omitted.
86
+ - Split frontend/backend deployments should set explicit `allowed_origins` values.
87
+ - Relay requests must use `Content-Type: application/json` and stay below `max_body_bytes` (default `262144`).
88
+ - Relay rate limiting defaults to `60` requests per IP per minute.
89
+ - `project_mode="local-only"` writes accepted browser events to `.debugbundle/local/events` or your configured `local_events_dir`.
90
+ - `project_mode="connected"` writes durable spool files by default and forwards with the server-side `project_token` only.
91
+ - Leaving relay `project_mode` unset disables local writes and forwarding; accepted batches are only surfaced through `on_accept`.
92
+ - Connected relay mode without a usable `project_token` keeps accepting and optionally spooling events, but forwarding remains disabled until the server provides credentials.
93
+
94
+ ## Configuration Reference
95
+
96
+ Configuration sources and precedence:
97
+
98
+ - The SDK only reads the keyword arguments passed to `debugbundle.init(...)`.
99
+ - Environment variables, Django settings, Flask config, or FastAPI settings are convenience sources that your application maps into `debugbundle.init(...)`; the SDK does not read them directly.
100
+ - Explicit `debugbundle.init(...)` arguments always win because they are the only configuration source the runtime consumes.
101
+ - Capture-policy fields are server-owned and are not accepted in local SDK config. The SDK learns capture policy through `GET /v1/sdk/config` and applies it locally before transport.
102
+
103
+ | Option | Default | Purpose |
104
+ | --- | --- | --- |
105
+ | `project_token` | required for connected capture | Write-only DebugBundle project token. Blank or missing tokens disable connected capture and leave the SDK status at `disconnected`. |
106
+ | `service` | auto/default service | Service name shown on incidents and bundles. |
107
+ | `environment` | `development` | Runtime environment such as `production`, `staging`, or `development`. |
108
+ | `endpoint` | `https://api.debugbundle.com/v1/events` | Ingestion endpoint for connected mode or self-hosting. |
109
+ | `enabled` | `True` | Disable all capture without removing instrumentation. |
110
+ | `log_level` | `warning` | Minimum captured log severity. |
111
+ | `sample_rate` | `1.0` | Fraction of events to keep before transport. |
112
+ | `batch_size` | `25` | Events per batch before flushing. |
113
+ | `flush_interval` | `5.0` | Flush interval in seconds. |
114
+ | `redact_fields` | common sensitive fields | Additional field names to redact. |
115
+ | `max_probe_labels` | `50` | Maximum distinct probe labels buffered in memory. |
116
+ | `max_probe_entries_per_label` | `10` | Maximum entries retained per probe label. |
117
+ | `probe_flush_on_error` | `True` | Attach buffered probe data to captured exceptions. |
118
+ | `probes_poll_interval` | `60000` | Remote probe config poll interval in milliseconds. |
119
+ | `fetch_impl` | internal HTTP fetch | Custom remote-config fetch function for tests or advanced routing. |
120
+ | `on_diagnostic` | none | Callback for SDK internal diagnostics. |
121
+
122
+ Framework-native wiring:
123
+
124
+ - Django: initialize the SDK during startup, then add `DebugBundleDjangoMiddleware` to `MIDDLEWARE`.
125
+ - Flask: initialize the SDK during app creation, then call `instrument_flask(app)`.
126
+ - FastAPI: initialize the SDK during startup, then add `DebugBundleFastAPIMiddleware` or call `instrument_fastapi(app)`.
127
+ - There is no separate package-manager plugin, settings loader, or framework-only config surface in V1.
128
+
129
+ ## Install Examples by Mode
130
+
131
+ Vanilla Python:
132
+
133
+ ```python
134
+ import os
135
+ import debugbundle
136
+
137
+ debugbundle.init(
138
+ project_token=os.environ["DEBUGBUNDLE_PROJECT_TOKEN"],
139
+ service="worker",
140
+ environment="production",
141
+ )
142
+
143
+ debugbundle.capture_exceptions()
144
+ debugbundle.capture_logging()
145
+ ```
146
+
147
+ Flask:
148
+
149
+ ```python
150
+ import os
151
+ from flask import Flask
152
+ import debugbundle
153
+
154
+ app = Flask(__name__)
155
+ debugbundle.init(
156
+ project_token=os.environ["DEBUGBUNDLE_PROJECT_TOKEN"],
157
+ service="checkout-api",
158
+ environment="production",
159
+ )
160
+ debugbundle.instrument_flask(app)
161
+ ```
162
+
163
+ FastAPI:
164
+
165
+ ```python
166
+ import os
167
+ from fastapi import FastAPI
168
+ import debugbundle
169
+
170
+ app = FastAPI()
171
+ debugbundle.init(
172
+ project_token=os.environ["DEBUGBUNDLE_PROJECT_TOKEN"],
173
+ service="checkout-api",
174
+ environment="production",
175
+ )
176
+ debugbundle.instrument_fastapi(app)
177
+ ```
178
+
179
+ Logger integration:
180
+
181
+ ```python
182
+ import logging
183
+ import debugbundle
184
+
185
+ debugbundle.capture_logging(logging.getLogger("checkout"))
186
+ ```
187
+
188
+ Connected browser relay:
189
+
190
+ ```python
191
+ from flask import Flask
192
+ import debugbundle
193
+
194
+ app = Flask(__name__)
195
+ debugbundle.create_flask_relay_handler(
196
+ allowed_origins=["https://app.example.com"],
197
+ project_mode="connected",
198
+ project_token="dbundle_proj_...",
199
+ endpoint="https://api.debugbundle.com/v1/events",
200
+ )(app)
201
+ ```
202
+
203
+ Local-only browser relay:
204
+
205
+ ```python
206
+ from flask import Flask
207
+ import debugbundle
208
+
209
+ app = Flask(__name__)
210
+ debugbundle.create_flask_relay_handler(
211
+ allowed_origins=["http://localhost:3000"],
212
+ project_mode="local-only",
213
+ local_events_dir=".debugbundle/local/events",
214
+ )(app)
215
+ ```
216
+
217
+ There is no zero-install fallback for the Python SDK itself in V1. The nearest low-friction path is the browser relay mounted on an existing Python web app.
218
+
219
+ ## Runtime and Framework Support
220
+
221
+ | Surface | Minimum compatibility version | Recommended production version | Installed-base compatibility lane | Rolling CI lane | Out of scope |
222
+ | --- | --- | --- | --- | --- | --- |
223
+ | Python runtime | 3.10 | 3.12 | 3.10 and 3.11 remain supported for installed-base coverage | 3.12 | 3.9 and older |
224
+ | Django | 5.x | latest 5.x patch | 5.x compatibility support | repo release smoke and tests install Django 5.x | Django 4.x and older |
225
+ | Flask | 3.x | latest 3.x patch | 3.x compatibility support | repo release smoke installs Flask 3.x | Flask 2.x and older |
226
+ | FastAPI | 0.115+ | latest 0.115+ patch line | 0.115+ compatibility support | repo tests install FastAPI 0.115+ | standalone Starlette, older FastAPI lines |
227
+
228
+ Post-V1 planned expansions from `spec/sdk-language-targets.md` remain out of scope here: Celery, RQ, Dramatiq, standalone Starlette, Gunicorn/Uvicorn server hooks, and AWS Lambda Python.
229
+
230
+ ## Dependency Alignment
231
+
232
+ `debugbundle-python` ships as one package in V1, so there is no multi-package version-alignment step like a BOM or plugin family lock.
233
+
234
+ - Pin one `debugbundle-python` version across your service and worker repos when you want identical SDK behavior everywhere.
235
+ - Keep framework dependencies inside the supported lanes above: Django 5.x, Flask 3.x, and FastAPI 0.115+.
236
+ - The packaged HTTP client dependency is `httpx>=0.27,<0.29`; if you override transport behavior in tests or wrappers, stay inside that range unless you retest the SDK.
237
+
238
+ ## Safety Defaults
239
+
240
+ - SDK failures are caught internally and do not crash the host process.
241
+ - Sensitive fields are redacted before transport.
242
+ - Duplicate event storms are suppressed locally.
243
+ - Runtime context excludes environment variables.
244
+ - Browser relay requests cannot smuggle server-side credentials.
245
+
246
+ ## Service Naming
247
+
248
+ - Use one stable backend service name per deployable, such as `checkout-api`, `billing-worker`, or `admin-api`.
249
+ - Keep browser relay traffic on the browser-owned service name by default, for example `checkout-web`; the Python relay preserves the browser service unless you explicitly override `service=` or `environment=` on the relay helper.
250
+ - When multiple Python deployables share one DebugBundle project, give each deployable its own `service` value instead of reusing one generic name.
251
+ - Reuse the same environment label across related surfaces, for example `production` on both `checkout-web` and `checkout-api`, so incident and bundle correlation stays readable.
252
+
253
+ ## Safe Startup and Status
254
+
255
+ - The SDK never crashes the host process when configuration is invalid, transport calls fail, or remote config responses are malformed.
256
+ - `debugbundle.init(project_token="")` or any missing/blank connected token leaves capture disabled and `debugbundle.get_status()` returns `disconnected`.
257
+ - Rate-limited transports move the status to `degraded` until the retry window expires.
258
+ - Three consecutive transport failures also move the status to `disconnected` until a later successful flush.
259
+ - `debugbundle.get_last_event_at()` returns the Unix timestamp of the last successful delivery, or `None` before the first success.
260
+
261
+ ## First-Event Verification
262
+
263
+ Use the repo-local smoke target to prove a fresh install end to end against a mock ingestion endpoint:
264
+
265
+ ```bash
266
+ make smoke
267
+ ```
268
+
269
+ That command builds the wheel, installs it into a fresh virtualenv, runs a Flask app that emits an application-owned `capture_message()` event, sends a browser relay batch through `/debugbundle/browser`, validates the emitted Python events against the SDK event-envelope fixture, and confirms both paths reach the mock ingestion endpoint with the expected `service`, `environment`, SDK metadata, and correlation fields.
270
+
271
+ For a manual verification snippet inside your own app:
272
+
273
+ ```python
274
+ import os
275
+ import debugbundle
276
+
277
+ debugbundle.init(
278
+ project_token=os.environ["DEBUGBUNDLE_PROJECT_TOKEN"],
279
+ service="checkout-api",
280
+ environment="staging",
281
+ )
282
+
283
+ debugbundle.capture_message("debugbundle first-event verification", level="error")
284
+ debugbundle.flush()
285
+ print(debugbundle.get_status(), debugbundle.get_last_event_at())
286
+ ```
287
+
288
+ ## Development
289
+
290
+ ```bash
291
+ pip install -e ".[dev]"
292
+ ruff check .
293
+ mypy src
294
+ pytest
295
+ python -m build
296
+ ```
297
+
298
+ CI validates Ruff, mypy, pytest, package build, event schema fixtures, and coverage gates.
299
+
300
+ ## Documentation
301
+
302
+ - Python SDK docs: <https://debugbundle.com/docs/sdks/python>
303
+ - SDK overview: <https://debugbundle.com/docs/sdks>
304
+ - Browser relay: <https://debugbundle.com/docs/sdks/browser-relay>
305
+ - Repository: <https://github.com/debugbundle/debugbundle-python>
306
+
307
+ ## License
308
+
309
+ AGPL-3.0-only. See `LICENSE`.
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "debugbundle-python"
7
- version = "0.1.6"
7
+ version = "0.1.9"
8
8
  description = "DebugBundle SDK for Python"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.10"