Skip to main content
Yanked

This release has been yanked by its maintainers, and will be ignored by installers, except when explicitly specified.
Consider using release 0.3.1 instead.
Reason given by maintainers: Retries a rejected login in a loop; fixed in 0.3.0, use 0.3.1.

Shipbook Python SDK

Ship your Python server logs to Shipbook — with zero new logging API to learn. The SDK plugs into Python's standard logging module, so the code you already write just works:

import logging
import shipbook

shipbook.start(app_id="YOUR_APP_ID", app_key="YOUR_APP_KEY")

log = logging.getLogger(__name__)
log.info("user signed in")
log.error("payment failed", exc_info=True)

Every logging call in your process is captured, batched, and uploaded to Shipbook in the background. Source location (file, function, line), the logger name (as the tag), thread info, and exception tracebacks all come across automatically — because Python's logging already records them.

Install

pip install shipbook

Zero required dependencies. Optional framework helpers:

pip install "shipbook[fastapi]"   # or [flask], [django], [mcp]

How it works

shipbook.start() attaches a single ShipbookHandler to the root logger and returns at once; it logs in to Shipbook on a background thread, so an unreachable API never delays your app's startup. There is no separate Shipbook logging API — ShipbookHandler is the SDK. Logs are kept in memory and uploaded in batches by a background thread; nothing on your request path blocks on the network, and nothing is written to disk.

What ships is controlled by two independent gates:

  1. Standard logging levels — records are only created if the logger's level allows them. To ship DEBUG/INFO, make sure the level permits it (or pass capture_level=logging.DEBUG to start()).
  2. Server-side config — Shipbook's dashboard controls which tags/severities are actually uploaded, and can be changed without a redeploy. Until the first config arrives, logs are held and then filtered by it, so a filter set in the dashboard also applies to startup logs.

With the Accumulate config, logs below the warning level are held per request and uploaded only when that request logs a warning or error — as their context. Healthy requests cost nothing.

To point the SDK at another Shipbook API (for example a staging environment), call shipbook.set_connection_url(url) before start().

Attaching to a specific logger

By default the handler is attached to the root logger. To scope it yourself:

shipbook.start(app_id="...", app_key="...", attach_to_root=False)
logging.getLogger("myapp").addHandler(shipbook.get_handler())

Web frameworks — read your server request by request

A LogRecord doesn't know which request it belongs to. The framework integrations bind each request to a Shipbook session, so logs carry the user, client IP, and trace id. Each request is also recorded with its method, route (/items/{item_id}), status and duration, and its logs are grouped under it in the Logbook. A failed request (5xx) is always recorded, even if it logged nothing.

FastAPI / Starlette

from shipbook.integrations.fastapi import ShipbookMiddleware
app.add_middleware(ShipbookMiddleware)

Flask

from shipbook.integrations.flask import init_app
init_app(app)

Django (sync and async views) — add to MIDDLEWARE, after SessionMiddleware and AuthenticationMiddleware:

"shipbook.integrations.django.ShipbookMiddleware"

Customize each request with extractors (FastAPI/Flask keyword arguments; on Django, subclass and override get_user, get_session_id, get_trace_id, get_attributes):

app.add_middleware(
    ShipbookMiddleware,
    user_extractor=lambda request: shipbook.User(user_id=request.headers.get("x-user-id")),
    session_extractor=lambda request: request.cookies.get("login"),  # group requests into one session
    attributes_extractor=lambda request: {"tenant": request.headers.get("x-tenant")},
)

Or call shipbook.register_user(...) anywhere inside the request. By default every request is its own session; on Django a request joins its Django session when it has one.

Linked apps. When a client app with a Shipbook SDK calls your API, it sends an x-shipbook-session header. The request joins that client session, so the Logbook shows the whole flow — the app's logs and your server's — in one view.

