Python library for viem chain metadata, enabling compatibility with Javascript tooling.
Project description
python-viem
python-viem is a lightweight utility for retrieving EVM chain metadata from a local snapshot (viem-chains.json). It supports fast O(1) lookups by either numeric chain ID or human-readable name.
Installation
pip install python-viem
uv add python-viem # for uv users
Features
- Instant chain metadata lookup by:
chain_id(e.g.,8453 → "Base")name(e.g.,"Polygon" → 137)network(e.g.,"base-sepolia" → 84532)
Usage
from python_viem import get_chain_by_id, get_chain_by_name, get_chain_by_network
from python_viem.viem import CHAINS_BY_NETWORK, CHAINS_BY_NAME, CHAINS_BY_ID
print(get_chain_by_id(8453)["name"]) # Base
print(get_chain_by_name("polygon")["id"]) # 137
print(get_chain_by_network("base-sepolia")["id"]) # 43113
print(list(CHAINS_BY_NETWORK.keys())) # List of all network keys
print(list(CHAINS_BY_NAME.keys())) # List of all chain names
print(list(CHAINS_BY_ID.keys())) # List of all chain IDs
Functions
get_chain_by_id(chain_id: int) -> Optional[Dict[str, Any]]
get_chain_by_name(name: str) -> Optional[Dict[str, Any]]
get_chain_by_network(network: str) -> Optional[Dict[str, Any]]
All functions return the full chain metadata dictionary or None if not found.
Project Structure
python_viem/
├── __init__.py
├── viem.py
├── viem-chains.json
License
MIT
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file python_viem-0.1.2.tar.gz.
File metadata
- Download URL: python_viem-0.1.2.tar.gz
- Upload date:
- Size: 45.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
39290ef0e99d770eeb5ab1a8769f48c34cf5c871ae2f701edba47f61caa3fa18
|
|
| MD5 |
a3e37b7324585747ce995e0bf8e88514
|
|
| BLAKE2b-256 |
fcd6963c4bfc2f4f2b666ba65e357d3baecbdd44be2cc49f64528e8dbca18921
|
File details
Details for the file python_viem-0.1.2-py3-none-any.whl.
File metadata
- Download URL: python_viem-0.1.2-py3-none-any.whl
- Upload date:
- Size: 44.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
02e84faa9369eda0ec06c5b5f26b44f4d72b97eb126b93fd2e3af630f9700b2d
|
|
| MD5 |
ceb15d103008b9ac5115f9af0175d478
|
|
| BLAKE2b-256 |
36d614154d8d07a8f73737ec6a8da5a68df9e913dea48cbd62b49ffeaa943ff3
|