Skip to main content

Drop-in activity logging SDK for Python applications — ships logs to a Labrador server.

Project description

Labrador SDK for Python

A lightweight, non-intrusive activity logging SDK. Initialize once, capture events anywhere — logs are buffered and shipped to your Labrador server in the background.

Installation

# Local development
pip install -e ./labrador-sdk

# From PyPI (after publishing)
pip install labrador-sdk

Quick Start

import labrador

# Call once at application startup
labrador.init(
    base_url="http://localhost:8080",
    user_id="user-uuid-here",
)

# Capture events anywhere — non-blocking
labrador.capture("user uploaded a file")
labrador.capture("payment processed successfully")

# Block until all buffered events are shipped (optional)
labrador.flush()

Standard Logging Integration

Route Python's built-in logging module into Labrador:

import logging
import labrador

labrador.init("http://localhost:8080", user_id="service-worker")

# All WARNING+ records from your app will be forwarded to Labrador
logging.getLogger("myapp").addHandler(labrador.get_handler(level=logging.WARNING))

API Reference

labrador.init(base_url, user_id, *, batch_size=20, flush_interval=5.0, max_retries=3, timeout=10.0)

Initialise the SDK. Must be called before any other function. Safe to call again — any previous client is shut down first.

Parameter Type Default Description
base_url str Root URL of your Labrador server
user_id str Identifier attached to every log entry
batch_size int 20 Maximum entries per HTTP request
flush_interval float 5.0 Seconds between automatic background flushes
max_retries int 3 Retry attempts on 5xx / timeout errors
timeout float 10.0 HTTP request timeout in seconds

labrador.capture(message: str) → None

Push a log entry. Non-blocking. Safe to call from any thread. Silently no-ops if init() was not called.

labrador.flush(timeout: float = 5.0) → None

Block until all buffered entries are shipped or timeout elapses.

labrador.shutdown(timeout: float = 5.0) → None

Drain remaining entries, close the HTTP session, and stop the background worker. Called automatically via atexit.

labrador.get_handler(level: int = logging.WARNING) → logging.Handler

Return a logging.Handler that forwards records to Labrador. Raises RuntimeError if init() was not called.

How It Works

capture("msg")  →  LogBuffer (deque, maxlen=500)
                         ↓
BackgroundWorker (daemon thread, wakes every flush_interval)
                         ↓
              drain up to batch_size entries
                         ↓
HttpTransport  →  POST {base_url}/submit-logs
                         ↓
               202 ✓  |  5xx → retry with backoff  |  4xx → drop
  • Buffer drops the oldest entry when full — capture() never blocks the caller.
  • An atexit hook automatically flushes on clean process exit.
  • The worker thread is a daemon — it exits silently if the process is killed.

Server Contract

The SDK sends:

POST /submit-logs
Content-Type: application/json

{
  "logs": [
    {
      "raw_data": "user uploaded a file",
      "action_user_id": "user-uuid",
      "created_at": "2026-03-02T10:00:00+00:00"
    }
  ]
}

Expected response: 202 Accepted.

Running Tests

pip install -e ".[dev]"
pytest

Dependencies

  • Runtime: requests >= 2.28.0
  • Dev: pytest, pytest-mock, responses

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

labrador_sdk_gmi-0.1.0.tar.gz (65.4 kB view details)

Uploaded Source

Built Distribution

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

labrador_sdk_gmi-0.1.0-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

Details for the file labrador_sdk_gmi-0.1.0.tar.gz.

File metadata

  • Download URL: labrador_sdk_gmi-0.1.0.tar.gz
  • Upload date:
  • Size: 65.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for labrador_sdk_gmi-0.1.0.tar.gz
Algorithm Hash digest
SHA256 f46762632b99fb4368f10ef2f7eca0df73e55081c99c35e2246c4f0235f641bc
MD5 d22beee4e7e3f49d9673367ff5a7735a
BLAKE2b-256 63b0674909ccf25010e64d4167df481b8bc67bf7893043a155b30f33796590df

See more details on using hashes here.

File details

Details for the file labrador_sdk_gmi-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for labrador_sdk_gmi-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d6d9e33b82b6143a57b4c56875608e89d7e60d1fa7c61bdbfa2e505ea954d216
MD5 82e59ecabfdf9b3038b840769383c6c9
BLAKE2b-256 19fa29e011a8532f1a5c06f6e40c6f1ba5d5de9feeb5f543776da6c526a5dd8f

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