Skip to main content

Public LogBrew Python SDK for building, validating, and flushing event batches.

Project description

logbrew-sdk

Public Python SDK for creating LogBrew event batches, validating them locally, and flushing them through a transport.

Install

python3 -m pip install logbrew-sdk
python3 -m logbrew_sdk.examples --help
python3 -m logbrew_sdk.examples --list
python3 -m logbrew_sdk.examples readme-example
python3 -m logbrew_sdk.examples real-user-smoke
python3 -m logbrew_sdk.examples
python3 -m logbrew_sdk.examples.readme_example
python3 -m logbrew_sdk.examples.real_user_smoke

The built wheel should also carry py.typed and wheel metadata with the expected package description before install. Normal installs also expose standard package metadata like pip show logbrew-sdk, pip show -f logbrew-sdk, pip list --format=json, pip freeze, and importlib.metadata.version("logbrew-sdk"). The plain pip show summary should keep the expected package name, version, summary, author, license expression, and site-packages install location. The built source distribution should also carry README.md, pyproject.toml, py.typed, and the packaged logbrew_sdk.examples.readme_example plus logbrew_sdk.examples.real_user_smoke modules in the archive itself. Both wheel and source-distribution installs carry the expected py.typed, example modules, and dist-info metadata files in site-packages, and that installed metadata keeps the pip install command, fake LOGBREW_API_KEY placeholder, preview_json() guidance, and packaged examples entrypoint commands a user would expect from the package description. Those installs should also keep pip-written INSTALLER, direct_url.json, --report, pip inspect, plain pip show summary fields, pip show -f file listings, and pip list --format=json package listings plus the expected pip freeze file URL with sha256 provenance so tooling can confirm the package came from the expected wheel or source-distribution artifact, the installed environment should stay clean under python -m pip check, both the wheel and source-distribution paths should survive a clean python -m pip uninstall -y logbrew-sdk removal before reinstalling the same artifact, a small installed-user python -m unittest run should still succeed, the published README example should still run from the installed package on both the main install and the reinstall paths, and the packaged examples entrypoint should be discoverable and runnable through python -m logbrew_sdk.examples --help, python -m logbrew_sdk.examples --list, python -m logbrew_sdk.examples readme-example, python -m logbrew_sdk.examples real-user-smoke, python -m logbrew_sdk.examples, python -m logbrew_sdk.examples.readme_example, and python -m logbrew_sdk.examples.real_user_smoke, with both --help and --list printing copy-pasteable packaged-example commands, including explicit named README-example and real-user-smoke entrypoint commands plus the default no-argument python -m logbrew_sdk.examples path being called out explicitly as the real-user-smoke entrypoint, instead of only generic argument help or bare example names. A one-line direct requirements file derived from that freeze output should also reinstall cleanly under python -m pip install --require-hashes -r ... in a fresh virtual environment. The installed module, public payload shape types like ReleaseAttributes, SpanAttributes, and TraceparentContext, LogBrewClient, HttpTransport, RecordingTransport, SdkError, TransportResponse, TransportError, W3C trace helpers like parse_traceparent(), create_traceparent(), and span_attributes_from_traceparent(), and key lifecycle methods like create(), preview_json(), flush(), shutdown(), pending_events(), always_accept(), and TransportError.network() also expose stable docstrings that tools like help(...) can show after install. Installed wheel and sdist paths now both prove the field-level typing metadata for commonly inspected attributes like TransportResponse.status_code, TransportResponse.attempts, and RecordingTransport.sent_bodies, prove the typed consumer through a temp pyproject.toml-driven mypy config, and prove a consumer-owned Makefile that wraps the installed-user typecheck, unittest, README-example, packaged-example, packaged examples list, packaged examples help, packaged examples entrypoint, packaged real-user example, and happy-path smoke commands instead of relying only on loose raw commands, with plain make printing copy-pasteable make smoke-... commands and the shorter make smoke-run path labeled explicitly as the real-user-smoke flow.

Example

import json
import sys

from logbrew_sdk import LogBrewClient, RecordingTransport

client = LogBrewClient.create(
    api_key="LOGBREW_API_KEY",
    sdk_name="logbrew-python",
    sdk_version="0.1.0",
)

client.release(
    "evt_release_001",
    "2026-06-02T10:00:00Z",
    {
        "version": "1.2.3",
        "commit": "abc123def456",
        "notes": "Public release marker",
    },
)
client.environment(
    "evt_environment_001",
    "2026-06-02T10:00:01Z",
    {"name": "production", "region": "global"},
)
client.issue(
    "evt_issue_001",
    "2026-06-02T10:00:02Z",
    {
        "title": "Checkout timeout",
        "level": "error",
        "message": "Request timed out after retry budget",
    },
)
client.log(
    "evt_log_001",
    "2026-06-02T10:00:03Z",
    {"message": "worker started", "level": "info", "logger": "job-runner"},
)
client.span(
    "evt_span_001",
    "2026-06-02T10:00:04Z",
    {
        "name": "GET /health",
        "traceId": "trace_001",
        "spanId": "span_001",
        "status": "ok",
        "durationMs": 12.5,
    },
)
client.action(
    "evt_action_001",
    "2026-06-02T10:00:05Z",
    {"name": "deploy", "status": "success"},
)

