Blockfrost Python SDK
raw JSON → 0.7.0 verified Fri May 01 auth: no python
The official Python SDK for Blockfrost API v0.1.86. Provides a simple interface to interact with the Cardano blockchain via the Blockfrost API. Current version: 0.7.0. Active development with occasional releases.
pip install blockfrost-python Common errors
error ModuleNotFoundError: No module named 'blockfrost_python' ↓
cause The correct module name is 'blockfrost', not 'blockfrost_python'.
fix
Install: pip install blockfrost-python. Import: from blockfrost import BlockFrostApi
error AttributeError: module 'blockfrost' has no attribute 'BlockFrostApi' ↓
cause Importing using 'import blockfrost' does not automatically expose the class.
fix
Use: from blockfrost import BlockFrostApi
error blockfrost.exceptions.ApiError: (403) Forbidden ↓
cause Missing or invalid project_id. The API key is required.
fix
Set environment variable BLOCKFROST_PROJECT_ID or pass project_id parameter.
Warnings
gotcha BlockFrostApi requires the 'project_id' argument (or the environment variable BLOCKFROST_PROJECT_ID). Without it, requests will fail with 403. ↓
fix Set BLOCKFROST_PROJECT_ID environment variable or pass project_id parameter.
breaking Version 0.6.0 removed the deprecated 'api_version' parameter. Use 'base_url' instead to point to a custom backend. ↓
fix Replace api_version='v0' with base_url='https://your-custom-url/'.
Imports
- BlockFrostApi wrong
from blockfrost_python import BlockFrostApicorrectfrom blockfrost import BlockFrostApi - BlockFrostApi wrong
import blockfrostcorrectfrom blockfrost import BlockFrostApi
Quickstart
from blockfrost import BlockFrostApi
api = BlockFrostApi(project_id=os.environ.get('BLOCKFROST_PROJECT_ID', ''))
# Retrieve the latest block
block = api.block_latest()
print(block)