Understand Python
Framework-neutral Python SDK for sending logs and exceptions to Understand.io.
This package is for Python applications. It does not run inside Laravel and it does not reimplement the browser JavaScript SDK. Where it shares configuration names with the Laravel package, that is config parity only.
Installation
Install from PyPI:
python3 -m pip install understand-py
Or add it to requirements.txt:
understand-py
Configuration
Set your Understand.io input token:
export UNDERSTAND_TOKEN="your-input-token"
export UNDERSTAND_ENV="production"
Or configure it directly in code:
from understand import UnderstandConfig
config = UnderstandConfig(
token="your-input-token",
environment="production",
)
Basic Usage
Send a log message:
from understand import UnderstandConfig, UnderstandLogger
logger = UnderstandLogger.from_config(
UnderstandConfig(token="your-input-token", environment="production")
)
logger.error("Understand.io test error", context={"source": "my-app"})
Capture and send an exception:
from understand import UnderstandConfig, UnderstandLogger
logger = UnderstandLogger.from_config(
UnderstandConfig(token="your-input-token", environment="production")
)
try:
raise RuntimeError("Payment capture failed")
except RuntimeError as exc:
logger.exception(exc, context={"feature": "payments"})
Stdlib Logging
Attach Understand to Python's built-in logging package:
import logging
from understand import UnderstandConfig, UnderstandLogger
from understand.integrations.logging import UnderstandLoggingHandler
understand_logger = UnderstandLogger.from_config(
UnderstandConfig.from_env()
)
logging.getLogger().addHandler(UnderstandLoggingHandler(understand_logger))
logging.getLogger().setLevel(logging.INFO)
logging.error("This error is sent to Understand.io")
Exceptions logged with exc_info=True are sent as structured exception events:
try:
raise ValueError("Invalid checkout amount")
except ValueError:
logging.exception("Checkout failed")
Request Context
For web applications, attach request-like metadata before logging:
from understand import RequestContext, UnderstandConfig, UnderstandLogger
logger = UnderstandLogger.from_config(
UnderstandConfig(token="your-input-token", environment="production")
)
logger.field_provider.set_request_context(
RequestContext(
path="/checkout/payments",
method="POST",
route_name="payments.create",
query={"debug": "1"},
body={"amount": 4999, "password": "hidden automatically"},
client_ip="203.0.113.10",
user_agent="Mozilla/5.0",
user_id="user-123",
session_id="session-id",
)
)
Fields like password, password_confirmation, access_token, secret_key,
token, and access_key are replaced with [value hidden] by default.
Environment variables:
UNDERSTAND_TOKENUNDERSTAND_ENABLEDUNDERSTAND_API_URLUNDERSTAND_HANDLERUNDERSTAND_ENVUNDERSTAND_SQLUNDERSTAND_SQL_BINDINGSUNDERSTAND_QUERY_STRINGUNDERSTAND_REQUEST_BODYUNDERSTAND_POST_DATAas a SDK config-parity alias for request body collectionUNDERSTAND_HIDDEN_REQUEST_FIELDSUNDERSTAND_SSL_CA_BUNDLE
For browser JavaScript error tracking, use the separate understand-js SDK.
Long-Running Workers
For long-running workers, call reset_context() between jobs to regenerate the
request token and clear collected data:
for job in jobs:
logger.reset_context()
try:
process_job(job)
except Exception as exc:
logger.exception(exc, context={"job_id": job.id})
Local Testing Without Sending Data
Use CallbackHandler to inspect payloads without making network requests:
import json
from understand import CallbackHandler, UnderstandConfig, UnderstandLogger
events = []
logger = UnderstandLogger.from_config(
UnderstandConfig(token="test-token", environment="local"),
handler=CallbackHandler(lambda payload: events.append(json.loads(payload))),
)
logger.error("Local test error")
print(json.dumps(events, indent=2))
Metadata
Release files for understand-py 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| understand_py-0.1.0.tar.gz | 15.4 kB | With provenance | Details for understand_py-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| understand_py-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for understand_py-0.1.0-py3-none-any.whl |
Total release size: 28.0 kB
Release files / understand_py-0.1.0.tar.gz
| Download URL | understand_py-0.1.0.tar.gz |
|---|---|
| Size | 15.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e01b3b0bb24cdde90fb8574f56ed33a904cd6954ea5c1a25ae4bf55b701d879b
|
|
BLAKE2b-256 checksum How to use checksums |
14100d575d4354ead12bc1d699df61c39b4ff4dc4be016d64d7589121664ff7c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 15, 2026.
Transparency logRelease files / understand_py-0.1.0-py3-none-any.whl
| Download URL | understand_py-0.1.0-py3-none-any.whl |
|---|---|
| Size | 12.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
173015f9c85ea0c89cfe9d6f7214cfa04fe423f5000550ebaf46b2fb37e26996
|
|
BLAKE2b-256 checksum How to use checksums |
d859a743deed6240d382089a612a58e4d161147ec975bcba5a4c2f4ebcfc1564
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 15, 2026.
Transparency logSecurity for understand-py 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for understand_py-0.1.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 15, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.