Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

py-multiformats

CI PyPI Python versions License: Apache-2.0 Built with PyO3

Python bindings for the official Rust multiformats implementations, wrapped with PyO3:

The package also embeds the canonical multicodec and multibase registries, compiled in at build time from the vendored tables in data/ and refreshed weekly from upstream.

Contents

Why this package?

The existing Python options are four single-format packages (py-multibase, py-multihash, py-multiaddr, py-cid) that have mostly gone quiet, and the pure-Python multiformats package. This one puts all four formats behind a single typed API and lets the Rust reference implementations do the actual work (the same code that runs inside rust-libp2p). Spec fixes arrive by bumping a dependency, parsing and hashing run at native speed, and the codec tables are generated from the canonical registries instead of being copied in once and left to rot. Ships as prebuilt abi3 wheels for CPython ≥ 3.10, no runtime dependencies.

Install

pip install py-multiformats

Usage

from multiformats import multibase, multicodec, multihash
from multiformats.cid import CID
from multiformats.multiaddr import Multiaddr
from multiformats.multihash import Multihash

# multicodec — the codec registry. Every entry is a module constant.
multicodec.DAG_PB                                    # 112 (0x70)
multicodec.code("dag-pb")                            # 112, name -> code
multicodec.name(multicodec.DAG_PB)                   # "dag-pb"
multicodec.tag(multicodec.DAG_PB)                    # "ipld" (accepts constant, code, or name)
multicodec.entries()                                 # [(name, tag, code, status), ...]

# multibase — constants hold the canonical encoding names
encoded = multibase.encode(multibase.BASE58BTC, b"hello")   # "zCn8eVZg"
base, data = multibase.decode(encoded)               # ("base58btc", b"hello")
base == multibase.BASE58BTC                          # True
multibase.bases()                                    # all supported encodings

# multihash
mh = multihash.digest(multicodec.SHA2_256, b"hello world")
mh = multihash.sha2_256(b"hello world")              # same, via convenience function
mh.code == multicodec.SHA2_256                       # True
mh.name                                              # "sha2-256"
mh.size                                              # 32
mh.digest                                            # raw digest bytes
Multihash.from_bytes(mh.to_bytes()) == mh            # True
multihash.codes()                                    # name -> code table

# CID
cid = CID.decode("QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n")
cid.version                                          # 0
cid.codec == multicodec.DAG_PB                       # True
cid.codec_name                                       # "dag-pb"
cid.hash.name                                        # "sha2-256"
CID(1, multicodec.RAW, cid.hash)                     # codec by constant, code, or name
str(cid.to_v1())                                     # "bafybeihdwdce..."
cid.to_v1().encode(multibase.BASE64URL)              # any multibase encoding
CID.from_bytes(cid.to_bytes()) == cid                # True

# multiaddr
addr = Multiaddr("/ip4/127.0.0.1/tcp/4001")
list(addr)                                           # [("ip4", "127.0.0.1"), ("tcp", "4001")]
addr.protocols()                                     # ["ip4", "tcp"]
addr = addr.encapsulate("/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC")
addr.decapsulate("/tcp/4001")                        # Multiaddr("/ip4/127.0.0.1")
Multiaddr.from_bytes(addr.to_bytes()) == addr        # True

Anything that fails to parse, decode, or encode raises multiformats.MultiformatsError, a subclass of ValueError.

Development

You need a Rust toolchain and uv:

uv sync                                       # create the venv, install the dev tools, build the extension
uv run pytest                                 # run the test suite
uv run mypy tests/                            # type-check against the stubs
uv run maturin develop                        # rebuild the extension after Rust changes
cargo clippy --all-targets -- -D warnings     # lint the Rust side
cargo test                                    # run the Rust unit tests

The dev tools (maturin, pytest, mypy) are declared as a dependency group in pyproject.toml, so uv sync installs everything.

Code generation

The multicodec and multibase registries are not hand-written. The canonical tables are vendored in data/:

build.rs turns both CSVs into Rust at build time: the registry rows as a static ENTRIES table, phf perfect hash maps for the lookups, and a consts module with one constant per entry. The same entries become the Python constants (multicodec.DAG_PB, multibase.BASE58BTC, ...) at import time. build.rs also writes the multicodec.pyi and multibase.pyi stubs — those are committed and CI fails if they drift, so IDE autocomplete always matches the vendored tables.

To pull the latest tables from upstream:

./scripts/update-tables.sh

A scheduled workflow (update-tables.yml) runs the same script weekly and opens a pull request when a registry changed.

Releasing

Releases are tag-driven; nothing is built or uploaded from a laptop.

  1. Bump version in pyproject.toml (PEP 440, e.g. 0.1.0a1 for an alpha, 0.1.0 for a final release) and mirror it in Cargo.toml (0.1.0-alpha.1 in semver). Commit and push.

  2. Tag the commit and push the tag:

    git tag v0.1.0a1
    git push origin v0.1.0a1
    
  3. The release workflow triggers on v* tags: it builds abi3 wheels for Linux (manylinux + musllinux, x86_64/aarch64), macOS (x86_64/arm64), and Windows (x64), builds the sdist, and publishes everything to PyPI.

Publishing uses trusted publishing (OIDC) — there are no PyPI tokens anywhere. One-time setup, already done for this repository: a (pending) publisher on PyPI pointing at probe-lab/py-multiformats, workflow release.yml, environment pypi, and a matching pypi environment in the GitHub repository settings.

License

Apache-2.0

