API Reference¶
Helper functions¶
-
cid.
make_cid
(*args)[source]¶ Creates a
cid.CIDv0
orcid.CIDv1
object based on the given parametersThe function supports the following signatures:
make_cid(<base58 encoded multihash CID>) -> CIDv0
make_cid(<multihash CID>) -> CIDv0
make_cid(<multibase encoded multihash CID>) -> CIDv1
make_cid(<version>, <codec>, <multihash>) -> CIDv1
Parameters: args –
- base58-encoded multihash (str or bytes)
- multihash (str or bytes)
- multibase-encoded multihash (str or bytes)
- version:int, codec(str), multihash(str or bytes)
Returns: the respective CID object
Return type: Raises: - ValueError – if the number of arguments is not 1 or 3
- ValueError – if the only argument passed is not a
str
or abyte
- ValueError – if the string provided is not a valid base58 encoded hash
- ValueError – if 3 arguments are passed and version is not 0 or 1
- ValueError – if 3 arguments are passed and the
codec
is not supported bymulticodec
- ValueError – if 3 arguments are passed and the
multihash
is notstr
orbyte
- ValueError – if 3 arguments are passed with version 0 and codec is not dag-pb
-
cid.
is_cid
(cidstr)[source]¶ Checks if a given input string is valid encoded CID or not. It takes same input as cid.make_cid method with a single argument
Parameters: cidstr (str or bytes) – input string which can be a
- base58-encoded multihash
- multihash
- multibase-encoded multihash
Returns: if the value is a valid CID or not Return type: bool
-
cid.
from_string
(cidstr)[source]¶ Creates a CID object from a encoded form
Parameters: cidstr (str) – can be
- base58-encoded multihash
- multihash
- multibase-encoded multihash
Returns: a CID object Return type: cid.CIDv0
orcid.CIDv1
-
cid.
from_bytes
(cidbytes)[source]¶ Creates a CID object from a encoded form
Parameters: cidbytes (bytes) – can be
- base58-encoded multihash
- multihash
- multibase-encoded multihash
Returns: a CID object Return type: cid.CIDv0
orcid.CIDv1
Raises: ValueError if the base58-encoded string is not a valid string Raises: ValueError if the length of the argument is zero Raises: ValueError if the length of decoded CID is invalid
CID classes¶
-
class
cid.
CIDv0
(multihash)[source]¶ Bases:
cid.cid.BaseCID
CID version 0 object
-
CODEC
= 'dag-pb'¶
-
buffer
¶ The raw representation that will be encoded.
Returns: the multihash Return type: bytes
-
codec
¶ CID codec
-
multihash
¶ CID multihash
-
version
¶ CID version
-
-
class
cid.
CIDv1
(codec, multihash)[source]¶ Bases:
cid.cid.BaseCID
CID version 1 object
-
buffer
¶ The raw representation of the CID
Returns: raw representation of the CID Return type: bytes
-
codec
¶ CID codec
-
encode
(encoding='base58btc')[source]¶ Encoded version of the raw representation
Parameters: encoding (str) – the encoding to use to encode the raw representation, should be supported by py-multibase
Returns: encoded raw representation with the given encoding Return type: bytes
-
multihash
¶ CID multihash
-
to_v0
()[source]¶ Get an equivalent
cid.CIDv0
object.Returns: cid.CIDv0
objectReturn type: cid.CIDv0
Raises: ValueError – if the codec is not ‘dag-pb’
-
version
¶ CID version
-