Bitref Python API Docs | dltHub

Build a Bitref-to-database pipeline in Python using dlt with AI Workbench support for Claude Code, Cursor, and Codex.

Last updated:

BitRef's Bitcoin REST API provides endpoints for address transactions, block information, and mining data, all requiring an API key for access. The API includes specific calls for transaction validation, block header details, and mempool information. Use the API to retrieve public Bitcoin blockchain data. The REST API base URL is https://api.bitref.com and All requests require an X-API-Key header (API key) for authentication..

dlt is an open-source Python library that handles authentication, pagination, and schema evolution automatically. dlthub provides AI context files that enable code assistants to generate production-ready pipelines. Install with uv pip install "dlt[workspace]" and start loading Bitref data in under 10 minutes.


What data can I load from Bitref?

Here are some of the endpoints you can load from Bitref:

ResourceEndpointMethodData selectorDescription
address_balance/v1/address/:address/balanceGETReturns confirmed and unconfirmed balance for an address (confirmed_balance, unconfirmed_balance).
address_utxo/v1/address/:address/utxoGETReturns list of UTXOs for an address (objects with height, tx_hash, tx_pos, value).
address_validate/v1/address/:address/validateGETValidates a Bitcoin address; returns object including isvalid (boolean) or error and error_locations.
tx_info/v1/tx/:txid/infoGETDetailed transaction info including inputs, outputs, prevout data.
tx_status/v1/tx/:txid/statusGETReturns {confirmed, blockhash?, confirmations?, blocktime?}.
tx_mempool/v1/tx/:txid/mempoolGETMempool data for an unconfirmed tx (vsize, weight, fees, depends, spentby, etc.).
tx_hex/v1/tx/:txid/hexGETReturns {txhex: "..."}.
tx_merkle_proof/v1/tx/:txid/merkle-proofGETReturns merkle inclusion proof {block_height, merkle[], pos}.
tx_effective_feerate/v1/tx/:txid/effective-feerateGETReturns {effective_feerate}.
block_info/v1/block/:hash/infoGETtxBlock details; tx is array of txids.
block_header/v1/block/:hash/headerGETBlock header fields.
blocks/v1/blocks[/:startHeight]GETReturns last 10 blocks or 10 ending at startHeight (array).
block_latest_hash/v1/block/latest/hashGETReturns {blockhash}.
block_latest_height/v1/block/latest/heightGETReturns {blockheight}.
block_next/v1/block/nextGETReturns array representing block template (top-level array).
blocks_height/v1/block/height/:heightGETReturns {blockhash}.
mempool_info/v1/mempool/infoGETReturns mempool stats object.
mempool_histogram/v1/mempool/histogramGETReturns top-level array of [fee, vsize] pairs.
fees_estimate/v1/fees/estimate/:confTargetGETReturns {feerate, blocks}.
fees_estimates/v1/fees/estimatesGETReturns object mapping target->feerate.
fees_tip/v1/fees/tipGETReturns {tip_fee_rate}.
mining_info/v1/mining/infoGETReturns mining stats object.
stats_blockchain/v1/stats/blockchainGETReturns blockchain state object.
stats_transactions/v1/stats/transactionsGETReturns transaction stats object.
price/v1/priceGETReturns {timestamp, usd}.

How do I authenticate with the Bitref API?

Bitref uses an API key sent in the HTTP header X-API-Key on every request.

1. Get your credentials

  1. Visit https://bitref.com/api/ and click the "Request an API Key" button or sign up on bitref.com.
  2. Choose a subscription plan or use the free trial (100 requests per day for 7 days).
  3. Copy the issued API key displayed in the dashboard.
  4. Use that key as the X-API-Key header for all requests.

2. Add them to .dlt/secrets.toml

[sources.bitref_source] api_key = "your_api_key_here"

dlt reads this automatically at runtime — never hardcode tokens in your pipeline script. For production environments, see setting up credentials with dlt for environment variable and vault-based options.


How do I set up and run the pipeline?

Set up a virtual environment and install dlt:

