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)
- Caches parsed data for fast access.
- Robust fallback: supports both object and array-style JSON formats.
Usage
from python_viem import get_chain_by_id, get_chain_by_name
print(get_chain_by_id(8453)["name"]) # "Base"
print(get_chain_by_name("polygon")["id"]) # 137
JSON Format
Your viem-chains.json can use either format:
Object-style (preferred):
{
"mainnet": { "id": 1, "name": "Ethereum Mainnet", ... },
"polygon": { "id": 137, "name": "Polygon", ... }
}
Array-style (also supported):
[
{ "id": 1, "name": "Ethereum Mainnet", ... },
{ "id": 137, "name": "Polygon", ... }
]
Functions
get_chain_by_id(chain_id: int) -> Optional[Dict[str, Any]]
get_chain_by_name(name: str) -> Optional[Dict[str, Any]]
Both return the full chain metadata dictionary or None if not found.
Project Structure
python_viem/
├── __init__.py
├── viem.py
├── viem-chains.json ← bundled chain metadata
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.1.tar.gz.
File metadata
- Download URL: python_viem-0.1.1.tar.gz
- Upload date:
- Size: 46.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f77a66498e8f727f6524dd6c7a8d326ffa31c65a5ca448689c96080c92447287
|
|
| MD5 |
115999c38711c2267c66d0625d87306c
|
|
| BLAKE2b-256 |
b156c1b7ef6e305521a8e9d4507d85e170b800559b018f3bb2ee27d4c03c48e4
|
File details
Details for the file python_viem-0.1.1-py3-none-any.whl.
File metadata
- Download URL: python_viem-0.1.1-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 |
2cee79a13a11d97f35d1c41467cbe7dc4987babb33356dfe40ecbedfebea0556
|
|
| MD5 |
610e465d7fe978077728393a7f05811d
|
|
| BLAKE2b-256 |
80a736607764a5a158e81133762d2f5d41408c9c99c678dbd34b120c0e74de1c
|