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.4.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.4.0a1
File Size Uploaded
py_multiformats-0.4.0a1.tar.gz 76.7 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for py-multiformats 0.4.0a1
File
py_multiformats-0.4.0a1-cp310-abi3-win_amd64.whl CPython 3.10 abi3 Windows x86-64 Details
py_multiformats-0.4.0a1-cp310-abi3-musllinux_1_2_x86_64.whl CPython 3.10 abi3 Linux musl 1.2+ x86-64 Details
py_multiformats-0.4.0a1-cp310-abi3-musllinux_1_2_aarch64.whl CPython 3.10 abi3 Linux musl 1.2+ ARM64 Details
py_multiformats-0.4.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.4.0a1-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.10 abi3 Linux glibc 2.17+ ARM64 Details
py_multiformats-0.4.0a1-cp310-abi3-macosx_11_0_arm64.whl CPython 3.10 abi3 macOS 11.0+ ARM64 Details
py_multiformats-0.4.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.4.0a1.tar.gz

Download URL py_multiformats-0.4.0a1.tar.gz
Size 76.7 kB
Tags Source
SHA-256 checksum
How to use checksums
b7dd54d26e175147c036280235c7967366c3dd6cad7f0179bdd200d1f8db42b0
BLAKE2b-256 checksum
How to use checksums
a8379f82bd5eca813e143ce55cf7dd85ac1cc9821427a1d3161b465961d395d5
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.4.0a1-cp310-abi3-win_amd64.whl

Download URL py_multiformats-0.4.0a1-cp310-abi3-win_amd64.whl
Size 386.2 kB
Tags CPython 3.10 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
55d84153d111fad71c2c66e93cf53588ae994165dfb74ddd495c8b19f013eaf5
BLAKE2b-256 checksum
How to use checksums
ec375f02b6e96a23ab59995136a9308ddaa4dcf0a9877772f8e56009b9ff7607
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.4.0a1-cp310-abi3-musllinux_1_2_x86_64.whl

Download URL py_multiformats-0.4.0a1-cp310-abi3-musllinux_1_2_x86_64.whl
Size 696.3 kB
Tags CPython 3.10 Linux musl 1.2+ x86-64 abi3
SHA-256 checksum
How to use checksums
7c4b91e4d591e7cfdc1e0ab1eca008c5272457303c2c62f23ecf638f9f327b1d
BLAKE2b-256 checksum
How to use checksums
6defd6c32880d00d6c87e111c65f9c25d23a6af32fe16eac0a6b27fd982d25a4
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.4.0a1-cp310-abi3-musllinux_1_2_aarch64.whl

Download URL py_multiformats-0.4.0a1-cp310-abi3-musllinux_1_2_aarch64.whl
Size 642.1 kB
Tags CPython 3.10 Linux musl 1.2+ ARM64 abi3
SHA-256 checksum
How to use checksums
f22aa737697a52f91a8c8e97cdd2d437161a4f0fffec31c49a5ff8f97a1f8d29
BLAKE2b-256 checksum
How to use checksums
d5abd2ef5cfa0f7b1e538e746e0022c7c1e26ed17d1885fc03fd7fb761812fa9
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.4.0a1-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL py_multiformats-0.4.0a1-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 477.7 kB
Tags CPython 3.10 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
d42d6192d37b9ff77f6be36465f5a481058a524d69697af228649811d164938b
BLAKE2b-256 checksum
How to use checksums
8cafc676bcb9e0be37ac0c260ea9bffcbb5b893171e5509ac657e7d1f261f37d
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.4.0a1-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL py_multiformats-0.4.0a1-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 465.0 kB
Tags CPython 3.10 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
a0150c114e883e94126d7d638101bc279080a9e6fc8e71d5e5fb0163554a60e3
BLAKE2b-256 checksum
How to use checksums
7f1a9b0a2fd3c51850b5b4a476701bf17e74fc0df9675cbfaecf27292be1ad59
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.4.0a1-cp310-abi3-macosx_11_0_arm64.whl

Download URL py_multiformats-0.4.0a1-cp310-abi3-macosx_11_0_arm64.whl
Size 418.0 kB
Tags CPython 3.10 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
bc32ce2427fb07f1c904d44bc9454b393c40fa681ea46889c9d49d317dfd6fa7
BLAKE2b-256 checksum
How to use checksums
540f64a5b923aa9a1df87470d73186cb39044aa51c51d46136ee7df43d1570dd
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.4.0a1-cp310-abi3-macosx_10_12_x86_64.whl

Download URL py_multiformats-0.4.0a1-cp310-abi3-macosx_10_12_x86_64.whl
Size 463.1 kB
Tags CPython 3.10 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
639b0a03f0468c095bd7f12ff2132e19b4b9d0bb19377acb1164f29bc29bba1d
BLAKE2b-256 checksum
How to use checksums
d5f954e966e25bc81b7eb8da978d7aa9832898c44219931a2bbb64181d93ddae
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