JSON-RPC and MCP over HTTP. A JSON-RPC call is labeled with what it asked for, e.g. tools/call get-logs, so calls to one endpoint stay apart.

MCP servers

For an MCP server built with the mcp SDK (2.x), add the middleware and every call becomes a request, labeled with its operation, over any transport (stdio included):

from mcp.server.mcpserver import MCPServer
from shipbook.integrations.mcp import ShipbookMiddleware

server = MCPServer("my-server", middleware=[ShipbookMiddleware()])

A tool that fails, raises or returns isError, is recorded as a failed request with its JSON-RPC error code.

Background jobs

Wrap background work so its logs are grouped as a named session:

with shipbook.run_in_context(job_name="nightly-billing"):
    logging.getLogger(__name__).info("charging customers")

Each run is its own session and counts as one request, like an HTTP request: it appears in the request counts and error rates, and the Logbook shows when it started, how long it took, and whether it raised.

Anything logged outside a request or job falls back to a per-process background session — nothing is lost.

To read other units of work (a queue message, a scheduled task) the way requests are read, run each one as a request:

with shipbook.run_in_request(shipbook.RequestKind.Rpc, "process order"):
    process(order)

It's recorded with its duration and whether it finished or raised.

Threads and executors

contextvars follow await and asyncio tasks automatically, but a manually spawned thread or executor starts with a fresh context and would lose the request's user/IP. Wrap the callable to carry the current context along:

pool.submit(shipbook.preserve_context(do_work))

Crashes and shutdown

An uncaught exception is captured and uploaded before Python prints it and exits, so the crash that killed your process reaches Shipbook. Exceptions in other threads are captured too, and exceptions in asyncio tasks arrive through logging.

Crashes are grouped in Loglytics by the innermost stack frame of your own code; frames from installed packages and the standard library are skipped. If your app is itself installed as a package (pip install .), name it so its frames count as yours:

shipbook.start(app_id="...", app_key="...", in_app_include=["myapp"])

Queued logs are uploaded before the process ends: at interpreter exit and on SIGTERM/SIGINT (a container stop or a deploy), waiting at most 2 seconds. Your own signal handlers still run afterwards, and a default SIGTERM still terminates the process. To flush or stop explicitly:

shipbook.flush()      # upload now and wait; flush(timeout=2) to bound it
shipbook.shutdown()

Forked workers (for example gunicorn with --preload) each upload their own logs.

Troubleshooting

shipbook.enable_inner_log(True) prints the SDK's own diagnostics (login, uploads) to stderr.

License

MIT

Metadata

Release files for shipbook 0.2.0

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

Source distribution (sdist)

Source distribution for shipbook 0.2.0
File Size Uploaded Provenance Actions
shipbook-0.2.0.tar.gz 42.7 kB Without provenance Details for shipbook-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for shipbook 0.2.0
File Interpreter ABI Platform Actions
shipbook-0.2.0-py3-none-any.whl Python 3 none any Details for shipbook-0.2.0-py3-none-any.whl

Total release size: 82.3 kB

Release files / shipbook-0.2.0.tar.gz

Download URL shipbook-0.2.0.tar.gz
Size 42.7 kB
Tags Source
SHA-256 checksum
How to use checksums
19f71a54c5cd04700bcf2bd2b19633e808d8c5826f63222503f9548c51264844
BLAKE2b-256 checksum
How to use checksums
2c97f2b487a4863d82cab78f2184df0a1a47d984c8f0755309c0bf7fdacf436d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.3

Release files / shipbook-0.2.0-py3-none-any.whl

Download URL shipbook-0.2.0-py3-none-any.whl
Size 39.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0f37555c38f3e944c86a2304a23040d99213e207cfcaeca9c96b83786b9f85ec
BLAKE2b-256 checksum
How to use checksums
2999bc17981e3ce5feeaa815b440436f246425e0c43e3692c7a5761edcfbf623
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.3

Security for shipbook 0.2.0

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

0.2.0 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