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
The package includes py.typed, public type aliases such as ReleaseAttributes, SpanAttributes, MetricAttributes, and TraceparentContext, and copyable examples for wiring LogBrew into your Python service. Keep the real key in your app configuration and use preview_json() when you want to inspect queued JSON before sending.
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 examples. Call flush() or shutdown() to send queued events through a transport, and use preview_json() when you want a stable local JSON preview before sending anything.
Metrics
Use metric() for explicit, application-owned measurements. LogBrew validates the metric name, kind, value, unit, temporality, and optional metadata before queueing the event:
from logbrew_sdk import LogBrewClient
client = LogBrewClient.create(
api_key="LOGBREW_API_KEY",
sdk_name="logbrew-python",
sdk_version="0.1.0",
)
client.metric(
"evt_metric_queue_depth",
"2026-06-02T10:00:06Z",
{
"name": "queue.depth",
"kind": "gauge",
"value": 42,
"unit": "{items}",
"temporality": "instant",
"metadata": {"service": "worker"},
},
)
Supported metric kinds are counter, gauge, and histogram. Counters and histograms require delta or cumulative temporality and non-negative values; gauges require instant temporality and may be negative. Keep metadata low-cardinality and primitive. This SDK does not automatically collect runtime or framework metrics yet.
Trace Context
Use the W3C helpers when a Python service needs to interoperate with distributed tracing headers:
from logbrew_sdk import create_traceparent_headers, 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"},
)
headers = create_traceparent_headers(
trace_id=attributes["traceId"],
span_id=attributes["spanId"],
trace_flags="01",
)
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. create_traceparent_headers() returns an explicit outbound carrier with only traceparent for app-owned HTTP clients. 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. The helpers do not patch HTTP clients or capture request payloads.
Agent-Readable Timelines
Use create_product_action_attributes() and create_network_milestone_attributes() when your service already knows important product steps or API milestones. The helpers create normal action event attributes with primitive metadata that AI assistants can analyze across sessions without visual replay, global HTTP patching, payload capture, or header capture.
from logbrew_sdk import (
LogBrewClient,
create_network_milestone_attributes,
create_product_action_attributes,
)
client = LogBrewClient.create(
api_key="LOGBREW_API_KEY",
sdk_name="checkout-api",
sdk_version="1.0.0",
)
client.action(
"evt_checkout_submit",
"2026-06-02T10:00:05Z",
create_product_action_attributes(
{
"name": "checkout.submit",
"status": "running",
"sessionId": "sess_123",
"traceId": "4bf92f3577b34da6a3ce929d0e0e4736",
"routeTemplate": "/checkout/:step",
"funnel": "checkout",
"step": "submit",
"metadata": {"service": "checkout"},
}
),
)
client.action(
"evt_payment_api",
"2026-06-02T10:00:06Z",
create_network_milestone_attributes(
{
"routeTemplate": "/payments/:id",
"method": "POST",
"statusCode": 202,
"durationMs": 94,
"sessionId": "sess_123",
"traceId": "4bf92f3577b34da6a3ce929d0e0e4736",
"metadata": {"service": "checkout"},
}
),
)
Timeline helpers keep only primitive metadata, strip query strings and hashes from route templates, normalize HTTP methods, infer failed network milestones from status codes 400 and above, and serialize through the existing action event type. Keep metadata low-cardinality, such as sessionId, traceId, routeTemplate, method, statusCode, durationMs, screen, funnel, and step.
The packaged agent-timeline example shows a two-event checkout timeline with explicit traceparent propagation and sanitized product/network metadata:
python -m logbrew_sdk.examples agent-timeline
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 canonical LogBrew severities (info, warning, error, critical), 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. Python DEBUG records are captured as info and CRITICAL records as critical; the original Python level name and number remain available in metadata. 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
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 logbrew_sdk-0.1.1.tar.gz.
File metadata
- Download URL: logbrew_sdk-0.1.1.tar.gz
- Upload date:
- Size: 22.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e4ae601154e16e66a7eb1834119e049e0846c73f6dfcfd62551db9146e89c9bf
|
|
| MD5 |
1a6f8b94a81096352db2803ccffae2a6
|
|
| BLAKE2b-256 |
a5d28ac92c9514fb097b40202e5ac36426449d9e4888af1a2f595653e27667c2
|
Provenance
The following attestation bundles were made for logbrew_sdk-0.1.1.tar.gz:
Publisher:
publish-packages.yml on LogBrewCo/sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
logbrew_sdk-0.1.1.tar.gz -
Subject digest:
e4ae601154e16e66a7eb1834119e049e0846c73f6dfcfd62551db9146e89c9bf - Sigstore transparency entry: 1803156974
- Sigstore integration time:
-
Permalink:
LogBrewCo/sdk@2ad6679e80a58ca3e713b9e13be9c315098010fc -
Branch / Tag:
refs/heads/main - Owner: https://github.com/LogBrewCo
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
self-hosted -
Publication workflow:
publish-packages.yml@2ad6679e80a58ca3e713b9e13be9c315098010fc -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file logbrew_sdk-0.1.1-py3-none-any.whl.
File metadata
- Download URL: logbrew_sdk-0.1.1-py3-none-any.whl
- Upload date:
- Size: 17.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f0902204c70879bd1e4c50276c207b463e064009ef3e5284349c235a9c9b9f7a
|
|
| MD5 |
4ca65b82573b1f5d8f49b005794bd9ef
|
|
| BLAKE2b-256 |
24b0af9a06d4b2995ea4f23423587f501fef4ad7562cebee120364e10953079a
|
Provenance
The following attestation bundles were made for logbrew_sdk-0.1.1-py3-none-any.whl:
Publisher:
publish-packages.yml on LogBrewCo/sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
logbrew_sdk-0.1.1-py3-none-any.whl -
Subject digest:
f0902204c70879bd1e4c50276c207b463e064009ef3e5284349c235a9c9b9f7a - Sigstore transparency entry: 1803156996
- Sigstore integration time:
-
Permalink:
LogBrewCo/sdk@2ad6679e80a58ca3e713b9e13be9c315098010fc -
Branch / Tag:
refs/heads/main - Owner: https://github.com/LogBrewCo
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
self-hosted -
Publication workflow:
publish-packages.yml@2ad6679e80a58ca3e713b9e13be9c315098010fc -
Trigger Event:
workflow_dispatch
-
Statement type: