IPFSDictChain Module

Dictionary-like data structure that stores its state on IPFS and keeps track of changes.

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

Bases: IPFSDict

A dictionary-like data structure that stores its state on IPFS and keeps track of changes.

Parameters:

cid (Optional[str], optional) – The IPFS CID to initialize the dictionary with, defaults to None

__init__(cid: str | None = None)[source]

Initialize the IPFSDictChain object.

Parameters:

cid (Optional[str], optional) – The IPFS CID to initialize the dictionary with, defaults to None.

_get_previous_cid_for(cid: str) str | None[source]

Lightweight fetch of just the previous_cid for a given state CID.

This avoids creating a full IPFSDictChain instance which would make unnecessary network calls for data we don’t need.

Parameters:

cid (str) – The CID of the state to fetch previous_cid from

Returns:

The previous CID, or None if not found or on error

Return type:

Optional[str]

changes() Dict[str, Dict[str, Any]][source]

Returns a dictionary containing the changes between the current state and the previous state.

Returns:

A dictionary of changes, with keys as attribute names and values as dictionaries containing the old and new values

Return type:

Dict[str, Dict[str, Any]]

get_previous_cids(max_depth: int | None = None) List[str][source]

Returns a list of previous CIDs.

Uses lightweight fetches to traverse the chain without loading full state data.

Parameters:

max_depth (Optional[int], optional) – The maximum number of previous CIDs to return, defaults to None

Returns:

A list of previous CIDs

Return type:

List[str]

get_previous_states(max_depth: int | None = None) List[Dict[str, Any]][source]

Returns a list of previous states as dictionaries.

Parameters:

max_depth (Optional[int], optional) – The maximum number of previous states to return, defaults to None

Returns:

A list of previous state dictionaries

Return type:

List[Dict[str, Any]]

save() str[source]

Saves the current state of the dictionary to IPFS and returns the new CID.

Returns:

The new IPFS CID

Return type:

str