Skip to main content

Python library for viem chain metadata, enabling compatibility with Javascript tooling.

Project description

python-viem

python-viem is a lightweight Python utility that mirrors EVM chain metadata from the Viem TypeScript library. It enables standardized, cross-language access to chain definitions and supports fast O(1) lookups by chain ID, name, or network slug.


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

python_viem-0.1.3.tar.gz (45.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

python_viem-0.1.3-py3-none-any.whl (44.3 kB view details)

Uploaded Python 3

File details

Details for the file python_viem-0.1.3.tar.gz.

File metadata

  • Download URL: python_viem-0.1.3.tar.gz
  • Upload date:
  • Size: 45.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.9

File hashes

Hashes for python_viem-0.1.3.tar.gz
Algorithm Hash digest
SHA256 ddccf689d0e2b232d981084c73c9c6332486cbc039a54d68add842749c810a6f
MD5 2a22376d526718229982c848caa040d6
BLAKE2b-256 df2c65f7bcc446a263eb5a0b32916c6f37c71c1276c7ccd693cd01b9f9812eda

See more details on using hashes here.

File details

Details for the file python_viem-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: python_viem-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 44.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.9

File hashes

Hashes for python_viem-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 b5adf8fa115caa838c4a2d4b1fb4bb37536c092bcd6c48b5a01f7620ad1990a9
MD5 4daf73e75575793635d64489aeee85ff
BLAKE2b-256 a74a0bca58cc111dff780fa944791fadd2a66b5942b2c88add2014a61aeba3e4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page