Release files for py-multiformats 0.2.0a1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for py-multiformats 0.2.0a1
File Size Uploaded
py_multiformats-0.2.0a1.tar.gz 76.1 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for py-multiformats 0.2.0a1
File
py_multiformats-0.2.0a1-cp310-abi3-win_amd64.whl CPython 3.10 abi3 Windows x86-64 Details
py_multiformats-0.2.0a1-cp310-abi3-musllinux_1_2_x86_64.whl CPython 3.10 abi3 Linux musl 1.2+ x86-64 Details
py_multiformats-0.2.0a1-cp310-abi3-musllinux_1_2_aarch64.whl CPython 3.10 abi3 Linux musl 1.2+ ARM64 Details
py_multiformats-0.2.0a1-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.10 abi3 Linux glibc 2.17+ x86-64 Details
py_multiformats-0.2.0a1-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.10 abi3 Linux glibc 2.17+ ARM64 Details
py_multiformats-0.2.0a1-cp310-abi3-macosx_11_0_arm64.whl CPython 3.10 abi3 macOS 11.0+ ARM64 Details
py_multiformats-0.2.0a1-cp310-abi3-macosx_10_12_x86_64.whl CPython 3.10 abi3 macOS 10.12+ x86-64 Details

Total release size: 3.6 MB

Release files / py_multiformats-0.2.0a1.tar.gz

Download URL py_multiformats-0.2.0a1.tar.gz
Size 76.1 kB
Tags Source
SHA-256 checksum
How to use checksums
2fb5daa1fc1b71878a5da6a7166f21512ffb7da45efe0a5aa1fa83edffad8408
BLAKE2b-256 checksum
How to use checksums
53bfa19e9030f6d58b0d2e5db221c48ff091b1314f46cc2436c5e1ff7f086654
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 18, 2026.

Transparency log

Release files / py_multiformats-0.2.0a1-cp310-abi3-win_amd64.whl

Download URL py_multiformats-0.2.0a1-cp310-abi3-win_amd64.whl
Size 384.0 kB
Tags CPython 3.10 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
85ee0d761452120eece66dd8897b08671d86cd09f2f0e7e9c641e25c9d4f47c0
BLAKE2b-256 checksum
How to use checksums
d9169114ce8c7db2c963ee9e7b9482ec7f9859aab73123b46a0320c0bfa8a42e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 18, 2026.

Transparency log

Release files / py_multiformats-0.2.0a1-cp310-abi3-musllinux_1_2_x86_64.whl

Download URL py_multiformats-0.2.0a1-cp310-abi3-musllinux_1_2_x86_64.whl
Size 692.7 kB
Tags CPython 3.10 Linux musl 1.2+ x86-64 abi3
SHA-256 checksum
How to use checksums
820e0994f78a2ee648e0289959b92de837650a5526862e3e72b8290b0743c346
BLAKE2b-256 checksum
How to use checksums
c898106ffaa2c7cd8483544369b6b25eb7e379c970cea985e82f955d0069754b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 18, 2026.

Transparency log

Release files / py_multiformats-0.2.0a1-cp310-abi3-musllinux_1_2_aarch64.whl

Download URL py_multiformats-0.2.0a1-cp310-abi3-musllinux_1_2_aarch64.whl
Size 639.1 kB
Tags CPython 3.10 Linux musl 1.2+ ARM64 abi3
SHA-256 checksum
How to use checksums
f2ccbfbd01c4b5a5a6735ce1a15c60ae3ca092102dd00dcf4f7b703b70153f24
BLAKE2b-256 checksum
How to use checksums
cf6fc5533a345f628010b64a2d5741acf27f6751892b098d1d7d22aa3b1593d7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 18, 2026.

Transparency log

Release files / py_multiformats-0.2.0a1-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL py_multiformats-0.2.0a1-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 474.5 kB
Tags CPython 3.10 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
20fe25fa473e2681d80e6390cdb17deb770e613dbbe8343fd8f0289547b9e4d2
BLAKE2b-256 checksum
How to use checksums
4491736b12b29b45be8b27300d1d2902881a4af90b16db5bad952a0c52686e39
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 18, 2026.

Transparency log

Release files / py_multiformats-0.2.0a1-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL py_multiformats-0.2.0a1-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 462.0 kB
Tags CPython 3.10 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
e68c26f3be640ff62e59c615e48773c0d0720065ce3467fe598afcac20e5ce55
BLAKE2b-256 checksum
How to use checksums
7ab33ad9966e895d92d6df4c53fe0c0b70a86343a5cc5b7242aa27ad839e67a2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 18, 2026.

Transparency log

Release files / py_multiformats-0.2.0a1-cp310-abi3-macosx_11_0_arm64.whl

Download URL py_multiformats-0.2.0a1-cp310-abi3-macosx_11_0_arm64.whl
Size 415.6 kB
Tags CPython 3.10 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
216d21d9cec08033e7dfa30da593ac7775c507e9fac7bee0aa9ab67441f9d46d
BLAKE2b-256 checksum
How to use checksums
33ccb05e178c12b75c8e063b752777865d10c34d75ffae5b2eb392e20d255a64
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 18, 2026.

Transparency log

Release files / py_multiformats-0.2.0a1-cp310-abi3-macosx_10_12_x86_64.whl

Download URL py_multiformats-0.2.0a1-cp310-abi3-macosx_10_12_x86_64.whl
Size 460.1 kB
Tags CPython 3.10 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
4356801282a3d9b620ad0b86783273ae9060e051d58c0d686c4c820598a3e773
BLAKE2b-256 checksum
How to use checksums
6f26fb0c238aea3dc0426fcc504a41179e6ba67a05f5ae9f37ead7ff9497a579
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 18, 2026.

Transparency log
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page