Registry / serialization / py-cid

py-cid

JSON →
library0.5.0pypypi✓ verified 87d ago

py-cid is a Python library that provides an implementation of the Content Identifier (CID) specification. CIDs are self-describing content-addressed identifiers used in distributed systems like IPFS and IPLD, leveraging cryptographic hashing and multiformats for flexible self-description. The library is actively maintained, with version 0.5.0 being the latest release, supporting Python 3.10 and newer.

pip install py-cid
INSTALL
IMPORT
SIG · PY-CID
P
py-cid
serializationpythonv0.5.0
Install
3.9s avg
Import
61ms
Disk
19MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.5.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.910 runs
installs and imports cleanly · install 0.0s · import 0.061s · 22.2MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 3.9s · import 0.061s · 22MB
19MB installed
● package 19MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

make_cid
from cid import make_cid
CIDv0
from cid import CIDv0
CIDv1
from cid import CIDv1

This quickstart demonstrates how to create CIDv0 and CIDv1 objects using `make_cid` from both base58 and multibase encoded strings. It also shows how to access their version, codec, multihash, and how to encode CIDv1 into different multibase formats.

from cid import make_cid, CIDv0, CIDv1 # Create a CIDv0 from a base58-encoded multihash cid_v0_str = 'QmaozNR7DZHQK1ZcU9p7QdrshMvXqWK6gpu5rmrkPdT3L4' cid0 = make_cid(cid_v0_str) print(f"CIDv0: {cid0}") print(f"Version: {cid0.version}, Codec: {cid0.codec}, Multihash: {cid0.multihash.hex()}") # Create a CIDv1 from a multibase-encoded CID string cid_v1_str = 'bafybeigdyrzt5sfp7udm7hu76uh7y26nf3fzmsyqhwfsgr2zfdnc2dsxze' cid1 = make_cid(cid_v1_str) print(f"CIDv1: {cid1}") print(f"Version: {cid1.version}, Codec: {cid1.codec}, Multihash: {cid1.multihash.hex()}") # Accessing components print(f"CIDv0 string: {str(cid0)}") print(f"CIDv1 encoded in base32: {cid1.encode('base32')}") # requires py-multibase
Debug
Known issues
breakingThe PyPI package `py-cid` was previously renamed to `py-multiformats-cid` around version 0.4.0 (2022-10-31). The current `py-cid` (version 0.5.0+) is a distinct project. Installing `py-multiformats-cid` will provide an older, incompatible API if you are expecting the current `py-cid` behavior.
fix
Ensure you are installing `py-cid` from the `ipld/py-cid` project and using `pip install py-cid` for the current API. Avoid `py-multiformats-cid` if you intend to use the latest `py-cid` features.
affects: <=0.4.0 (for the old project that was renamed)
gotchaCIDv0 and CIDv1 have fundamental differences in structure and string representation. CIDv0 CIDs are always Base58-encoded and use the `dag-pb` codec implicitly. CIDv1 CIDs are multibase-encoded (e.g., base32, base64) and explicitly include a codec prefix. Mixing up expectations can lead to incorrect CID parsing or encoding errors.
fix
Be explicit about the CID version you expect. Use `make_cid` which handles both, or `CIDv0` and `CIDv1` constructors directly for specific versions. Remember `cid.encode()` on `CIDv0` will only produce Base58, while `CIDv1.encode(base)` allows various multibase encodings.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'cid'
The `py-cid` library is not installed or the environment is incorrect.
fix
Install the library using `pip install py-cid`.
TypeError: make_cid() takes 1 positional argument but 2 were given
You are likely attempting to pass a 'codec' argument to `make_cid` when it expects to infer it from the input string, or are misusing the `CIDv1` constructor.
fix
`make_cid` generally infers the CID version and codec from the provided string. For `CIDv1` with a raw multihash, use `CIDv1('codec-name', multihash_bytes)` directly. For example: `CIDv1('raw', b'\x12\x20' + b'hash_bytes')`.
AttributeError: 'CIDv0' object has no attribute 'encode_multibase'
You are trying to call a multibase encoding method on a CIDv0 object. CIDv0 only supports Base58 encoding.
fix
Ensure you are working with a `CIDv1` object if you need flexible multibase encoding. For `CIDv0`, use `str(cid_obj)` or `cid_obj.encode()` to get its Base58 string representation.
Upgrade
Version history
0.5.0latest on PyPI · released Feb 13, 2026
Audit
Dependencies
py-multihashrequiredUsed for cryptographic hashing within CIDs.
py-multicodecrequiredRequired to handle different content types (codecs) within CIDs, especially for CIDv1.
py-multibaserequiredNeeded for encoding/decoding CIDv1 strings into various multibase formats.
Agent activity
4 hits · last 30 days
node
4
Resources
py-cid — pip install py-cid · libregistry