Skip to main content

Logstack Python SDK

A Python SDK for the Logstack logging platform.

Installation

pip install logstack-py

The import name is still logstack (e.g. from logstack import LogStackClient).

v1.0.2

  • capture_logging default on. Automatically forwards stdlib logging calls with source: "python-logging". Original handlers (console, etc.) are preserved.
  • Lowers root logger level when needed so info / debug records reach the capture handler.
  • Skips re-entrant capture from the internal Logstack logger.

v1.0.1

  • Fix batch-flush deadlock when batch_size is reached
  • Normalize API URL (strips redundant /v1 suffix)
  • Optional on_error callback; accepts HTTP 201 from ingest API
  • create_fastapi_middleware(client) for proper FastAPI/Starlette integration

Usage

Basic Usage

from logstack import LogStackClient

# Create a client
# capture_logging=True (default): any logging.getLogger(...).info / error etc.
# is automatically captured and sent with source="python-logging".
# Your normal logging configuration (console handlers etc.) continues to work.
client = LogStackClient(
    api_key="your-api-key",
    environment="production",
)

# Explicit structured logs
client.info("Application started", metadata={"version": "1.0.0"})
client.error("Database connection failed", metadata={"error": "connection refused"})

# Flush and close
client.close()

Automatic stdlib logging capture

By default capture_logging=True. All Python logging calls across your app (including libraries) are forwarded:

import logging
from logstack import LogStackClient

client = LogStackClient(api_key="...")  # capture_logging=True by default

log = logging.getLogger(__name__)
log.info("User action", extra={"user_id": 123})   # <- captured automatically
log.error("Failed to process")                    # <- captured as error level

The original log records still go to any handlers you have configured (StreamHandler, etc.).

Disable with capture_logging=False if you only want explicit client.xxx() calls.

Using Context Manager

from logstack import LogStackClient

with LogStackClient(api_key="your-api-key") as client:
    client.info("Application started")
    client.error("Something went wrong")

Django Integration

# settings.py
MIDDLEWARE = [
    # ...
    'logstack.middleware.DjangoMiddleware',
    # ...
]

# Or with custom client
MIDDLEWARE = [
    # ...
    'logstack.middleware.DjangoMiddleware',
    # ...
]

# In your code
from logstack import DjangoMiddleware, LogStackClient

client = LogStackClient(api_key="your-api-key")
middleware = DjangoMiddleware(get_response, client=client)

FastAPI Integration

from fastapi import FastAPI
from logstack import LogStackClient, FastAPIMiddleware

app = FastAPI()
client = LogStackClient(api_key="your-api-key")
FastAPIMiddleware(app, client=client)

API Reference

LogStackClient(api_key, ..., capture_logging=True)

Create a new Logstack client.

info(message, metadata=None)

Send an info level log.

debug(message, metadata=None)

Send a debug level log.

warn(message, metadata=None)

Send a warn level log.

error(message, metadata=None)

Send an error level log.

critical(message, metadata=None)

Send a critical level log.

fatal(message, metadata=None)

Send a fatal level log and flush immediately.

flush()

Manually flush the batch of logs.

close()

Close the client and flush any pending logs.

License

MIT

Metadata

Release files for logstack-py 1.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for logstack-py 1.0.2
File Size Uploaded Provenance
logstack_py-1.0.2.tar.gz 7.1 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for logstack-py 1.0.2
File Interpreter ABI Platform
logstack_py-1.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 14.8 kB

Release files / logstack_py-1.0.2.tar.gz

Download URL logstack_py-1.0.2.tar.gz
Size 7.1 kB
Tags Source
SHA-256 checksum
How to use checksums
5de7a8c1e6f9bcb8144ecc41200332a5d0a6fdf7fae104a452fe5f7f2b373270
BLAKE2b-256 checksum
How to use checksums
2c9d63cd4d54fba690559523147ab0087edb28e531ae861b2ff0af14e3d482f9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.5

Release files / logstack_py-1.0.2-py3-none-any.whl

Download URL logstack_py-1.0.2-py3-none-any.whl
Size 7.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
69d10660c2e54f3c3a494dc5ba6b3407974557d8aeecf8a4d99dff76bd7c6821
BLAKE2b-256 checksum
How to use checksums
f802d21fbc4438e8ae8751e9e31eaeb06669be0c096cc19e3a907213ea4fec00
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.5

Security for logstack-py 1.0.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0.2 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page