Documentation Python SDK
5 min read | June 24, 2026
Tutorial

Python SDK

The Astralog Python SDK handles event batching and network flushing automatically in a background thread, ensuring zero performance impact on your application.

View on GitHub

Installation

pip install astralog

Initialization

# main.py
from astralog import Client

client = Client(api_key="ast_sk_live_xxxxxxxxxxxxx")

# Upon termination, optionally call close() to flush the queue
# client.close()

Logging API Reference

All methods accept a message string and an optional dict for structured metadata.

1. client.info()

Use for general system events, successful actions, or checkpoints.

client.info("User registered", {
    "user_id": "usr_99283",
    "plan": "premium"
})

2. client.warn()

Use for non-fatal issues, retries, or rate limits approaching.

client.warn("Rate limit approaching", {
    "tenant_id": "org_123",
    "remaining_quota": 5
})

3. client.error()

Use for exceptions, fatal crashes, or 5xx HTTP responses.

try:
    db.connect()
except Exception as e:
    client.error("Database connection failed", {
        "db_host": "10.0.0.5",
        "error_msg": str(e)
    })

4. client.debug()

Use for verbose information that helps during active development or deep troubleshooting.

client.debug("Cache miss, querying DB", {
    "cache_key": "user_profile_99283",
    "latency_ms": 12.4
})

5. client.event()

The underlying raw method. Allows you to specify custom event levels dynamically.

client.event("critical", "System overheating", {
    "temperature": 95
})

Fail-Open Architecture

The Python SDK queues events in a thread-safe Queue and spawns a daemon thread for flushing. If the queue is saturated (i.e. your application is producing events much faster than the network can handle), the SDK will transparently drop the incoming events. This Fail-Open design guarantees that your application will never crash with an OutOfMemoryError due to logging telemetry.