Python SDK for Heimdall observability platform
Project description
Heimdall Python SDK
Synchronous, fail-safe Python client for the Heimdall ingest API. Send telemetry events, errors, and performance metrics from any Python application.
Installation
pip install heimdall-sdk
With FastAPI middleware support:
pip install heimdall-sdk[fastapi]
Quick Start
from heimdall import HeimdallClient
client = HeimdallClient(
api_key="your-api-key",
service_name="payments-api",
environment="production",
)
# Send telemetry events
client.success("payment_processed", metadata={"amount": 150, "currency": "USD"})
client.error("payment_failed", metadata={"reason": "insufficient_funds"})
client.warning("retry_attempt", metadata={"attempt": 2})
client.info("user_login", tags={"region": "us-east"})
client.timeout("external_api_call")
client.canceled("bulk_import")
Error Capture
try:
process_payment(order)
except Exception as exc:
client.capture_exception(exc, endpoint="/checkout")
# exc is NOT re-raised by the SDK
Manual error reporting:
client.send_error(
"PaymentGatewayError",
"Gateway returned 503",
endpoint="/api/payments",
stacktrace=traceback.format_exc(),
)
Performance Tracking
Direct call:
client.send_performance(
"db_query",
target_type="database",
target_name="users",
duration_ms=45,
)
Decorator (automatically measures duration):
@client.track("transfer", target_type="function", include_exceptions=True)
def process_transfer(amount: float) -> dict:
...
Context manager:
with client.timing("bank_sync", target_type="job", target_name="nightly_sync"):
sync_with_bank()
FastAPI Integration
from fastapi import FastAPI
from heimdall import HeimdallClient
from heimdall.integrations.fastapi import setup_heimdall
app = FastAPI()
client = HeimdallClient(api_key="your-api-key", service_name="my-api")
setup_heimdall(app, client)
Every HTTP request automatically gets a request_duration performance metric using the route path template (e.g. GET /users/{user_id}).
Configuration
| Parameter | Type | Default | Description |
|---|---|---|---|
api_key |
str |
required | Heimdall API key |
base_url |
str |
https://heimdall-ob.com/api/v1 |
Override for local development |
enabled |
bool |
True |
Set False to disable all network calls |
raise_on_error |
bool |
False |
Raise HeimdallTransportError on failures |
timeout |
float |
5.0 |
HTTP request timeout in seconds |
service_name |
str |
None |
Injected into every event's tags |
environment |
str |
None |
Injected into every event's tags |
default_metadata |
dict |
None |
Merged into every event's metadata |
default_tags |
dict |
None |
Merged into every event's tags |
Fail-Safe by Default
All send methods return True on success and False on any failure — the SDK never raises into your application unless raise_on_error=True.
result = client.success("order_placed")
if not result:
logger.warning("Heimdall telemetry unavailable")
Development
git clone <repo>
cd heimdall-sdk
pip install -e ".[dev]"
pytest
For more examples see specs/001-heimdall-python-sdk/quickstart.md.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file heimdall_sdk-0.2.0.tar.gz.
File metadata
- Download URL: heimdall_sdk-0.2.0.tar.gz
- Upload date:
- Size: 13.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0e639ce39f5d061b5b0e49da8c4392f665cb21b75ba215c5f10787eb28851c81
|
|
| MD5 |
8ab1d67a33570ce5a03b72c4080e08fc
|
|
| BLAKE2b-256 |
19428ef34f139d4704240bb9f1ed1126fa69236c4caa7dbe913851e0fb683d99
|
File details
Details for the file heimdall_sdk-0.2.0-py3-none-any.whl.
File metadata
- Download URL: heimdall_sdk-0.2.0-py3-none-any.whl
- Upload date:
- Size: 14.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dc0c60afddcbede497e5a02dead3f364933da1e7ca44b0362c7b5c93cc8d6d12
|
|
| MD5 |
06d550c1519ae9ba43485e61180f9064
|
|
| BLAKE2b-256 |
9a4227cb2cabfa6e4ca3b9bd27a729fb7fd5de96b1d5225da45456211451329a
|