Skip to main content

bloklake

The official Python client for the Bloklake API.

  • Typed queries: filters, field names and rows are TypedDicts and Literals, so your editor and mypy catch a misspelled field.
  • Arrow on the wire, JSON-like rows in your code: responses travel as Apache Arrow (about 2–2.5× smaller than JSON, so cheaper) and are decoded here into plain dicts with the same values /query/json returns.
  • Pagination, retries and integrity built in: follows next_block, reuses prepared queries, retries rate limits and busy servers, and refuses truncated responses.
pip install bloklake

Python 3.9+. Depends on pyarrow and requests.

Quick start

from bloklake import Bloklake

bl = Bloklake(chain="eth")  # API key from BLOKLAKE_API_KEY

page = bl.query({
    "from_block": 19_426_000,
    "to_block": 19_426_009,
    "logs": [{
        "address": ["0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48"],
        "topic0": ["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"],
    }],
    "fields": {"log": ["block_number", "transaction_hash", "topic1", "topic2", "data"]},
})

for log in page.logs:
    print(log["block_number"], log["data"])
print(page.meta.next_block)

Write the query in snake_case, as above, or in the API's camelCase ("fromBlock", "blockNumber", as in the HTTP API and curl examples); the client sends camelCase either way. Give each key one way only. Rows always come back in snake_case (log["block_number"]).

Reading a whole range

paginate follows next_block until to_block (or the chain head when you leave to_block out). After the first page it sends only the prepared-query id, and falls back to the full query if the id expired.

for page in bl.paginate({
    "from_block": 19_000_000,
    "to_block": 19_100_000,
    "logs": [{"topic0": [TRANSFER]}],
    "fields": {"log": ["block_number", "address", "topic1", "topic2", "data"]},
}):
    store(page.logs)

collect(query) returns all pages merged into one Page. Use it for ranges that fit in memory.

Results

A Page has logs, transactions and blocks lists (empty when not requested) and meta (from_block, to_block, next_block, objects, archive_height, finalized_block, to_block_hash, query_id, unavailable_fields).

Rows use the API's column names (block_number, transaction_hash) and its JSON encoding:

Field kind Value
block numbers, indexes, gas, timestamps int
amounts (value, gas prices, fees, uint256) decimal str (int(x) to compute)
hashes, addresses, topics, input, data 0x hex str
withdrawals, access_list, authorization_list lists of dicts
not available or not applicable None

To get a dataframe: pandas.DataFrame(page.logs) or polars.DataFrame(page.logs). If you'd rather keep the raw Arrow columns, use the API directly as shown in Reading Arrow.

Other calls

s = bl.create_set("address", pools)                    # idempotent: same values, same id
bl.query({"logs": [{"address_set": s.set_id, "topic0": [SWAP]}], "fields": {"log": ["address", "data"]}})
bl.get_set(s.set_id)
bl.delete_set(s.set_id)

bl.prepare({"logs": [...], "fields": {...}})  # Prepared(query_id, expires_in)
bl.status()   # ChainStatus(chain_id, first_block, archive_height, finalized_block), free
bl.schema()   # every field and whether this chain has it, free
bl.account()  # plan, rps, balance or usage, free

Errors

Failures raise BloklakeError with status (0 for client-side failures), code (invalid_query, rate_limited, balance_exhausted, truncated, …), retry_after and request_id. The client retries 429, 503, 5xx, network errors and truncated responses itself, up to max_retries (default 4), honoring Retry-After. Other errors need a fix and are raised at once. See Errors.

from bloklake import BloklakeError

try:
    bl.query(q)
except BloklakeError as e:
    if e.code == "balance_exhausted":
        alert_someone()
    else:
        raise

Options

Bloklake(
    api_key="bl_live_…",    # default: BLOKLAKE_API_KEY
    chain="rh",             # or base_url="https://api.bloklake.com/v1/chains/rh"
    max_retries=4,
    timeout=120.0,
    session=requests.Session(),  # proxies, custom adapters, tests
)

Development

pip install -e ".[dev]"
pytest              # unit and fixture tests
mypy src/bloklake   # strict
BLOKLAKE_TEST_URL=https://api.bloklake.com/v1/chains/eth BLOKLAKE_API_KEY=… pytest   # plus live tests
python scripts/generate.py   # regenerate src/bloklake/fields.py after updating scripts/schema.json

The fixture tests decode recorded Arrow responses and compare them with the server's own /query/json output for the same requests, field by field.

License

MIT

Metadata

Release files for bloklake 0.1.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 bloklake 0.1.0
File Size Uploaded Provenance Actions
bloklake-0.1.0.tar.gz 557.6 kB Without provenance Details for bloklake-0.1.0.tar.gz

Built distribution (wheel)

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

Total release size: 572.8 kB

Release files / bloklake-0.1.0.tar.gz

Download URL bloklake-0.1.0.tar.gz
Size 557.6 kB
Tags Source
SHA-256 checksum
How to use checksums
c969c8d7846479b3bdac2a8809e70f9c3c366743c29d4d7e3e2584a23d3d2ede
BLAKE2b-256 checksum
How to use checksums
1dd8a8db35e49964998c197a2e99a226af081e64ffc592839882c6f9703a64bf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.4

Release files / bloklake-0.1.0-py3-none-any.whl

Download URL bloklake-0.1.0-py3-none-any.whl
Size 15.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ba37e94eb7f294381f73ee1bb10b839359c8c1148caa35ae8b14dacbfa53c19d
BLAKE2b-256 checksum
How to use checksums
1dcc61ff9309f059a23b2e45f506e7d7a7b6ec909a8a7857cc3ae22e3e449f3b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.4

Security for bloklake 0.1.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.1.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