print(client.preview_json())

transport = RecordingTransport.always_accept()
response = client.shutdown(transport)
print(
    json.dumps(
        {"ok": True, "status": response.status_code, "attempts": response.attempts, "events": 6}
    ),
    file=sys.stderr,
)

Use a clearly fake placeholder like LOGBREW_API_KEY in local examples and tests. Call flush() or shutdown() to send queued events through a transport, and use preview_json() when you want a stable local JSON preview without sending anything.

Trace Context

Use the W3C helpers when a Python service needs to interoperate with distributed tracing headers:

from logbrew_sdk import parse_traceparent, span_attributes_from_traceparent

traceparent = "00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01"
context = parse_traceparent(traceparent)
attributes = span_attributes_from_traceparent(
    traceparent,
    name="GET /health",
    span_id="b7ad6b7169203331",
    status="ok",
    duration_ms=12.5,
    metadata={"service": "checkout"},
)

parse_traceparent() validates W3C shape, rejects all-zero trace/span IDs, normalizes IDs to lowercase, and exposes the sampled flag. span_attributes_from_traceparent() returns LogBrew span attributes with traceId from the incoming trace and parentSpanId from the incoming parent span. FastAPI and Django integrations use these helpers automatically for valid inbound traceparent headers and start a fresh synthetic span when the header is missing or malformed.

HTTP Delivery

Use HttpTransport for real outbound delivery from server-side Python apps:

from logbrew_sdk import HttpTransport, LogBrewClient

client = LogBrewClient.create(
    api_key="LOGBREW_API_KEY",
    sdk_name="logbrew-python",
    sdk_version="0.1.0",
)
transport = HttpTransport(
    endpoint="https://api.logbrew.com/v1/events",
    headers={"x-logbrew-source": "python-worker"},
)

client.log(
    "evt_worker_started",
    "2026-06-02T10:00:06Z",
    {"message": "worker started", "level": "info", "logger": "worker"},
)
client.flush(transport)

HttpTransport uses Python's standard-library HTTP stack, posts JSON, passes the SDK key through the authorization header, supports custom endpoint/header/timeout settings, and maps connection failures into retryable TransportError.network(...) failures so LogBrewClient.flush() can preserve queued events and retry.

Standard Logging

Use LogBrewLoggingHandler when an application already uses Python's standard logging module:

import logging

from logbrew_sdk import LogBrewClient, LogBrewLoggingHandler, RecordingTransport

client = LogBrewClient.create(
    api_key="LOGBREW_API_KEY",
    sdk_name="logbrew-python",
    sdk_version="0.1.0",
)
transport = RecordingTransport.always_accept()
handler = LogBrewLoggingHandler(
    client,
    transport,
    flush_on_emit=True,
    metadata={"service": "checkout"},
)

logger = logging.getLogger("checkout.worker")
logger.addHandler(handler)
logger.setLevel(logging.INFO)

logger.info("worker started", extra={"order_id": "ord_123"})

The handler does not change global logging configuration. It maps standard logging levels into LogBrew log levels, keeps the logger name, captures primitive extra={...} values as metadata, and records source file name, function, line, thread, and process names without sending the full source path by default. Exception type and message are captured when exc_info is present; full exception text is opt-in with include_exception_text=True.

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

logbrew_sdk-0.1.0.tar.gz (18.9 kB view details)

Uploaded Source

Built Distribution

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

logbrew_sdk-0.1.0-py3-none-any.whl (14.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: logbrew_sdk-0.1.0.tar.gz
  • Upload date:
  • Size: 18.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for logbrew_sdk-0.1.0.tar.gz
Algorithm Hash digest
SHA256 b58c81039f23f5ac8099dd7fb436a33dcfbd1c7492af62df1b32816f83c14d47
MD5 f2d8fec909173377072911b68aeab5d0
BLAKE2b-256 72f5e5500628c7cb98d8fea9669376676c80336271351ad8a53801856c768292

See more details on using hashes here.

Provenance

The following attestation bundles were made for logbrew_sdk-0.1.0.tar.gz:

Publisher: publish-packages.yml on LogBrewCo/sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

  • Download URL: logbrew_sdk-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 14.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for logbrew_sdk-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 dc87eb7afc4ef375e1e6a763e314ddfe04b83695e161f6c3775b3de1af44e81c
MD5 c4d2b87be70fd8026545df1222f37a17
BLAKE2b-256 176e3274967bd2e6e17994f46ee56f75f666b8000e8616520983e22bc7c0e132

See more details on using hashes here.

Provenance

The following attestation bundles were made for logbrew_sdk-0.1.0-py3-none-any.whl:

Publisher: publish-packages.yml on LogBrewCo/sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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