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:
- Standard
logginglevels — records are only created if the logger's level allows them. To shipDEBUG/INFO, make sure the level permits it (or passcapture_level=logging.DEBUGtostart()). - 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.
What your app prints stays as it is. Python prints warnings and errors by itself only while no handler is attached, so the SDK prints them the same way when it is the only handler; once your app configures logging, its own handlers decide.
start() takes your app's version from the nearest pyproject.toml ([project] or [tool.poetry]), from the working directory up. Pass app_version="1.4.0" to set it yourself.
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, and an exception your code didn't handle is sent as an error of that request.
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.
On Django the signed-in user is attached without an extractor, once your view has read request.user: its id, username and email. The middleware never loads the user itself. Override get_user to attach something else, or to return None and attach nobody.
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.
An exception raised from another one names its cause in its reason: could not load the order (caused by KeyError: 'missing').
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.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| shipbook-0.3.0.tar.gz | 55.0 kB | Without provenance | Details for shipbook-0.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| shipbook-0.3.0-py3-none-any.whl | Python 3 | none | any | Details for shipbook-0.3.0-py3-none-any.whl |
Total release size: 98.6 kB
Release files / shipbook-0.3.0.tar.gz
| Download URL | shipbook-0.3.0.tar.gz |
|---|---|
| Size | 55.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a4c594504df668c3ae36e24f1cd79570617fea4757f91c846387a4a604e99981
|
|
BLAKE2b-256 checksum How to use checksums |
667c10ab1e1c2ff8c840934a6c29e0a84e7b289adab1edc168f6153432cd51ec
|
| 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.3.0-py3-none-any.whl
| Download URL | shipbook-0.3.0-py3-none-any.whl |
|---|---|
| Size | 43.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a4a7896829b5a0a9e04507ae121687246ebb1a1ec6ba7e3b1508df0012864f2c
|
|
BLAKE2b-256 checksum How to use checksums |
230dd36606ee9b7f0c587ab40200489d1b84f360eda4718ffeb1a95fa27dc721
|
| 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.3.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.