IPFSDict Module

class ipfs_dict_chain.IPFSDict.IPFSDict(cid: str | None = None)[source]

Bases: Dict

A dictionary-like object that stores its data on IPFS.

Parameters:

cid (Optional[str], optional) – The IPFS content identifier (CID) of the dictionary data, defaults to None

__getitem__(key: str) Any[source]

Get the value of the given key in the IPFSDict object.

Parameters:

key (str) – The key to get the value for

Returns:

The value of the given key

Return type:

Any

__setitem__(key: str, value: Any) None[source]

Set the value of the given key in the IPFSDict object.

Parameters:
  • key (str) – The key to set the value for

  • value (Any) – The value to set

__str__() str[source]

Convert the IPFSDict object to a string representation.

Returns:

The string representation of the IPFSDict object

Return type:

str

cid() str[source]

Get the IPFS content identifier (CID) of the dictionary data.

Returns:

The CID

Return type:

str

items() List[Tuple[str, Any]][source]

Get the dictionary data. This is a list of key-value pairs with all the data except values that start with an underscore.

Returns:

The dictionary data

Return type:

List[Tuple[str, Any]]

load(cid: str) None[source]

Load the dictionary data from IPFS using the given CID.

Parameters:

cid (str) – The IPFS content identifier (CID) of the dictionary data

Raises:
  • ValueError – If the CID is not a string

  • IPFSError – If there is an issue retrieving the data from IPFS

save() str[source]

Save the dictionary data to IPFS and update the CID.

Returns:

The new CID

Return type:

str