Files
brk/packages/brk_client/DOCS.md
2026-01-11 18:55:40 +01:00

21 KiB

Table of Contents

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.

MetricEndpoint Objects

class MetricEndpoint(Generic[T])

An endpoint for a specific metric + index combination.

BrkClient Objects

class BrkClient(BrkClientBase)

Main BRK client with catalog 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)

get_address

def get_address(address: Address) -> AddressStats

Address information.

Retrieve comprehensive information about a Bitcoin address including balance, transaction history, UTXOs, and estimated investment metrics. Supports all standard Bitcoin address types (P2PKH, P2SH, P2WPKH, P2WSH, P2TR, etc.).

get_address_txs

def get_address_txs(address: Address,
                    after_txid: Optional[str] = None,
                    limit: Optional[int] = None) -> List[Txid]

Address transaction IDs.

Get transaction IDs for an address, newest first. Use after_txid for pagination.

get_address_txs_chain

def get_address_txs_chain(address: Address,
                          after_txid: Optional[str] = None,
                          limit: Optional[int] = None) -> List[Txid]

Address confirmed transactions.

Get confirmed transaction IDs for an address, 25 per page. Use ?after_txid= for pagination.

get_address_txs_mempool

def get_address_txs_mempool(address: Address) -> List[Txid]

Address mempool transactions.

Get unconfirmed transaction IDs for an address from the mempool (up to 50).

get_address_utxo

def get_address_utxo(address: Address) -> List[Utxo]

Address UTXOs.

Get unspent transaction outputs for an address.

get_block_height

def get_block_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.

get_block_by_hash

def get_block_by_hash(hash: BlockHash) -> BlockInfo

Block information.

Retrieve block information by block hash. Returns block metadata including height, timestamp, difficulty, size, weight, and transaction count.

get_block_by_hash_raw

def get_block_by_hash_raw(hash: BlockHash) -> List[int]

Raw block.

Returns the raw block data in binary format.

get_block_by_hash_status

def get_block_by_hash_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.

get_block_by_hash_txid_by_index

