Skip to main content

A Python SDK for the Logstack logging platform

Project description

Logstack Python SDK

A Python SDK for the Logstack logging platform.

Installation

pip install logstack-py

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
client = LogStackClient(
    api_key="your-api-key",
    environment="production",
)

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

# Flush and close
client.close()

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, api_url="https://api.logstack.tech", environment="production", flush_interval=5.0, batch_size=100)

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

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

logstack_py-1.0.1.tar.gz (6.2 kB view details)

Uploaded Source

Built Distribution

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

logstack_py-1.0.1-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

Details for the file logstack_py-1.0.1.tar.gz.

File metadata

  • Download URL: logstack_py-1.0.1.tar.gz
  • Upload date:
  • Size: 6.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for logstack_py-1.0.1.tar.gz
Algorithm Hash digest
SHA256 0023941c1f1c060fbbda4ee612d69a4586bb7aad42084c2d49882087a0e1a08f
MD5 0e6f006108ed31476097e3a132bb62d1
BLAKE2b-256 ca0e55cddd4f53c3a6ea1194c980ee60a765ec6bf312a4bf85e7ee5c78597a31

See more details on using hashes here.

File details

Details for the file logstack_py-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: logstack_py-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 6.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for logstack_py-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3dc4f2d5571044215fc413cf8118a7be22e5ab0eb2f51e23d99b5ecd2f0c1efa
MD5 c6bce225fcd77147cd5dca94b0ace2b7
BLAKE2b-256 72dc1929a7643072d89e933eab00bd3a3dd7eacde9d4d36f65bb9a9a65e192ae

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