1. Quickstart¶
Using the Bloxplorer package is easy and straightforward, as it should be.
1.1. Setup¶
To install the Bloxplorer package simply run this command in your favorite terminal:
>>> pip install bloxplorer
1.2. Usage¶
After installation, you can import and use the desired explorer and its methods. For a full list of available methods click here. The available explorers are Bitcoin, Liquid and Bitcoin Testnet:
1.2.1. Bitcoin Explorer¶
from bloxplorer import bitcoin_explorer
result = bitcoin_explorer.blocks.get_last_height()
print(result.data)
'587840'
1.2.2. Liquid Explorer¶
from bloxplorer import liquid_explorer
result = liquid_explorer.blocks.get_last_height()
print(result.data)
'412287'
1.2.3. Bitcoin Testnet Explorer¶
from bloxplorer import bitcoin_testnet_explorer
result = bitcoin_testnet_explorer.blocks.get_last_height()
print(result.data)
'1571699'
1.3. Timeouts¶
You can tell Bloxplorer to stop waiting for a response from the Blockstream API after a given number of seconds with the timeout parameter. By default the timeout is set to 5 seconds.
>>> bitcoin_explorer.blocks.get_blocks(start_height='587840', timeout=3)
1.4. Exceptions¶
There are 2 different types of exceptions that can be raised, Client and API exceptions.
Client Exceptions
In the event of a network problem (e.g. DNS failure, refused connection, etc), BlockstreamClientNetworkError will be raised.
In the event of a Timeout, BlockstreamClientTimeout will be raised.
For anything else, BlockstreamClientError will be raised.
These exceptions will contain the error message, the resource url and the http method.
API Exceptions
In the event of an API error (e.g. Invalid resource, Bad Request, etc), Bloxplorer will raise BlockstreamApiError.
This exception will contain the same data as the Client exceptions, alongside the status code.
1.5. Source Code¶
Bloxplorer is available on GitHub.
Clone the public repository:
>>> git clone https://github.com/valinsky/bloxplorer.git
1.6. Dependencies¶
Bloxplorer uses the beautiful Requests package for its HTTP calls.