def get_block_by_hash_txid_by_index(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.

get_block_by_hash_txids

def get_block_by_hash_txids(hash: BlockHash) -> List[Txid]

Block transaction IDs.

Retrieve all transaction IDs in a block by block hash.

get_block_by_hash_txs_by_start_index

def get_block_by_hash_txs_by_start_index(
        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.

get_blocks

def get_blocks() -> List[BlockInfo]

Recent blocks.

Retrieve the last 10 blocks. Returns block metadata for each block.

get_blocks_by_height

def get_blocks_by_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.

get_mempool_info

def get_mempool_info() -> MempoolInfo

Mempool statistics.

Get current mempool statistics including transaction count, total vsize, and total fees.

get_mempool_txids

def get_mempool_txids() -> List[Txid]

Mempool transaction IDs.

Get all transaction IDs currently in the mempool.

get_metric

def get_metric(metric: Metric) -> List[Index]

Get supported indexes for a metric.

Returns the list of indexes are supported by the specified metric. For example, realized_price might be available on dateindex, weekindex, and monthindex.

get_metric_by_index

def get_metric_by_index(index: Index,
                        metric: Metric,
                        count: Optional[Any] = None,
                        format: Optional[Format] = None,
                        from_: Optional[Any] = None,
                        to: Optional[Any] = None) -> AnyMetricData

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).

get_metrics_bulk

def get_metrics_bulk(index: Index,
                     metrics: Metrics,
                     count: Optional[Any] = None,
                     format: Optional[Format] = None,
                     from_: Optional[Any] = None,
                     to: Optional[Any] = None) -> List[AnyMetricData]

Bulk metric data.

Fetch multiple metrics in a single request. Supports filtering by index and date range. Returns an array of MetricData objects.

get_metrics_catalog

def get_metrics_catalog() -> TreeNode

Metrics catalog.

Returns the complete hierarchical catalog of available metrics organized as a tree structure. Metrics are grouped by categories and subcategories. Best viewed in an interactive JSON viewer (e.g., Firefox's built-in JSON viewer) for easy navigation of the nested structure.

get_metrics_count

def get_metrics_count() -> List[MetricCount]

Metric count.

Current metric count

get_metrics_indexes

def get_metrics_indexes() -> List[IndexInfo]

List available indexes.

Returns all available indexes with their accepted query aliases. Use any alias when querying metrics.

get_metrics_list

def get_metrics_list(page: Optional[Any] = None) -> PaginatedMetrics

Metrics list.

Paginated list of available metrics

get_metrics_search_by_metric

def get_metrics_search_by_metric(metric: Metric,
                                 limit: Optional[Limit] = None
                                 ) -> List[Metric]

Search metrics.

Fuzzy search for metrics by name. Supports partial matches and typos.

get_tx_by_txid

def get_tx_by_txid(txid: Txid) -> Transaction

Transaction information.

Retrieve complete transaction data by transaction ID (txid). Returns the full transaction details including inputs, outputs, and metadata. The transaction data is read directly from the blockchain data files.

get_tx_by_txid_hex

def get_tx_by_txid_hex(txid: Txid) -> Hex

Transaction hex.

Retrieve the raw transaction as a hex-encoded string. Returns the serialized transaction in hexadecimal format.

get_tx_by_txid_outspend_by_vout

def get_tx_by_txid_outspend_by_vout(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.

get_tx_by_txid_outspends

def get_tx_by_txid_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.

get_tx_by_txid_status

def get_tx_by_txid_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.

get_v1_difficulty_adjustment

def get_v1_difficulty_adjustment() -> DifficultyAdjustment

Difficulty adjustment.

Get current difficulty adjustment information including progress through the current epoch, estimated retarget date, and difficulty change prediction.

get_v1_fees_mempool_blocks

def get_v1_fees_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.

def get_v1_fees_recommended() -> RecommendedFees

Recommended fees.

Get recommended fee rates for different confirmation targets based on current mempool state.

get_v1_mining_blocks_fees_by_time_period

def get_v1_mining_blocks_fees_by_time_period(
        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

get_v1_mining_blocks_rewards_by_time_period

def get_v1_mining_blocks_rewards_by_time_period(
        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

get_v1_mining_blocks_sizes_weights_by_time_period

def get_v1_mining_blocks_sizes_weights_by_time_period(
        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

get_v1_mining_blocks_timestamp

def get_v1_mining_blocks_timestamp(timestamp: Timestamp) -> BlockTimestamp

Block by timestamp.

Find the block closest to a given UNIX timestamp.

get_v1_mining_difficulty_adjustments

def get_v1_mining_difficulty_adjustments() -> List[DifficultyAdjustmentEntry]

Difficulty adjustments (all time).

Get historical difficulty adjustments. Returns array of [timestamp, height, difficulty, change_percent].

get_v1_mining_difficulty_adjustments_by_time_period

def get_v1_mining_difficulty_adjustments_by_time_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. Returns array of [timestamp, height, difficulty, change_percent].

get_v1_mining_hashrate

def get_v1_mining_hashrate() -> HashrateSummary

Network hashrate (all time).

Get network hashrate and difficulty data for all time.

get_v1_mining_hashrate_by_time_period

def get_v1_mining_hashrate_by_time_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

get_v1_mining_pool_by_slug

def get_v1_mining_pool_by_slug(slug: PoolSlug) -> PoolDetail

Mining pool details.

Get detailed information about a specific mining pool including block counts and shares for different time periods.

get_v1_mining_pools

def get_v1_mining_pools() -> List[PoolInfo]

List all mining pools.

Get list of all known mining pools with their identifiers.

get_v1_mining_pools_by_time_period

def get_v1_mining_pools_by_time_period(
        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

get_v1_mining_reward_stats_by_block_count

def get_v1_mining_reward_stats_by_block_count(block_count: int) -> RewardStats

Mining reward statistics.

Get mining reward statistics for the last N blocks including total rewards, fees, and transaction count.

get_v1_validate_address

def get_v1_validate_address(address: str) -> AddressValidation

Validate address.

Validate a Bitcoin address and get information about its type and scriptPubKey.

get_health

def get_health() -> Health

Health check.

Returns the health status of the API server

get_version

def get_version() -> str

API version.

Returns the current version of the API server