blockpulsar-client-python 1.0.0
Python Client for Blockpulsar API
License: Apache-2.0
Requires Python: >=3.6
Keywords: blockpulsar,Blockpulsar API,api,blockchain

# Blockpulsar Python Client
Official Python client for Blockpulsar API

- Website: https://blockpulsar.com
- API documentation: https://blockpulsar-docs.web.app/
- API version: 1.0.0
- Package version: 1.0.0


## Install
```bash
pip3 install blockpulsar-client-python
```


## Usage
Import the module first and instantiate a `blockpulsar.Client` object.
```Python
import blockpulsar

bp_client = blockpulsar.Client(api_key=<BLOCKPULSAR_API_KEY>, secret_key=<BLOCKPULSAR_SECRET_KEY>)
```
**Note:** It is recommended `api_key` and `secret_key` to be specified by setting the `BLOCKPULSAR_API_KEY` and `BLOCKPULSAR_SECRET_KEY` environment
variables in `.env` file, respectively. See an example below.


## Example
Create a `.env` file and provide the `BLOCKPULSAR_API_KEY` and `BLOCKPULSAR_SECRET_KEY` environment variables.
Install `python-dotenv` library (`pip3 install python-dotenv`) to load the environment variables from the `.env` file.

```Python
import blockpulsar
from dotenv import dotenv_values


def main():
    config = dotenv_values('.env')
    bp_client = blockpulsar.Client(api_key=config['BLOCKPULSAR_API_KEY'],
                                   secret_key=config['BLOCKPULSAR_SECRET_KEY'])

    block_hash = bp_client.btc.get_best_block_hash()
    block = bp_client.btc.get_block(block_hash)

    print(block)


if __name__ == '__main__':
    main()
```

## Methods
```Python
# Returns the hash of the best (tip) block in the most-work fully-validated chain.
get_best_block_hash()
```
```Python
# Get block.
#
# Args:
# -blockhash: The block hash
get_block(blockhash)
```
```Python
# Returns an object containing various state info regarding blockchain processing.
get_blockchain_info()
```
```Python
# Returns the height of the most-work fully-validated chain. The genesis block has height 0.
get_block_count()
```
```Python
# Returns hash of block in best-block-chain at height provided.
#
# Args:
# -height: The height index. The genesis block has height 0
get_block_hash(height)
```
```Python
# Get block header
#
# Args:
# -blockhash: The block hash
get_block_header(blockhash)
```
```Python
# Compute per block statistics for a given window. All amounts are in satoshis.
# It won’t work for some heights with pruning.
#
# Args:
# -hash_or_height: The block hash or height of the target block
get_block_stats(hash_or_height)
```
```Python
# Return information about all known tips in the block tree, including the main chain
# as well as orphaned branches.
get_chain_tips()
```
```Python
# Compute statistics about the total number and rate of transactions in the chain.
#
# Args:
# -blockhash: (optional) The hash of the block that ends the window. Default is chain tip
# -nblocks: (optional) Size of the window in number of blocks. Default is one month (30)
get_chain_tx_stats(blockhash, nblocks=30)
```
```Python
# Returns the proof-of-work difficulty as a multiple of the minimum difficulty.
get_difficulty()
```
```Python
# Get memory pool ancestors.
#
# Args:
# -txid: The transaction id (must be in mempool)
get_mempool_ancestors(txid)
```
```Python
# Get memory pool descendants.
#
# Args:
# -txid: The transaction id (must be in mempool)
get_mempool_descendants(txid)
```
```Python
# Returns mempool data for given transaction.
#
# Args:
# -txid: The transaction id (must be in mempool)
get_mempool_entry(txid)
```
```Python
# Returns details on the active state of the transaction memory pool.
get_mempool_info()
```
```Python
# Get raw memory pool data. A list of TX IDs.
get_raw_mempool()
```
```Python
# Returns details about an unspent transaction output.
#
# Args:
# -txid: The transaction ID
# -n: vout number
# -include_mempool: (optional) Whether to include the mempool.
#  Note that an unspent output that is spent in the mempool won’t appear. Default is true
get_tx_out(txid, n, include_mempool=True)
```
```Python
# Returns a hex-encoded proof that “txid” was included in a block.
#
# Args:
# -txids: The transaction IDs to filter
# -blockhash: The hash of the block. Looks for txid in the block with this hash if it is provided
get_tx_out_proof(txids, blockhash='')
```
```Python
# Returns a json object containing mining-related information.
get_mining_info()
```
```Python
# Returns the estimated network hashes per second based on the last n blocks.
#
# Args:
# -nblocks: (optional) The number of blocks, or -1 for blocks since last difficulty change.
#  Default is 120
# -height: (optional) To estimate at the time of the given height. Default is -1
get_network_hashps(nblocks=120, height=-1)
```
```Python
# Get raw transaction. By default this function only works for mempool transactions.
# When called with a blockhash argument, getrawtransaction will return the transaction
# if the specified block is available and the transaction is found in that block.
#
# Args:
# -txid: The transaction ID
# -blockhash: (optional) The block in which to look for the transaction
get_raw_transaction(txid, blockhash='')
```
```Python
# Return information about the given bitcoin address.
#
# Args:
# -address: BTC address to be checked
validate_address(address)
```

## Contributions
Contributions are welcome and can be made by submitting GitHub pull requests to this repository. The
`blockpulsar-client-python` source code follows [Google Python Style Guide](https://google.github.io/styleguide/pyguide.html) and
rules specified in [.pylintrc](https://github.com/blockpulsar/blockpulsar-client-python/blob/master/.pylintrc) file.



## License
This source code is available to everyone under the standard [Apache-2.0 License](https://github.com/blockpulsar/blockpulsar-client-python/blob/master/LICENSE).