Skip to main content

Thread-safe Python client for the Log Ingestor service

Project description

streamlogia — Python SDK

Thread-safe Python client for the Streamlogia log ingestion service. Batches and ships log entries in the background while optionally mirroring them to the console. Requires Python 3.8+ and no third-party dependencies.

Installation

pip install streamlogia

Quick start

Set the environment variables once — the SDK picks them up automatically:

export STREAMLOGIA_API_KEY=your-api-key
export STREAMLOGIA_PROJECT_ID=your-project-id

FastAPI

import streamlogia
from fastapi import FastAPI

app = FastAPI()
client = streamlogia.init(app, source="order-service")

Flask

import streamlogia
from flask import Flask

app = Flask(__name__)
client = streamlogia.init(app, source="payment-service")

init() does everything in one call: reads credentials from the environment, attaches request-logging middleware, wires the stdlib root logger to the ingestor, and registers a shutdown hook to flush buffered logs on exit.

Use the returned client for direct log calls, or use logging.getLogger(__name__) anywhere in your app — both route to the ingestor.

import logging

logger = logging.getLogger("order-service")
logger.info("server started")                                    # goes to ingestor
client.info("order created", meta={"order_id": "o_1"})          # also goes to ingestor

init() options

Parameter Type Default Description
app app inst. None Flask or FastAPI/Starlette app. Omit for framework-less usage
source str "unknown" Default source tag applied to every entry
api_key str env var Override STREAMLOGIA_API_KEY
project_id str env var Override STREAMLOGIA_PROJECT_ID
batch_size int 1 Flush the queue when it reaches this many entries
flush_interval float 5.0 Background flush interval in seconds
console bool True Mirror logs to stdout/stderr in addition to the ingestor
log_level int logging.DEBUG Minimum stdlib log level forwarded to the ingestor
on_error callable prints to stderr Called with the exception when an ingest request fails

Logging methods

client.debug("cache miss", meta={"key": "user:99"})
client.info("order created", meta={"order_id": "o_1"}, tags=["orders"])
client.warn("disk usage high", meta={"used_pct": 87})
client.error("db connection failed", meta={"host": "db-1"})

All methods accept:

  • meta — arbitrary dict of structured fields attached to the entry
  • tags — list of string tags for filtering in the UI

Console output

DEBUG and INFO go to stdout; WARN and ERROR go to stderr.

When running under systemd, stdout/stderr are captured by the journal:

journalctl -u your-service -f

Pass console=False to init() if you only want logs in the ingestor and nothing on the terminal.

Framework integrations

Request logging middleware

init() automatically attaches middleware when you pass an app. Each HTTP request produces one log entry after the response is sent, containing:

method, path, status, duration_ms, ip, user_agent, request_id (when X-Request-Id / x-request-id header is present)

Status codes ≥ 500 → ERROR, ≥ 400 → WARN, everything else → INFO.

See examples/fastapi_app.py and examples/flask_app.py for complete examples.

stdlib logging integration

init() wires the stdlib root logger automatically. You can also attach a handler manually to a specific logger:

import logging

logger = logging.getLogger("myapp")
logger.setLevel(logging.DEBUG)
logger.addHandler(client.logging_handler())

logger.info("server started")
logger.error("unhandled exception", exc_info=True)  # traceback captured in meta

# Pass structured fields via extra={"meta": {...}}
logger.info("order created", extra={"meta": {"order_id": "o_1"}})

Do not add a separate StreamHandler — the client's console=True setting already handles stdout/stderr output and a second handler would print every line twice.

Python log levels map as follows:

Python level Ingestor level
DEBUG DEBUG
INFO INFO
WARNING WARN
ERROR / CRITICAL ERROR

Advanced: manual client setup

If you need full control you can create and manage the client directly:

from streamlogia import LogIngestorClient

client = LogIngestorClient(
    api_key="...",       # or omit to read STREAMLOGIA_API_KEY
    project_id="...",    # or omit to read STREAMLOGIA_PROJECT_ID
    source="worker",
    batch_size=50,
    console=False,
)

client.info("job started")
client.close()  # flush before exit

Direct ingestion

Bypass the internal queue to send entries immediately:

response = client.ingest([
    {
        "projectId": "...",
        "level": "INFO",
        "message": "manual entry",
        "source": "script",
        "timestamp": "2026-01-01T00:00:00+00:00",
        "tags": [],
        "meta": {},
    }
])
# {"ingested": 1, "ids": ["..."]}

Migration guide

From logingestor to streamlogia

Version 0.3.0 renames the package module and environment variables. The following changes are required:

Imports

# Before
import logingestor
client = logingestor.init(app, source="my-service")

# After
import streamlogia
client = streamlogia.init(app, source="my-service")

Manual client setup

# Before
from logingestor import LogIngestorClient

# After
from streamlogia import LogIngestorClient

Environment variables

# Before
export LOGINGESTOR_API_KEY=your-api-key
export LOGINGESTOR_PROJECT_ID=your-project-id

# After
export STREAMLOGIA_API_KEY=your-api-key
export STREAMLOGIA_PROJECT_ID=your-project-id

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

streamlogia-0.3.0.tar.gz (8.8 kB view details)

Uploaded Source

Built Distribution

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

streamlogia-0.3.0-py3-none-any.whl (9.4 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for streamlogia-0.3.0.tar.gz
Algorithm Hash digest
SHA256 2001cafc51e2873770dd2e29d39c86b627a8e29f23154e3942183d458f7e62c0
MD5 670736fd32423b2bdaf0d2bf125dea93
BLAKE2b-256 858061eefdcb62c6e06eb18c2563936cfcc0c97f78ab76625a968b963a5574a6

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for streamlogia-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b18eacd80157612566d16d195cf03b758672951a18a92a1d8aa0e9551152dcb8
MD5 83ce2148f6310c2c1e5008d62483bdc5
BLAKE2b-256 d9127f2efd36ff61ecabe3723b0e2b3fbcf338dee5594ecce6d4c17992f2182b

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