Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

heimdall_sdk-0.3.0.tar.gz (14.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

heimdall_sdk-0.3.0-py3-none-any.whl (15.5 kB view details)

Uploaded Python 3

File details

Details for the file heimdall_sdk-0.3.0.tar.gz.

File metadata

  • Download URL: heimdall_sdk-0.3.0.tar.gz
  • Upload date:
  • Size: 14.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.4

File hashes

Hashes for heimdall_sdk-0.3.0.tar.gz
Algorithm Hash digest
SHA256 08851ddacf3f99aeeb09ada34779f638f5084f5d3dd68fe8bc70577e5bc1f847
MD5 d2bf10cf0bd3448f5f8627e9302a09ec
BLAKE2b-256 96c26b87e3741f9ea33da95ee716345056bc7ba0580429401575627accf210c6

See more details on using hashes here.

File details

Details for the file heimdall_sdk-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: heimdall_sdk-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 15.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.4

File hashes

Hashes for heimdall_sdk-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b5fa3a47649b20a96203c283adb5c14dddca8b20762cb66878e7cdcbb826b732
MD5 8fe2cab3c58e045e0e187cb0f81a8841
BLAKE2b-256 eb2a0d8b4dfcedad4cf9849b7c7348adcd70d00998beec672d377bfb47fba436

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page