# Python SDK Use the Python SDK archive for application logs, spans, and exceptions while public PyPI publishing awaits approval. ## Availability and installation The Python SDK implementation is available as an installable archive. Public PyPI publishing is waiting for organization approval, and the Python tab is temporarily hidden in the setup UI. Do not assume `pip install prilog-monitoring` is available from PyPI. Requires Python 3.9 or later. Install the public runtime archive: ```bash python -m pip install https://prilog.ai/api/monitoring/sdk/0.1.0/python.tar.gz ``` Create a monitoring connection in Prilog and copy its DSN into `PRILOG_DSN`. The public SDK archive contains runtime code and its MIT license, with no customer credentials. ## Initialize before application imports ```python import os import logging from prilog_monitoring import init, span, capture_exception monitoring = init( dsn=os.environ.get("PRILOG_DSN"), service_name="checkout-api", environment="production", release="1.0.0", ) with span("checkout.validate"): logging.warning("Order validation started") # In an existing handled-error path: try: raise ValueError("Payment declined") except ValueError as error: capture_exception(error) if monitoring is not None: monitoring.shutdown() ``` Without a DSN, `init` returns `None` and monitoring remains disabled. The guarded shutdown call above suits a short script. For a long-running service, keep the monitor alive and call `shutdown()` in the service's graceful-shutdown path. The SDK also registers an `atexit` handler. ## Instrumentation and configuration `init` accepts `dsn`, `service_name`, `environment`, `release`, `sample_rate`, and `auto_instrument`. Initialize before importing the application libraries you want to instrument. Install the compatible OpenTelemetry instrumentor packages for your frameworks and clients; the SDK discovers installed instrumentor plugins. Python logging, global exceptions, and thread exceptions are captured. Use `span(name, attributes=None)` as a context manager for explicit work and `capture_exception(error, attributes=None)` in handled-error paths. Error capture records the exception without changing your application's handling. ## Asyncio and lifecycle Call `instrument_asyncio(loop)` from `prilog_monitoring` for an event loop you own. It records unhandled loop errors while preserving the previous or default exception handler. Keep context around asynchronous work you own, and flush telemetry before a short-lived process exits. Use [troubleshooting](/docs/troubleshooting/#no-monitoring-data-arrives) if the startup signals do not appear.