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.1.0.tar.gz (12.5 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.1.0-py3-none-any.whl (13.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: heimdall_sdk-0.1.0.tar.gz
  • Upload date:
  • Size: 12.5 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.1.0.tar.gz
Algorithm Hash digest
SHA256 125ed448cd7b136b7f6cbcea9a0c66faba2fd6a08aecca1f1ab9a3fedfd9578c
MD5 1bf2036e830e1856595b977523bfe9e5
BLAKE2b-256 b73681af3e7ca953ee8167f56b0425ec131bd1e458c33f37764a16eddb75144a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: heimdall_sdk-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 13.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.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c51f90ea8c66d318f73b184bc8de0707a7cd3a4e868935f5e0f8729f0f761b3b
MD5 fdfae13190e0d77dbdc3efb2b01f9f3a
BLAKE2b-256 bcf12d9598d4f7b5c5cc64779febbe268c0443e65e2241c01325df38172e2751

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