Skip to main content

Jetstream Lakehouse

jetstream-lakehouse is a Python 3.10+ destination-neutral client for Jetstream v2 archive snapshots and its canonical live WebSocket. It contains no sink, checkpoint store, Spark, Databricks, Kafka, or Snowflake code. Downstream consumers own delivery and durable cursor storage.

The archive decoder is adapted from the Apache-2.0 licensed Databricks Community Connector Bluesky source. See NOTICE for attribution. It verifies archive generations, exact byte ranges, xxh3 metadata checksums, Zstandard checksums and sizes, CBOR structure, and sequence ordering. Exact collection/DID/kind matching happens after decoding.

Install

Install the latest published version with:

pip install jetstream-lakehouse

For development from a checkout, use uv for the environment, lock, and build:

uv sync --locked
uv build

See RELEASING.md for the TestPyPI and PyPI release process.

This package is a library and does not load configuration from environment variables or provide a command-line entry point. Pass settings to Config directly. Keep credentials in your application's secret store; api_key is optional and applies only to Jetstream archive requests.

Public API

from jetstream_lakehouse import ArchivePlan, Client, Config
from contextlib import closing

config = Config(
    endpoint="https://jetstream.us-east.bsky.network",
    api_key="",  # optionally pass an archive API key from your application's secret store
    collections=("app.bsky.feed.post",),
    kinds=("commit", "identity", "account", "sync"),
    max_sequence_span=10_000,
)
client = Client(config)

# One bounded sealed-archive range: events in (after_seq, through_seq].
batch = client.snapshot(after_seq=123456)
for event in batch.events:
    process(event)
print(batch.through_seq)  # candidate cursor, including valid zero-event windows

# Discover once, then persist plans for bounded windows across processes.
target = client.sealed_tip(after_seq=123456)
if target > 123456:
    before = min(target, 123456 + config.max_sequence_span)
    plan_json = client.plan_snapshot(123456, before).to_json()
    restored = ArchivePlan.from_json(plan_json)
    batch = client.read_plan(restored)  # performs no planner requests

# Explicit cursor resumes history; omit cursor only to follow from the current live tip.
with closing(client.live(cursor=123456)) as stream:
    for event in stream:
        process(event)

# Backfill bounded archive batches, then continue as one-event live batches.
with closing(client.replay(after_seq=123456)) as stream:
    for batch in stream:
        write_to_sink(batch.events)
        await_durability()
        save_cursor(batch.through_seq)

Event is immutable and uses the same fields for archive and live input: seq, event_time, witnessed_at, did, kind, operation, collection, rkey, cid, rev, is_resync, record, event_payload, and optional raw_payload_base64. JSON values are compact JSON strings. Missing values are None. Raw archive CBOR is base64 text and is not available on live events. Create, update, delete, identity, account, sync, and resync markers remain individual events; this client does not fold them into current-record state.

event_payload contains the record for creates/updates, the original upstream marker object for identity/account/sync, and None for deletes. It has the same shape in both modes. JSON keys are sorted and timestamps are normalized to UTC. A sync's rev is extracted from its marker object.

Archive ranges are exclusive/inclusive: (after_seq, through_seq]. A returned through_seq means the complete range was validated, including when filters matched no events. It is only a candidate cursor; the caller persists it after its own destination confirms durability. If a write fails, resume from the caller's last saved cursor. This provides at-least-once delivery to the caller, not exactly-once persistence in an external system.

snapshot requires an explicit after_seq and reads at most max_sequence_span. A window can start and end inside a physical segment. replay pins one sealed tip for the whole backfill, then connects live at that boundary. Segments sealed during backfill arrive through the server's cold replay. If live lookback expires, replay discovers a new archive boundary from its last yielded cursor; if the archive cannot bridge the gap yet, it raises CursorTooOld without skipping ahead.

sealed_tip(after_seq) discovers the complete sealed boundary without downloading segments. It can return a value below the supplied cursor; the application chooses whether this means no backfill or a checkpoint recovery. Discovery never moves the cursor. A no-work case is target <= checkpoint, so no plan needs to be created. Plan bounded windows repeatedly toward the fixed target; the planner's sealedTipSeq can be clipped by each before_seq and is not the complete head.

plan_snapshot(after_seq, before_seq) collects and validates every planner page without fetching segment bytes. Call ArchivePlan.to_json() to persist the exact page windows, checksums, and block selections, then restore with ArchivePlan.from_json() and pass it to read_plan(). Format version 1 is deterministic JSON; future supported readers will continue to read v1 plans or reject them explicitly if support is removed. The source-scope fingerprint binds the normalized endpoint and filters, but is not a signature. Tokens and operational settings are not serialized. Credentials may rotate and read time/byte limits may change; the destination client must still use the same source scope. Imported plans are bounded to the library's hard 1,000,000-sequence span and the current read byte/time limits still apply.

Each separate planning or plan-reading call has its own refresh budget. snapshot() retains one shared budget for planning and reading. Batch byte accounting bounds serialized event rows; it is not a hard process-RSS limit because decoded objects and transport buffers add overhead. A saved plan has no live session or deadline. If a recorded segment generation changes or disappears, read_plan() raises ArchiveChanged and never replans automatically. Treat that as a failure needing caller intervention. In every mode, persist through_seq only after all returned events are durable.

live(cursor=None) starts at the current live tip. Numeric cursors are sequences; live values at or above 10**15 are rejected because the server would interpret them as timestamps. Transient connection errors, timeouts, HTTP 429/5xx, and ConsumerTooSlow reconnect from the last yielded sequence, suppressing repeats. max_retries bounds consecutive failures and resets after forward event progress. Restart after a destination failure with the application's last saved cursor.

