This release is a pre-release and may not be stable for production use.
py-multiformats
Python bindings for the official Rust multiformats implementations, wrapped with PyO3:
- rust-multibase — self-describing base encodings
- rust-multihash — self-describing hashes
- rust-multiaddr — self-describing network addresses
- rust-cid — self-describing content identifiers
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/:
data/multicodec-table.csv— verbatim copy of multiformats/multicodectable.csvdata/multibase-table.csv— verbatim copy of multiformats/multibasemultibase.csv
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.
-
Bump
versioninpyproject.toml(PEP 440, e.g.0.1.0a1for an alpha,0.1.0for a final release) and mirror it inCargo.toml(0.1.0-alpha.1in semver). Commit and push. -
Tag the commit and push the tag:
git tag v0.1.0a1 git push origin v0.1.0a1
-
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
Release files for py-multiformats 0.3.0a1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| py_multiformats-0.3.0a1.tar.gz | 76.2 kB | Details |
Built distributions (wheels)
| File | Reset | |||
|---|---|---|---|---|
| py_multiformats-0.3.0a1-cp310-abi3-win_amd64.whl | CPython 3.10 | abi3 | Windows x86-64 | Details |
| py_multiformats-0.3.0a1-cp310-abi3-musllinux_1_2_x86_64.whl | CPython 3.10 | abi3 | Linux musl 1.2+ x86-64 | Details |
| py_multiformats-0.3.0a1-cp310-abi3-musllinux_1_2_aarch64.whl | CPython 3.10 | abi3 | Linux musl 1.2+ ARM64 | Details |
| py_multiformats-0.3.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.3.0a1-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl | CPython 3.10 | abi3 | Linux glibc 2.17+ ARM64 | Details |
| py_multiformats-0.3.0a1-cp310-abi3-macosx_11_0_arm64.whl | CPython 3.10 | abi3 | macOS 11.0+ ARM64 | Details |
| py_multiformats-0.3.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.3.0a1.tar.gz
| Download URL | py_multiformats-0.3.0a1.tar.gz |
|---|---|
| Size | 76.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9b1110a3e72fd95344b25e7198bfc0e9534847bdb01a710b4284978f2eebde2f
|
|
BLAKE2b-256 checksum How to use checksums |
469d12b61211200a58671bde46f96f6be65db31e16ca8a33aa79087624868166
|
| 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 logRelease files / py_multiformats-0.3.0a1-cp310-abi3-win_amd64.whl
| Download URL | py_multiformats-0.3.0a1-cp310-abi3-win_amd64.whl |
|---|---|
| Size | 384.5 kB |
| Tags | CPython 3.10 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
3d38eb9408828f40d737187d401425cdf1c49d55a45b8baaeff751188a2bf70b
|
|
BLAKE2b-256 checksum How to use checksums |
27a78c77c27fe91ce4cd991c1b9e2474e9a6595e3788c03580888700dbf06f88
|
| 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 logRelease files / py_multiformats-0.3.0a1-cp310-abi3-musllinux_1_2_x86_64.whl
| Download URL | py_multiformats-0.3.0a1-cp310-abi3-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 693.4 kB |
| Tags | CPython 3.10 Linux musl 1.2+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
051613bfa3e1b9d28352f342e9bc235874b7d8860aa630099b167ef9bff814c2
|
|
BLAKE2b-256 checksum How to use checksums |
19d8552e2482bc2efd339402dfc1589d5d3d47c26c4727d2b757a2c664d1a3de
|
| 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 logRelease files / py_multiformats-0.3.0a1-cp310-abi3-musllinux_1_2_aarch64.whl
| Download URL | py_multiformats-0.3.0a1-cp310-abi3-musllinux_1_2_aarch64.whl |
|---|---|
| Size | 639.2 kB |
| Tags | CPython 3.10 Linux musl 1.2+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
42e025f614f4e6db57953a877d8d5ef81d0219698486d4fe4d1ea794646bc14b
|
|
BLAKE2b-256 checksum How to use checksums |
de5668378db72f5dbc306a86ac451171e77f67da34afd255b0174f78cddb731e
|
| 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 logRelease files / py_multiformats-0.3.0a1-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | py_multiformats-0.3.0a1-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 474.9 kB |
| Tags | CPython 3.10 Linux glibc 2.17+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
445584c881bdecc14a4963ccf97a62dae7bedd36824cd71d19ab8afda5dfa690
|
|
BLAKE2b-256 checksum How to use checksums |
0f8bb0d5fcdf2be9a644b7e8bb6d0b5e2f690b6cc07990f7a1c7de3d71168475
|
| 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 logRelease files / py_multiformats-0.3.0a1-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
| Download URL | py_multiformats-0.3.0a1-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl |
|---|---|
| Size | 462.1 kB |
| Tags | CPython 3.10 Linux glibc 2.17+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
683acfd05da99242c7bdacbcd290916bd3d8d210189da819de0780cc2543ee55
|
|
BLAKE2b-256 checksum How to use checksums |
11344456235604b6fc22f9f046616d4ca12b8f540cd9810230e5a5184c0e956b
|
| 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 logRelease files / py_multiformats-0.3.0a1-cp310-abi3-macosx_11_0_arm64.whl
| Download URL | py_multiformats-0.3.0a1-cp310-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 415.8 kB |
| Tags | CPython 3.10 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
4ac12a1726bdcdc43f6e8c8d653d40e513cc1e4bd298fe92aa2edeb94bbc51a6
|
|
BLAKE2b-256 checksum How to use checksums |
5a0f20267653aa2c6d48887d42a980764659bcddbb172d2623a3551ad8652f6e
|
| 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 logRelease files / py_multiformats-0.3.0a1-cp310-abi3-macosx_10_12_x86_64.whl
| Download URL | py_multiformats-0.3.0a1-cp310-abi3-macosx_10_12_x86_64.whl |
|---|---|
| Size | 460.3 kB |
| Tags | CPython 3.10 abi3 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
cd69926cf87ec32ea7cc99463c0523cd989bf574af88f49a8a155c80ed5c62b9
|
|
BLAKE2b-256 checksum How to use checksums |
eb0c15176a800e2a3da8bda034a0f1a674de6378bb69e88f5143ee49c34b1687
|
| 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