uv venv && source .venv/bin/activate uv pip install "dlt[workspace]"

1. Install the dlt AI Workbench:

dlt ai init --agent <your-agent> # <agent>: claude | cursor | codex

This installs project rules, a secrets management skill, appropriate ignore files, and configures the dlt MCP server for your agent. Learn more →

2. Install the rest-api-pipeline toolkit:

dlt ai toolkit rest-api-pipeline install

This loads the skills and context about dlt the agent uses to build the pipeline iteratively, efficiently, and safely. The agent uses MCP tools to inspect credentials — it never needs to read your secrets.toml directly. Learn more →

3. Start LLM-assisted coding:

Use /find-source to load data from the Bitref API into DuckDB.

The rest-api-pipeline toolkit takes over from here — it reads relevant API documentation, presents you with options for which endpoints to load, and follows a structured workflow to scaffold, debug, and validate the pipeline step by step.

4. Run the pipeline:

python bitref_pipeline.py

If everything is configured correctly, you'll see output like this:

Pipeline bitref_pipeline load step completed in 0.26 seconds 1 load package(s) were loaded to destination duckdb and into dataset bitref_data The duckdb destination used duckdb:/bitref.duckdb location to store data Load package 1749667187.541553 is LOADED and contains no failed jobs

Inspect your pipeline and data:

dlt pipeline bitref_pipeline show

This opens the Pipeline Dashboard where you can verify pipeline state, load metrics, schema (tables, columns, types), and query the loaded data directly.


Python pipeline example

This example loads tx/info and address/balance from the Bitref API into DuckDB. It mirrors the endpoint and data selector configuration from the table above:

import dlt from dlt.sources.rest_api import RESTAPIConfig, rest_api_resources @dlt.source def bitref_source(api_key=dlt.secrets.value): config: RESTAPIConfig = { "client": { "base_url": "https://api.bitref.com", "auth": { "type": "api_key", "api_key": api_key, }, }, "resources": [ {"name": "tx_info", "endpoint": {"path": "v1/tx/:txid/info"}}, {"name": "address_balance", "endpoint": {"path": "v1/address/:address/balance"}} ], } yield from rest_api_resources(config) def get_data() -> None: pipeline = dlt.pipeline( pipeline_name="bitref_pipeline", destination="duckdb", dataset_name="bitref_data", ) load_info = pipeline.run(bitref_source()) print(load_info)

To add more endpoints, append entries from the resource table to the "resources" list using the same name, path, and data_selector pattern.


How do I query the loaded data?

Once the pipeline runs, dlt creates one table per resource. You can query with Python or SQL.

Python (pandas DataFrame):

import dlt data = dlt.pipeline("bitref_pipeline").dataset() sessions_df = data.tx_info.df() print(sessions_df.head())

SQL (DuckDB example):

SELECT * FROM bitref_data.tx_info LIMIT 10;

In a marimo or Jupyter notebook:

import dlt data = dlt.pipeline("bitref_pipeline").dataset() data.tx_info.df().head()

See how to explore your data in marimo Notebooks and how to query your data in Python with dataset.


What destinations can I load Bitref data to?

dlt supports loading into any of these destinations — only the destination parameter changes:

DestinationExample value
DuckDB (local, default)"duckdb"
PostgreSQL"postgres"
BigQuery"bigquery"
Snowflake"snowflake"
Redshift"redshift"
Databricks"databricks"
Filesystem (S3, GCS, Azure)"filesystem"

Change the destination in dlt.pipeline(destination="snowflake") and add credentials in .dlt/secrets.toml. See the full destinations list.


Next steps

Continue your data engineering journey with the other toolkits of the dltHub AI Workbench:

  • data-exploration — Build custom notebooks, charts, and dashboards for deeper analysis with marimo notebooks.
  • dlthub-runtime — Deploy, schedule, and monitor your pipeline in production.
dlt ai toolkit data-exploration install dlt ai toolkit dlthub-runtime install

Was this page helpful?

Community Hub

Need more dlt context for Bitref?

Request dlt skills, commands, AGENT.md files, and AI-native context.