Live uses one buffered WebSocket frame and a max_batch_bytes message limit. Calls yield one event at a time to apply backpressure. Use closing(...) when a loop may exit early. Pass a threading.Event as stop to interrupt idle reads and retry waits; replay checks it between archive batches too. An active connection attempt is bounded by request_timeout_seconds. client.live(timeout_seconds=20) imposes a total deadline across connections, idle reads, and backoff, raising StreamTimeout when it expires; socket shutdown can take up to one additional second.

Filters and limits

Set collections, dids, and kinds on Config. Kinds default to all supported kinds. Collection filters constrain commits; DID-level marker events are retained unless kinds or DID filters exclude them. Providing collections while excluding commit is rejected, as required by the upstream API. Limits are 4 kind entries, 100 collection patterns, and 10,000 DIDs. Archive planning may over-select blocks, so filters are applied exactly after decoding. Live uses the canonical v2 repeated filter parameters.

Config also exposes max_sequence_span, max_batch_bytes, request_timeout_seconds, refresh_timeout_seconds, max_retries, and include_raw_payload. Invalid options and non-HTTPS origins are rejected before network calls. HTTP requests disable ambient netrc credentials, refuse redirects, cap response sizes, and pin selected bytes to ETags. Archive corruption, changed generations, malformed plans, expired cursors, and exhausted deadlines raise typed exceptions from jetstream_lakehouse.errors; no successful candidate cursor is returned for an incomplete archive window. The live stream uses /xrpc/network.bsky.jetstream.subscribeEvents with the xrpc.v1.json subprotocol, not the legacy endpoint.

Catch ProtocolError for invalid data or size limits, ArchiveChanged for a changed segment generation, and CursorTooOld for unavailable replay history. RefreshTimeout covers archive work; StreamTimeout covers an optional live deadline. LiveStreamError.code identifies terminal v2 errors without exposing server messages. These all inherit from JetstreamError, which also covers denied access and exhausted retries. Live connections disable automatic environment proxy discovery.

Tests and downstream use

uv run ruff check ., uv run pytest, and uv build run without service credentials (installing/building dependencies may require PyPI access). The ordinary test suite performs no external network requests. See tests/FIXTURES.md for the independent Go-writer fixture's provenance. Synthetic events cover all supported kinds, including deletes and resyncs; malformed archives and HTTP ranges exercise checksum and generation validation.

The public live contract test reads three events with a 20-second deadline and requires no key or cursor:

JETSTREAM_INTEGRATION_LIVE=1 uv run pytest tests/integration -k live

The archive contract test requires a cursor inside sealed history and a key where the endpoint requires authentication. Put the raw token in a local file with mode 0600, for example .secrets/jetstream_api_key; .secrets/ is ignored by Git. Pass only the path on the command line:

JETSTREAM_API_KEY_FILE="$PWD/.secrets/jetstream_api_key" \
JETSTREAM_INTEGRATION_CURSOR=123456 \
uv run pytest tests/integration -k archive

The archive test caps the sequence span at 1,000 by default and the read deadline at 30 seconds. It requires actual events, so an empty or future range cannot pass as a verified archive read. JETSTREAM_ENDPOINT overrides the test endpoint; JETSTREAM_INTEGRATION_LIVE_CURSOR optionally tests explicit live resume. These variables belong only to the test harness; the library continues to require explicit Config objects. Both network tests are skipped in ordinary CI.

For further content diversity, public post datasets such as two-million-bluesky-posts can supply record JSON. They don't contain Jetstream's archive framing, generation checks, full marker stream, or cursor semantics, so use the native fixture and protocol tests for those guarantees. The public Jetstream service provides real v2 frames for the live contract check.

A Lakeflow adapter or a Zerobus producer can consume the public models and own its own delivery contract and checkpoint. Those integrations belong in their downstream repositories/packages; this library does not import or depend on either.

Protocol reference: Jetstream v2 documentation.

Metadata

Release files for jetstream-lakehouse 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 jetstream-lakehouse 0.2.0
File Size Uploaded Provenance Actions
jetstream_lakehouse-0.2.0.tar.gz 106.8 kB With provenance Details for jetstream_lakehouse-0.2.0.tar.gz

Built distribution (wheel)

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

Total release size: 147.8 kB

Release files / jetstream_lakehouse-0.2.0.tar.gz

Download URL jetstream_lakehouse-0.2.0.tar.gz
Size 106.8 kB
Tags Source
SHA-256 checksum
How to use checksums
0364ac5840ced5a5492c47136c4ac43d0fdf129815a6b561dce9798cc9580b4d
BLAKE2b-256 checksum
How to use checksums
aae89e8e71e67eed5e2c240966fab10b775bf1c886f0e822027a2eb4ef5bf46c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 12, 2026.

Transparency log

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

Download URL jetstream_lakehouse-0.2.0-py3-none-any.whl
Size 41.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a88bb16f442c39d167f4dc631786caa8591c2dc9b9886b4c6e7fd96bae761d78
BLAKE2b-256 checksum
How to use checksums
21041a75c243ce0c40d9c7a26c4617265aefc8d4c2ebc2e652515a4a6ee6e748
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 12, 2026.

Transparency log

Security for jetstream-lakehouse 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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for jetstream_lakehouse-0.2.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 12, 2026.

Transparency log

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 Full 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