25 KiB
Table of Contents
- brk_client
- BrkError
- MetricData
- BrkClient
- VERSION
- INDEXES
- POOL_ID_TO_POOL_NAME
- TERM_NAMES
- EPOCH_NAMES
- YEAR_NAMES
- SPENDABLE_TYPE_NAMES
- AGE_RANGE_NAMES
- MAX_AGE_NAMES
- MIN_AGE_NAMES
- AMOUNT_RANGE_NAMES
- GE_AMOUNT_NAMES
- LT_AMOUNT_NAMES
- __init__
- metric
- get_address
- get_address_txs
- get_address_confirmed_txs
- get_address_mempool_txs
- get_address_utxos
- get_block_by_height
- get_block
- get_block_raw
- get_block_status
- get_block_txid
- get_block_txids
- get_block_txs
- get_blocks
- get_blocks_from_height
- get_mempool
- get_mempool_txids
- get_metric_info
- get_metric
- get_metrics_tree
- get_metrics
- get_metrics_count
- get_indexes
- list_metrics
- search_metrics
- get_disk_usage
- get_sync_status
- get_tx
- get_tx_hex
- get_tx_outspend
- get_tx_outspends
- get_tx_status
- get_difficulty_adjustment
- get_mempool_blocks
- get_recommended_fees
- get_block_fee_rates
- get_block_fees
- get_block_rewards
- get_block_sizes_weights
- get_block_by_timestamp
- get_difficulty_adjustments
- get_difficulty_adjustments_by_period
- get_hashrate
- get_hashrate_by_period
- get_pool
- get_pools
- get_pool_stats
- get_reward_stats
- validate_address
- get_health
- get_version
brk_client
BrkError Objects
class BrkError(Exception)
Custom error class for BRK client errors.
MetricData Objects
class MetricData(TypedDict, Generic[T])
Metric data with range information.
BrkClient Objects
class BrkClient(BrkClientBase)
Main BRK client with metrics tree and API methods.
VERSION
INDEXES
POOL_ID_TO_POOL_NAME
TERM_NAMES
EPOCH_NAMES
YEAR_NAMES
SPENDABLE_TYPE_NAMES
AGE_RANGE_NAMES
MAX_AGE_NAMES
MIN_AGE_NAMES
AMOUNT_RANGE_NAMES
GE_AMOUNT_NAMES
LT_AMOUNT_NAMES
__init__
def __init__(base_url: str = "http://localhost:3000", timeout: float = 30.0)
metric
def metric(metric: str, index: Index) -> MetricEndpointBuilder[Any]
Create a dynamic metric endpoint builder for any metric/index combination.
Use this for programmatic access when the metric name is determined at runtime.
For type-safe access, use the metrics tree instead.
get_address
def get_address(address: Address) -> AddressStats
Address information.
Retrieve address information including balance and transaction counts. Supports all standard Bitcoin address types (P2PKH, P2SH, P2WPKH, P2WSH, P2TR).
Endpoint: GET /api/address/{address}
get_address_txs
def get_address_txs(address: Address,
after_txid: Optional[str] = None,
limit: Optional[float] = None) -> List[Txid]
Address transaction IDs.
Get transaction IDs for an address, newest first. Use after_txid for pagination.
Endpoint: GET /api/address/{address}/txs
get_address_confirmed_txs
def get_address_confirmed_txs(address: Address,
after_txid: Optional[str] = None,
limit: Optional[float] = None) -> List[Txid]
Address confirmed transactions.
Get confirmed transaction IDs for an address, 25 per page. Use ?after_txid= for pagination.
Endpoint: GET /api/address/{address}/txs/chain
get_address_mempool_txs
def get_address_mempool_txs(address: Address) -> List[Txid]
Address mempool transactions.
Get unconfirmed transaction IDs for an address from the mempool (up to 50).
Endpoint: GET /api/address/{address}/txs/mempool
get_address_utxos
def get_address_utxos(address: Address) -> List[Utxo]
Address UTXOs.
Get unspent transaction outputs (UTXOs) for an address. Returns txid, vout, value, and confirmation status for each UTXO.
Endpoint: GET /api/address/{address}/utxo
get_block_by_height
def get_block_by_height(height: Height) -> BlockInfo
Block by height.
Retrieve block information by block height. Returns block metadata including hash, timestamp, difficulty, size, weight, and transaction count.
Endpoint: GET /api/block-height/{height}
get_block
def get_block(hash: BlockHash) -> BlockInfo
Block information.
Retrieve block information by block hash. Returns block metadata including height, timestamp, difficulty, size, weight, and transaction count.
Endpoint: GET /api/block/{hash}
get_block_raw
def get_block_raw(hash: BlockHash) -> List[float]
Raw block.
Returns the raw block data in binary format.
Endpoint: GET /api/block/{hash}/raw
get_block_status
def get_block_status(hash: BlockHash) -> BlockStatus
Block status.
Retrieve the status of a block. Returns whether the block is in the best chain and, if so, its height and the hash of the next block.
Endpoint: GET /api/block/{hash}/status
get_block_txid
def get_block_txid(hash: BlockHash, index: TxIndex) -> Txid
Transaction ID at index.
Retrieve a single transaction ID at a specific index within a block. Returns plain text txid.
Endpoint: GET /api/block/{hash}/txid/{index}
get_block_txids
def get_block_txids(hash: BlockHash) -> List[Txid]
Block transaction IDs.
Retrieve all transaction IDs in a block. Returns an array of txids in block order.
Endpoint: GET /api/block/{hash}/txids
get_block_txs
def get_block_txs(hash: BlockHash, start_index: TxIndex) -> List[Transaction]
Block transactions (paginated).
Retrieve transactions in a block by block hash, starting from the specified index. Returns up to 25 transactions at a time.
Endpoint: GET /api/block/{hash}/txs/{start_index}
get_blocks
def get_blocks() -> List[BlockInfo]
Recent blocks.
Retrieve the last 10 blocks. Returns block metadata for each block.
Endpoint: GET /api/blocks
get_blocks_from_height
def get_blocks_from_height(height: Height) -> List[BlockInfo]
Blocks from height.
Retrieve up to 10 blocks going backwards from the given height. For example, height=100 returns blocks 100, 99, 98, ..., 91. Height=0 returns only block 0.
Endpoint: GET /api/blocks/{height}
get_mempool
def get_mempool() -> MempoolInfo
Mempool statistics.
Get current mempool statistics including transaction count, total vsize, and total fees.
Endpoint: GET /api/mempool/info
get_mempool_txids
def get_mempool_txids() -> List[Txid]
Mempool transaction IDs.
Get all transaction IDs currently in the mempool.
Endpoint: GET /api/mempool/txids
get_metric_info
def get_metric_info(metric: Metric) -> List[Index]
Get supported indexes for a metric.
Returns the list of indexes supported by the specified metric. For example, realized_price might be available on dateindex, weekindex, and monthindex.
Endpoint: GET /api/metric/{metric}
get_metric
def get_metric(metric: Metric,
index: Index,
start: Optional[float] = None,
end: Optional[float] = None,
limit: Optional[str] = None,
format: Optional[Format] = None) -> Union[AnyMetricData, str]
Get metric data.
Fetch data for a specific metric at the given index. Use query parameters to filter by date range and format (json/csv).
Endpoint: GET /api/metric/{metric}/{index}
get_metrics_tree
def get_metrics_tree() -> TreeNode
Metrics catalog.
Returns the complete hierarchical catalog of available metrics organized as a tree structure. Metrics are grouped by categories and subcategories.
Endpoint: GET /api/metrics
get_metrics
def get_metrics(
metrics: Metrics,
index: Index,
start: Optional[float] = None,
end: Optional[float] = None,
limit: Optional[str] = None,
format: Optional[Format] = None) -> Union[List[AnyMetricData], str]
Bulk metric data.
Fetch multiple metrics in a single request. Supports filtering by index and date range. Returns an array of MetricData objects. For a single metric, use get_metric instead.
Endpoint: GET /api/metrics/bulk
get_metrics_count
def get_metrics_count() -> List[MetricCount]
Metric count.
Returns the number of metrics available per index type.
Endpoint: GET /api/metrics/count
get_indexes
def get_indexes() -> List[IndexInfo]
List available indexes.
Returns all available indexes with their accepted query aliases. Use any alias when querying metrics.
Endpoint: GET /api/metrics/indexes
list_metrics
def list_metrics(page: Optional[float] = None) -> PaginatedMetrics
Metrics list.
Paginated flat list of all available metric names. Use page query param for pagination.
Endpoint: GET /api/metrics/list
search_metrics
def search_metrics(metric: Metric,
limit: Optional[Limit] = None) -> List[Metric]
Search metrics.
Fuzzy search for metrics by name. Supports partial matches and typos.
Endpoint: GET /api/metrics/search/{metric}
get_disk_usage
def get_disk_usage() -> DiskUsage
Disk usage.
Returns the disk space used by BRK and Bitcoin data.
Endpoint: GET /api/server/disk
get_sync_status
def get_sync_status() -> SyncStatus
Sync status.
Returns the sync status of the indexer, including indexed height, tip height, blocks behind, and last indexed timestamp.
Endpoint: GET /api/server/sync
get_tx
def get_tx(txid: Txid) -> Transaction
Transaction information.
Retrieve complete transaction data by transaction ID (txid). Returns inputs, outputs, fee, size, and confirmation status.
Endpoint: GET /api/tx/{txid}
get_tx_hex
def get_tx_hex(txid: Txid) -> Hex
Transaction hex.
Retrieve the raw transaction as a hex-encoded string. Returns the serialized transaction in hexadecimal format.
Endpoint: GET /api/tx/{txid}/hex
get_tx_outspend
def get_tx_outspend(txid: Txid, vout: Vout) -> TxOutspend
Output spend status.
Get the spending status of a transaction output. Returns whether the output has been spent and, if so, the spending transaction details.
Endpoint: GET /api/tx/{txid}/outspend/{vout}
get_tx_outspends
def get_tx_outspends(txid: Txid) -> List[TxOutspend]
All output spend statuses.
Get the spending status of all outputs in a transaction. Returns an array with the spend status for each output.
Endpoint: GET /api/tx/{txid}/outspends
get_tx_status
def get_tx_status(txid: Txid) -> TxStatus
Transaction status.
Retrieve the confirmation status of a transaction. Returns whether the transaction is confirmed and, if so, the block height, hash, and timestamp.
Endpoint: GET /api/tx/{txid}/status
get_difficulty_adjustment
def get_difficulty_adjustment() -> DifficultyAdjustment
Difficulty adjustment.
Get current difficulty adjustment information including progress through the current epoch, estimated retarget date, and difficulty change prediction.
Endpoint: GET /api/v1/difficulty-adjustment
get_mempool_blocks
def get_mempool_blocks() -> List[MempoolBlock]
Projected mempool blocks.
Get projected blocks from the mempool for fee estimation. Each block contains statistics about transactions that would be included if a block were mined now.
Endpoint: GET /api/v1/fees/mempool-blocks
get_recommended_fees
def get_recommended_fees() -> RecommendedFees
Recommended fees.
Get recommended fee rates for different confirmation targets based on current mempool state.
Endpoint: GET /api/v1/fees/recommended
get_block_fee_rates
def get_block_fee_rates(time_period: TimePeriod) -> Any
Block fee rates (WIP).
Work in progress. Get block fee rate percentiles (min, 10th, 25th, median, 75th, 90th, max) for a time period. Valid periods: 24h, 3d, 1w, 1m, 3m, 6m, 1y, 2y, 3y
Endpoint: GET /api/v1/mining/blocks/fee-rates/{time_period}
get_block_fees
def get_block_fees(time_period: TimePeriod) -> List[BlockFeesEntry]
Block fees.
Get average block fees for a time period. Valid periods: 24h, 3d, 1w, 1m, 3m, 6m, 1y, 2y, 3y
Endpoint: GET /api/v1/mining/blocks/fees/{time_period}
get_block_rewards
def get_block_rewards(time_period: TimePeriod) -> List[BlockRewardsEntry]
Block rewards.
Get average block rewards (coinbase = subsidy + fees) for a time period. Valid periods: 24h, 3d, 1w, 1m, 3m, 6m, 1y, 2y, 3y
Endpoint: GET /api/v1/mining/blocks/rewards/{time_period}
get_block_sizes_weights
def get_block_sizes_weights(time_period: TimePeriod) -> BlockSizesWeights
Block sizes and weights.
Get average block sizes and weights for a time period. Valid periods: 24h, 3d, 1w, 1m, 3m, 6m, 1y, 2y, 3y
Endpoint: GET /api/v1/mining/blocks/sizes-weights/{time_period}
get_block_by_timestamp
def get_block_by_timestamp(timestamp: Timestamp) -> BlockTimestamp
Block by timestamp.
Find the block closest to a given UNIX timestamp.
Endpoint: GET /api/v1/mining/blocks/timestamp/{timestamp}
get_difficulty_adjustments
def get_difficulty_adjustments() -> List[DifficultyAdjustmentEntry]
Difficulty adjustments (all time).
Get historical difficulty adjustments including timestamp, block height, difficulty value, and percentage change.
Endpoint: GET /api/v1/mining/difficulty-adjustments
get_difficulty_adjustments_by_period
def get_difficulty_adjustments_by_period(
time_period: TimePeriod) -> List[DifficultyAdjustmentEntry]
Difficulty adjustments.
Get historical difficulty adjustments for a time period. Valid periods: 24h, 3d, 1w, 1m, 3m, 6m, 1y, 2y, 3y.
Endpoint: GET /api/v1/mining/difficulty-adjustments/{time_period}
get_hashrate
def get_hashrate() -> HashrateSummary
Network hashrate (all time).
Get network hashrate and difficulty data for all time.
Endpoint: GET /api/v1/mining/hashrate
get_hashrate_by_period
def get_hashrate_by_period(time_period: TimePeriod) -> HashrateSummary
Network hashrate.
Get network hashrate and difficulty data for a time period. Valid periods: 24h, 3d, 1w, 1m, 3m, 6m, 1y, 2y, 3y
Endpoint: GET /api/v1/mining/hashrate/{time_period}
get_pool
def get_pool(slug: PoolSlug) -> PoolDetail
Mining pool details.
Get detailed information about a specific mining pool including block counts and shares for different time periods.
Endpoint: GET /api/v1/mining/pool/{slug}
get_pools
def get_pools() -> List[PoolInfo]
List all mining pools.
Get list of all known mining pools with their identifiers.
Endpoint: GET /api/v1/mining/pools
get_pool_stats
def get_pool_stats(time_period: TimePeriod) -> PoolsSummary
Mining pool statistics.
Get mining pool statistics for a time period. Valid periods: 24h, 3d, 1w, 1m, 3m, 6m, 1y, 2y, 3y
Endpoint: GET /api/v1/mining/pools/{time_period}
get_reward_stats
def get_reward_stats(block_count: float) -> RewardStats
Mining reward statistics.
Get mining reward statistics for the last N blocks including total rewards, fees, and transaction count.
Endpoint: GET /api/v1/mining/reward-stats/{block_count}
validate_address
def validate_address(address: str) -> AddressValidation
Validate address.
Validate a Bitcoin address and get information about its type and scriptPubKey.
Endpoint: GET /api/v1/validate-address/{address}
get_health
def get_health() -> Health
Health check.
Returns the health status of the API server, including uptime information.
Endpoint: GET /health
get_version
def get_version() -> str
API version.
Returns the current version of the API server
Endpoint: GET /version