IPFS Module

class ipfs_dict_chain.IPFS.IPFSCache[source]

Bases: object

A simple cache for IPFS data.

get(cid: str) Dict[source]

Retrieve data from the cache by its Content Identifier (CID).

Parameters:

cid (str) – The Content Identifier (CID) of the data in the cache.

Returns:

The data retrieved from the cache.

Return type:

Dict

set(cid: str, data: Dict) None[source]

Store data in the cache with its Content Identifier (CID).

Parameters:
  • cid (str) – The Content Identifier (CID) of the data.

  • data (Dict) – The data to be stored in the cache.

exception ipfs_dict_chain.IPFS.IPFSError[source]

Bases: Exception

Custom exception for IPFS-related errors.

async ipfs_dict_chain.IPFS._add_json(data: Dict) str[source]

Add JSON data to IPFS and return its Content Identifier (CID).

Parameters:

data (Dict) – The JSON data to be added to IPFS.

Returns:

The Content Identifier (CID) of the added JSON data.

Return type:

str

async ipfs_dict_chain.IPFS._get_json(cid: str) Dict[source]

Retrieve JSON data from IPFS by its Content Identifier (CID) and cache the result.

Parameters:

cid (str) – The Content Identifier (CID) of the JSON data in IPFS.

Returns:

The JSON data retrieved from IPFS.

Return type:

Dict

ipfs_dict_chain.IPFS.add_json(data: Dict) str[source]

Add JSON data to IPFS and return its Content Identifier (CID) using a synchronous wrapper.

Parameters:

data (Dict) – The JSON data to be added to IPFS.

Returns:

The Content Identifier (CID) of the added JSON data.

Return type:

str

ipfs_dict_chain.IPFS.connect(host: str, port: int) None[source]

Connect to an IPFS daemon.

Parameters:
  • host (str) – The host of the IPFS daemon.

  • port (int) – The port of the IPFS daemon.

Raises:

IPFSError – If the connection to the IPFS daemon fails.

async ipfs_dict_chain.IPFS.get_file_content(cid: str) str[source]

Retrieve the content of a file from IPFS by its Content Identifier (CID).

Parameters:

cid (str) – The Content Identifier (CID) of the file in IPFS.

Returns:

The content of the file.

Return type:

str

ipfs_dict_chain.IPFS.get_json(cid: str) Dict[source]

Retrieve JSON data from IPFS by its Content Identifier (CID) using a synchronous wrapper.

Parameters:

cid (str) – The Content Identifier (CID) of the JSON data in IPFS.

Returns:

The JSON data retrieved from IPFS.

Return type:

Dict