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— arbitrarydictof structured fields attached to the entrytags— 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
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 streamlogia-0.2.0.tar.gz.
File metadata
- Download URL: streamlogia-0.2.0.tar.gz
- Upload date:
- Size: 8.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b4c474532d4d9416519c9e9b744248621142dd0aed2284e170cb2917157bfa04
|
|
| MD5 |
f7bfcee9b2c7953777e35177c347d083
|
|
| BLAKE2b-256 |
4044dd6dc94aa0c17034737b85a469398a0e18692ebcc7a910e87862a9790d23
|
File details
Details for the file streamlogia-0.2.0-py3-none-any.whl.
File metadata
- Download URL: streamlogia-0.2.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2837757d4b0dde46daec5efd5e1b65e0f0bf2b155ff180c449388ee4d9cd02d2
|
|
| MD5 |
e92cd17f04b1cdba270e2bbade8e304e
|
|
| BLAKE2b-256 |
853d5fc58951cd2803a34196a33cb051779da5ae2d422e8d2625a1bfa3075b30
|