electrum-client
Async Python client for the Electrum protocol (JSON-RPC 2.0 over TCP/SSL, newline-delimited), plus higher-level helpers for tracking onchain addresses, transactions, and blocks.
- Request/response correlation by id, subscription dispatch, automatic keepalive pings
server.versionhandshake sent automatically on connect, as required by the spec- Response payloads parsed into typed
pydanticmodels - Raw transaction / block header parsing (via
embit) - Reconnecting trackers for address balances/history, single transactions, and new blocks
Install
pip install electrum-client
Usage
import asyncio
from electrum_client import ElectrumClient
async def main():
async with ElectrumClient("ssl://electrum.blockstream.info:50002") as client:
print(await client.get_height())
print(await client.server_banner())
asyncio.run(main())
Scripthashes and balances
from electrum_client import ElectrumClient, scripthash_from_address
async with ElectrumClient("ssl://electrum.blockstream.info:50002") as client:
scripthash = scripthash_from_address("bc1q...")
balance = await client.get_balance(scripthash)
history = await client.get_history(scripthash)
utxos = await client.listunspent(scripthash)
Subscriptions
def on_change(params):
print("scripthash status changed:", params)
async with ElectrumClient("ssl://electrum.blockstream.info:50002") as client:
await client.subscribe_scripthash(scripthash, callback=on_change)
await asyncio.sleep(60) # keep the connection open to receive notifications
Trackers
AddressTracker, TransactionTracker, and BlockTracker wrap a reconnecting
ElectrumClient connection and dispatch typed events (OnchainAddressEvent,
OnchainTxEvent, BlockInfo) to an async callback — useful for driving
websockets or other push-based consumers.
from electrum_client import AddressTracker
tracker = AddressTracker("ssl://electrum.blockstream.info:50002")
tracker.add("bc1q...")
async def on_event(event):
print(event.address, event.confirmed, event.unconfirmed)
await tracker.run(callback=on_event, is_active=lambda: True)
Parsing helpers
from electrum_client import parse_raw_tx, parse_block_header
tx = parse_raw_tx(raw_tx_hex)
header = parse_block_header(header_hex, height)
Development
Requires uv.
uv sync
make format # black + ruff --fix
make check # black --check, ruff check, mypy
make test # unit tests
Regtest integration tests
The regtest suite runs the client against bitcoind in Docker, indexed by
two independent Electrum servers so the client is exercised against more
than one implementation:
electrs(electrs-esplora) — fast, but doesn't implementserver.featuresorblockchain.scripthash.get_mempoolfulcrum— fully spec-compliant, used to cover the protocol paths electrs can't (seetests/regtest/test_fulcrum.py)
make regtest-up
uv run pytest tests/regtest
make regtest-down
License
MIT
Metadata
Release files for electrum-client 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| electrum_client-0.1.0.tar.gz | 64.0 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| electrum_client-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 77.8 kB
Release files / electrum_client-0.1.0.tar.gz
| Download URL | electrum_client-0.1.0.tar.gz |
|---|---|
| Size | 64.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ccbe9540a323b1369ec2632d8a5fdcb4278536f44b09370b35048811b3355aba
|
|
BLAKE2b-256 checksum How to use checksums |
fe52c5d862ced8261b9d44d300531ece2772bc33aceb2215d26f50c9549f11ba
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.12.3 {"installer":{"name":"uv","version":"0.12.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / electrum_client-0.1.0-py3-none-any.whl
| Download URL | electrum_client-0.1.0-py3-none-any.whl |
|---|---|
| Size | 13.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b4de30016915b4cb503835f7b89a0a00b7d22005827a8f84f87d8190924d36f8
|
|
BLAKE2b-256 checksum How to use checksums |
b75a913f050ff09adddf02ed1d74c222d94baf63cd6df5b5aa0eae674d1879f8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.12.3 {"installer":{"name":"uv","version":"0.12.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for electrum-client 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.