pystratos API

class pystratos.AsyncIpfsClient(base_url: str = 'http://127.0.0.1:5001/api/v0', timeout: int | None = None)

Bases: object

AsyncIpfsClient is an asynchronous client for interacting with IPFS (InterPlanetary File System).

async add(file: bytes, *, filename: str | None = None) dict
async add(file: IO[bytes], *, filename: str | None = None) dict

Adds a file to IPFS. :param file: The file to add, either as bytes or a file-like object. :param filename: Optional name for the file in IPFS. If not provided, a random UUID will be used as the filename. :return: A dictionary containing the response from the IPFS API, typically including the CID (Content Identifier) of the added file.

async cat(cid)

Retrieves a file from IPFS by its CID. :param cid: The Content Identifier (CID) of the file to retrieve.

class pystratos.AsyncSpfsClient(base_url: str = 'https://sds-gateway-uswest.thestratos.org/spfs/PSu46EiNUYevTVA8doNHiCAFrxU=/api/v0', timeout: int | None = None)

Bases: AsyncIpfsClient

AsyncSpfsClient is a subclass of AsyncIpfsClient that provides methods for interacting with the Stratos Public File System (SPFS). It inherits all methods from AsyncIpfsClient and can be used to add and retrieve files from SPFS.

async add(file: bytes | IO[bytes], *, filename: str | None = None, encryption_key: bytes | None = None) dict

Adds a file to SPFS. If an encryption key is provided, the file will be encrypted before being added.

Parameters:
  • file – The file to add, either as bytes or a file-like object.

  • filename – Optional name for the file in SPFS. If not provided, a random UUID will be used as the filename.

  • encryption_key – Optional encryption key for encrypting the file before adding it to SPFS. If provided, the file will be encrypted using this key.

Returns:

A dictionary containing the response from the SPFS API, typically including the CID (Content Identifier) of the added file.

async cat(cid: str, encryption_key: bytes | None = None) bytes

Retrieves a file from SPFS by its CID. If an encryption key is provided, the file will be decrypted after retrieval. :param cid: The Content Identifier (CID) of the file to retrieve. :param encryption_key: Optional encryption key for decrypting the file after retrieval. If provided, the file will be decrypted using this key. :return: The content of the file, either encrypted or decrypted based on the presence of an encryption key.