aioipfs package

aioipfs module

class aioipfs.AsyncIPFS(host: str = 'localhost', port: int = 5001, scheme: str = 'http', maddr: Union[Multiaddr, str] = None, auth: Optional[Union[BasicAuth, BearerAuth]] = None, loop=None, conns_max: int = 0, conns_max_per_host: int = 0, read_timeout: int = 0, api_version: str = 'v0', debug: bool = False)

Asynchronous IPFS API client

Parameters:
  • maddr (str) – The multiaddr for the IPFS daemon’s RPC API (this is the preferred method of specifying the node’s address)

  • host (str) – Hostname/IP of the IPFS daemon to connect to

  • port (int) – The API port of the IPFS deamon

  • scheme (str) – RPC API protocol: ‘http’ (default) or ‘https’

  • conns_max (int) – Maximum HTTP connections for this client (default: 0)

  • conns_max_per_host (int) – Maximum per-host HTTP connections (default: 0)

  • read_timeout (int) – Socket read timeout

  • api_version' (str) – IPFS protocol version (‘v0’ by default)

  • debug (bool) – Enable client debugging traces

  • loop – force a specific asyncio event loop

coroutine agent_version_superioreq(version: str)

Returns True if the node’s agent version is superior or equal to version

Parameters:

version (str) – a kubo (formerly called go-ipfs) version number e.g “0.14.0”

allocate_tcp_maddr() Multiaddr

Find an unused TCP port on this host and return the multiaddr for it.

Return type:

Multiaddr

class aioipfs.BearerAuth(login: str, password: str = '', encoding: str = 'latin1')

Cheap subclass of BasicAuth to authenticate with a token

encode() str

Encode credentials.

class aioipfs.IpfsDaemonVersion(vstring=None)

aioipfs.api module

class aioipfs.api.BitswapAPI(driver)
coroutine ledger(peer)

Show the current ledger for a peer.

Parameters:

peer (str) – peer id

coroutine reprovide()

Trigger reprovider.

coroutine stat(verbose=False, human=False)

Show some diagnostic information on the bitswap agent.

coroutine unwant(block)

Remove a given block from your wantlist.

(this command has been deprecated it seems).

Parameters:

block (str) – Key(s) to remove from your wantlist

coroutine wantlist(peer=None)

Show blocks currently on the wantlist.

Parameters:

peer (str) – Specify which peer to show wantlist for

class aioipfs.api.BlockAPI(driver)
coroutine get(cid)

Get a raw IPFS block.

Parameters:

cid (str) – The cid of an existing block to get

Return type:

bytes

coroutine put(filepath, cid_codec=None, format='v0', mhtype='sha2-256', mhlen=-1, allow_big_block=False, pin=True)

Store input as an IPFS block.

Parameters:
  • cid_codec (str) – Multicodec to use in returned CID

  • allow_big_block (bool) – Disable block size check and allow creation of blocks bigger than 1MiB

  • filepath (str) – The path to a file containing the data for the block

  • mhtype (str) – multihash hash function

  • mhlen (int) – multihash hash length

  • pin (bool) – pin block

coroutine rm(cid, force=False, quiet=False)

Remove IPFS block(s).

Parameters:
  • cid (str) – The cid of an existing block to remove

  • force (bool) – Ignore nonexistent blocks

  • quiet (bool) – Write minimal output

coroutine stat(cid)

Print information of a raw IPFS block.

Parameters:

cid (str) – The cid of an existing block to stat

class aioipfs.api.BootstrapAPI(driver)

Bootstrap API

coroutine list()

Shows peers in the bootstrap list

coroutine rm_all()

Removes all peers in the bootstrap list

class aioipfs.api.CidAPI(driver)

CID API

coroutine format(cid, format=None, version=None, multibase=None)

Format and convert a CID in various useful ways.

Parameters:
  • cid (str) – CID to convert

  • format (str) – Printf style format string

  • version (int) – CID version to convert to

  • multibase (str) – Multibase to display CID in

class aioipfs.api.ConfigAPI(driver)

Configuration management API

coroutine config(key: str, value=None, boolean: bool = False, json: bool = False)

Get or set IPFS config values

Parameters:
  • key (str) – The key of the config entry (e.g. “Addresses.API”)

  • value (str) – The value to set the config entry to

  • boolean (bool) – Set a boolean value

  • json (bool) – Parse stringified JSON

coroutine profile_apply(profile, dry_run=False)

Apply profile to config

Parameters:
  • profile (str) – The profile to apply to the config

  • dry_run (bool) – print difference between the current config and the config that would be generated

coroutine replace(configpath)

Replaces the IPFS configuration with new config file

Parameters:

configpath (str) – new configuration’s file path

coroutine show()

Outputs IPFS config file contents

class aioipfs.api.CoreAPI(driver)
async add(*files, **kwargs)

Add a file or directory to ipfs.

This is an async generator yielding an IPFS entry for every file added.

The add_json, add_bytes and add_str coroutines support the same options

Parameters:
  • files – A list of files/directories to be added to the IPFS repository

  • recursive (bool) – Add directory paths recursively.

  • quiet (bool) – Write minimal output.

  • quieter (bool) – Write only final hash.

  • silent (bool) – Write no output.

  • progress (bool) – Stream progress data.

  • trickle (bool) – Use trickle-dag format for dag generation.

  • only_hash (bool) – Only chunk and hash - do not write to disk.

  • wrap_with_directory (bool) – Wrap files with a directory object.

  • pin (bool) – Pin this object when adding. Default: true.

  • raw_leaves (bool) – Use raw blocks for leaf nodes.

  • nocopy (bool) – Add the file using filestore.

  • fscache (bool) – Check the filestore for preexisting blocks.

  • offline (bool) – Offline mode (do not announce)

  • hidden (bool) – Include files that are hidden. Only takes effect on recursive add.

  • inline (bool) – Inline small blocks into CIDs

  • hash (str) – Hash function to use

  • to_files (str) – Add reference to a file inside the (MFS) at the provided path

  • inline_limit (int) – Maximum block size to inline

  • cid_version (int) – CID version

coroutine add_bytes(data, **kwargs)

Add a file using given bytes as data.

Parameters:

data (bytes) – file data

async add_generic(mpart, params=None)

Add a multiple-entry multipart, and yield the JSON message for every entry added. We use mjson_decode with the post method.

coroutine add_json(data, **kwargs)

Add a JSON object

Parameters:

data (str) – json object

coroutine add_single(mpart, params=None)

Add a single-entry multipart (used by add_{bytes,str,json})

coroutine add_str(data, name='', codec='utf-8', **kwargs)

Add a file using given string as data

Parameters:
  • data (str) – string data

  • codec (str) – input codec, default utf-8

coroutine cat(path, offset=None, length=None)

Show IPFS object data.

Parameters:
  • path (str) – The path of the IPFS object to retrieve

  • offset (int) – byte offset to begin reading from

  • length (int) – maximum number of bytes to read

coroutine commands(flags=False)

List all available commands.

coroutine dns(name, recursive=False)

Resolve DNS links

Parameters:
  • name (str) – domain name to resolve

  • recursive (bool) – Resolve until the result is not a DNS link.

coroutine get(path, dstdir='.', compress=False, compression_level=-1, archive=True, output=None, progress_callback=None, progress_callback_arg=None, chunk_size=262144)

Download IPFS objects.

Parameters:
  • path (str) – The path of the IPFS object to retrieve

  • dstdir (str) – destination directory, current directory by default

  • compress (bool) – Compress the output with GZIP compression

  • compression_level (str) – The level of compression (1-9)

  • archive (bool) – Output a TAR archive

  • chunk_size (int) – HTTP chunk size

async getgen(objpath, dstdir='.', compress=False, compression_level=-1, archive=True, output=None, progress_callback=None, progress_callback_arg=None, sleept=0.05, chunk_size=262144)

Download IPFS objects (async generator)

Parameters:
  • objpath (str) – The base58 objpath of the object to retrieve

  • dstdir (str) – destination directory, current directory by default

  • compress (bool) – Compress the output with GZIP compression

  • compression_level (str) – The level of compression (1-9)

  • archive (bool) – Output a TAR archive

  • chunk_size (int) – HTTP chunk size

coroutine id(peer: Optional[str] = None, format: Optional[str] = None, peerid_base: Optional[str] = None)

Show IPFS node id info.

Parameters:

peer (str) – peer id to look up, otherwise shows local node info

coroutine ls(path, headers=False, resolve_type=True, size: bool = True, stream: bool = False)

List directory contents for Unix filesystem objects.

Parameters:
  • path (str) – The path to the IPFS object(s) to list links from

  • headers (bool) – Print table headers (Hash, Size, Name)

  • resolve_type (bool) – Resolve linked objects to get their types

async ls_streamed(path, headers=False, resolve_type=True)

List directory contents for Unix filesystem objects (streamed)

Parameters:
  • path (str) – The path to the IPFS object(s) to list links from

  • headers (bool) – Print table headers (Hash, Size, Name)

  • resolve_type (bool) – Resolve linked objects to get their types

async ping(peerid, count=5)

Send echo request packets to IPFS hosts.

Parameters:
  • peerid (str) – ID of peer to be pinged

  • count (int) – Number of ping messages to send

coroutine resolve(name, recursive: bool = False, dht_record_count: Optional[int] = None, dht_timeout: Optional[int] = None)

Resolve the value of names to IPFS

Parameters:
  • name (str) – The name to resolve

  • recursive (bool) – Resolve until the result is an IPFS name

  • dht_record_count (int) – Number of records to request for DHT resolution

  • dht_timeout (int) – Max time to collect values during DHT resolution eg “30s”. Pass 0 for no timeout

coroutine shutdown()

Shut down the ipfs daemon

coroutine version(number=True, commit=True, repo=True, all=True)

Show ipfs version information

coroutine version_deps()

Shows information about dependencies used for build

class aioipfs.api.DhtAPI(driver)
coroutine findpeer(peerid, verbose=False)

DEPRECATED: This command is deprecated

async findprovs(key, verbose=False, numproviders=20)

DEPRECATED: This command is deprecated

coroutine get(peerid, verbose=False)

DEPRECATED: This command is deprecated

async provide(cid, verbose=False, recursive=False)

DEPRECATED: This command is deprecated

coroutine put(key, value)

DEPRECATED: This command is deprecated

async query(peerid, verbose=False)

DEPRECATED: This command is deprecated

class aioipfs.api.DiagAPI(driver)
coroutine cmds(verbose=False)

List commands run on this IPFS node.

coroutine cmds_set_time(time: str)

Set how long to keep inactive requests in the log.

coroutine profile(output: Optional[str] = None, collectors: Optional[list] = None, profile_time: Optional[str] = None, mutex_profile_fraction: Optional[int] = None, block_profile_rate: Optional[str] = None)

Collect a performance profile for debugging.

TODO: support passing collectors as an array

class aioipfs.api.FileAPI(driver)
class aioipfs.api.FilesAPI(driver)
coroutine cp(source, dest, parents: bool = False)

Add references to IPFS files and directories in MFS (or copy within MFS).

coroutine flush(path: str = '/')

Flush a given path’s data to disk.

coroutine write(mfspath, data, create=False, parents=False, cid_version=None, raw_leaves=False, hashfn: Optional[str] = None, truncate=False, offset=-1, count=-1)

Write to a mutable file in a given filesystem.

Parameters:
  • mfspath (str) – Path to write to

  • data – Data to write, can be a filepath or bytes data

  • offset (int) – Byte offset to begin writing at

  • create (bool) – Create the file if it does not exist

  • truncate (bol) – Truncate the file to size zero before writing

  • count (int) – Maximum number of bytes to read

  • cid_version (int) – CID version to use

  • hashfn (str) – Hash function to use. Will set Cid version to 1 if used. (experimental).

class aioipfs.api.FilestoreAPI(driver)
class aioipfs.api.KeyAPI(driver)
coroutine export(name, output=None, format='libp2p-protobuf-cleartext')

Export a keypair

Parameters:
  • name (str) – name of the key to export

  • output (str) – The path where the output should be stored

  • format (str) – The format of the private key to import, libp2p-protobuf-cleartext or pem-pkcs8-cleartext

coroutine key_import(keypath: str, name, ipns_base: Optional[str] = None, format='libp2p-protobuf-cleartext', allow_any_keytype: bool = False)

Import a key and prints imported key id

Parameters:
  • keypath (str) – filepath of the key to import

  • name (str) – name to associate with key in keychain

  • ipns_base (str) – Encoding used for keys: Can either be a multibase encoded CID or a base58btc encoded multihash

  • format (str) – The format of the private key to import, libp2p-protobuf-cleartext or pem-pkcs8-cleartext

  • allow_any_keytype (bool) – Allow importing any key type

class aioipfs.api.LogAPI(driver)
coroutine level(subsystem='all', level='debug')

Change logging level

Parameters:
  • subsystem (str) – The subsystem logging identifier. Use ‘all’ for all subsystems.

  • level (str) – The log level, with ‘debug’ the most verbose and ‘critical’ the least verbose. One of: debug, info, warning, error, critical. Required: yes.

coroutine ls()

List the logging subsystems

async tail()

Read the event log.

async for event in client.log.tail():

class aioipfs.api.NameAPI(driver)
coroutine inspect(record: Union[str, Path], verify: Optional[str] = None, dump: bool = True)

Inspects an IPNS Record

Parameters:
  • record (Union[Path, str]) – Path to the file containing the IPNS record

  • verify (str) – CID of the public IPNS key to validate against

  • dump (bool) – Include a full hex dump of the raw Protobuf record

coroutine publish(path, resolve=True, lifetime='24h', key='self', ttl=None, quieter=False, allow_offline=False, ipns_base: Optional[str] = None)

Publish IPNS names

Parameters:
  • path (str) – ipfs path of the object to be published

  • resolve (bool) – Check if the given path can be resolved before publishing

  • lifetime (str) – Time duration that the record will be valid for. This accepts durations such as “300s”, “1.5h” or “2h45m”. Valid time units are “ns”, “us” (or “µs”), “ms”, “s”, “m”, “h”.

  • key (str) – Name of the key to be used or a valid PeerID, as listed by ‘ipfs key list -l’.

  • allow_offline (bool) – When offline, save the IPNS record to the the local datastore without broadcasting to the network instead of simply failing

  • ttl (str) – Time duration this record should be cached for. Uses the same syntax as the lifetime option

  • quieter (bool) – Write only final hash

  • ipns_base (str) – Encoding used for keys: Can either be a multibase encoded CID or a base58btc encoded multihash

coroutine resolve(name=None, recursive=False, nocache=False, dht_record_count=None, dht_timeout=None, stream=False)

Resolve IPNS names.

Parameters:
  • name (str) – The IPNS name to resolve. Defaults to your node’s peerID

  • recursive (bool) – Resolve until the result is not an IPNS name

  • nocache (bool) – Do not use cached entries

  • dht_record_count (int) – Number of records to request for DHT resolution

  • dht_timeout (int) – Max time to collect values during DHT resolution eg “30s”. Pass 0 for no timeout

  • stream (bool) – Stream entries as they are found

async resolve_stream(name=None, recursive=True, nocache=False, dht_record_count=None, dht_timeout=None, stream=True)

Resolve IPNS names, streaming entries as they’re received (async generator)

class aioipfs.api.NamePubsubAPI(driver)
class aioipfs.api.ObjectAPI(driver)
coroutine diff(obja, objb, verbose=False)

Display the diff between two ipfs objects.

class aioipfs.api.ObjectPatchAPI(driver)

Add a link to a given object.

coroutine append_data(cid, filepath)

Append data to the data segment of a dag node.

Untested

Remove a link from an object.

coroutine set_data(cid, filepath)

Set the data field of an IPFS object.

Untested

class aioipfs.api.RefsAPI(driver)
coroutine refs(path: str, format: Optional[str] = None, edges: bool = False, unique: bool = False, recursive: bool = False, max_depth: Optional[int] = None)

List links (references) from an object.

class aioipfs.api.RepoAPI(driver)
class aioipfs.api.RoutingAPI(driver)
coroutine findpeer(peerid, verbose=False)

Find the multiaddresses associated with a Peer ID.

Parameters:
  • peerid (str) – The ID of the peer to search for

  • verbose (bool) – Print extra information

async findprovs(key, verbose=False, numproviders=20)

Find peers that can provide a specific value, given a key.

Parameters:
  • key (str) – The key to find providers for

  • verbose (bool) – Print extra information

  • numproviders (int) – The number of providers to find. Default: 20

coroutine get(peerid, verbose=False)

Given a key, query the routing system for its best value.

Parameters:
  • key (str) – The key to find providers for

  • verbose (bool) – Print extra information

async provide(key, verbose=False, recursive=False)

Announce to the network that you are providing given values.

Parameters:
  • key (str) – The key[s] to send provide records for

  • verbose (bool) – Print extra information

  • recursive (bool) – Recursively provide entire graph

coroutine put(key, value)

Write a key/value pair to the routing system.

Parameters:
  • key (str) – The key to store the value at

  • verbose (bool) – Print extra information

class aioipfs.api.StatsAPI(driver)
coroutine bw(peer=None, proto=None, poll=False, interval=None)

Print ipfs bandwidth information

class aioipfs.api.TarAPI(driver)
coroutine add(tar)

DEPRECATED: This command is deprecated

coroutine cat(key)

DEPRECATED: This command is deprecated

aioipfs.apis.dag module

class aioipfs.apis.dag.DagAPI(driver)
coroutine car_export(cid: str, progress: bool = False, output_path: Optional[Path] = None)

Streams the selected DAG as a .car stream and return it as a raw buffer or write it to a file if output_path is passed.

Parameters:
  • cid (str) – Root CID of a DAG to recursively export

  • progress (bool) – Stream progress

  • output_path (Path) – Write the CAR data to this file (optional)

coroutine car_import(car, silent=False, pin_roots=True, stats=False, allow_big_block=False)

Import the contents of .car files

Parameters:
  • car – path to a .car archive or bytes object

  • silent (bool) – No output

  • pin_roots (bool) – Pin optional roots listed in the .car headers after importing

coroutine export(cid: str, progress: bool = False, output_path: Optional[Path] = None)

Streams the selected DAG as a .car stream and return it as a raw buffer or write it to a file if output_path is passed.

Parameters:
  • cid (str) – Root CID of a DAG to recursively export

  • progress (bool) – Stream progress

  • output_path (Path) – Write the CAR data to this file (optional)

coroutine export_to_directory(cid: str, dst_dir: Path) bool

Export a UnixFS DAG to a CAR and unpack it to a directory

Parameters:
  • cid (str) – CID of a UnixFS DAG to recursively export

  • dst_dir (Path) – Filesystem destination path

Return type:

bool

coroutine get(objpath, output_codec=None)

Get a DAG node from IPFS

Parameters:
  • objpath (str) – path of the object to fetch

  • output_codec (str) – Format that the object will be encoded as

coroutine put(filename, store_codec='dag-cbor', input_codec='dag-json', hashfn='sha2-256', pin=True, allow_big_block=False)

Add a DAG node to IPFS

Parameters:
  • filename (str) – a path to the object to import

  • format (str) – format to use for the object inside IPFS

  • input_enc (str) – object input encoding

  • pin (bool) – pin the object after adding (default is False)

  • offline (bool) – Offline mode (no announce)

coroutine resolve(path)

Resolve an IPLD block

Parameters:

path (str) – path to resolve

async stat(cid, progress=True)

Gets stats for a DAG

Parameters:

cid (str) – CID of a DAG root to get statistics for

aioipfs.apis.multibase module

class aioipfs.apis.multibase.MultibaseAPI(driver)
coroutine decode(filepath: str)

Decode multibase string

Parameters:

filepath (str) – Path to the file containing the data to encode

coroutine encode(filepath: str, base='base64url')

Encode data into multibase string

Parameters:
  • filepath (str) – Path to the file containing the data to encode

  • base (str) – multibase encoding. Default: base64url

coroutine list(prefix=False, numeric=False)

List available multibase encodings

coroutine transcode(filepath: str, base='base64url')

Transcode multibase string between bases

Parameters:
  • filepath (str) – Path to the file containing the data to transcode

  • base (str) – multibase encoding. Default: base64url

aioipfs.apis.pin module

class aioipfs.apis.pin.PinAPI(driver)
async add(path, recursive=True, progress=True, name: Optional[str] = None)

Pin objects to local storage.

Parameters:
  • path (str) – Path to object(s) to be pinned

  • recursive (bool) – Recursively pin the object linked to by the specified object(s)

  • name (str) – An optional name for the created pin(s)

  • progress (bool) – Show progress

coroutine ls(path=None, pintype='all', quiet=False, stream: bool = False, names: bool = False)

List objects pinned to local storage.

Parameters:
  • path (str) – Path of object(s) to be listed

  • pintype (str) – The type of pinned keys to list. Can be “direct”, “indirect”, “recursive”, or “all”

  • quiet (bool) – Write just hashes of objects

  • stream (bool) – Enable streaming of pins as they are discovered

  • names (bool) – Enable displaying pin names

coroutine rm(path, recursive=True)

Remove pinned objects from local storage.

Parameters:
  • path (str) – Path of object(s) to be removed

  • recursive (bool) – Recursively unpin the object linked to by the specified object(s)

coroutine update(old, new, unpin=True)

Update a recursive pin

Parameters:
  • old (str) – Path to old object

  • new (str) – Path to new object to be pinned

  • unpin (bool) – Remove the old pin

coroutine verify(verbose=False, quiet=True)

Verify that recursive pins are complete.

Parameters:
  • verbose (bool) – Also write the hashes of non-broken pins

  • quiet (bool) – Write just hashes of broken pins

class aioipfs.apis.pin.PinRemoteAPI(driver)
coroutine add(service: str, objPath: str, name=None, background=False)

Pin object to remote pinning service.

Parameters:
  • service (str) – Service name

  • objPath (str) – Path to object(s) to be pinned

  • name (str) – An optional name for the pin

  • background (bool) – Add to the queue on the remote service and return immediately (does not wait for pinned status) Default: false

async ls(service: str, name=None, cid: list = [], status: list = ['pinned'])

List objects pinned to remote pinning service.

Parameters:
  • service (str) – Name of the remote pinning service to use

  • name (str) – Return pins with names that contain the value provided (case-sensitive, exact match)

  • cid (list) – Return pins for the specified CIDs

  • status (list) – Return pins with the specified statuses (queued,pinning,pinned,failed). Default: [pinned]

coroutine rm(service: str, name=None, cid: list = [], status: list = ['pinned'], force=False)

Remove pins from remote pinning service.

Parameters:
  • service (str) – Name of the remote pinning service to use

  • name (str) – Return pins with names that contain the value provided (case-sensitive, exact match)

  • cid (list) – Return pins for the specified CIDs

  • status (list) – Return pins with the specified statuses (queued,pinning,pinned,failed). Default: [pinned]

  • force (bool) – Allow removal of multiple pins matching the query without additional confirmation. Default: false

class aioipfs.apis.pin.PinRemoteServiceAPI(driver)
coroutine add(service, endpoint, key)

Add remote pinning service.

Parameters:
  • service (str) – Service name

  • endpoint (str) – Service endpoint

  • key (str) – Service key

coroutine ls(stat=False)

List remote pinning services.

Parameters:

stat (bool) – Try to fetch and display current pin count on remote service (queued/pinning/pinned/failed)

coroutine rm(service)

Remove remote pinning service.

Parameters:

service (str) – Service name

aioipfs.apis.p2p module

class aioipfs.apis.p2p.P2PAPI(driver)

P2P API.

Note: go-ipfs v0.4.18 introduced some changes in the P2P subsystem and some endpoints were renamed. Agent version detection is done in the affected API calls to maintain compatibility.

coroutine dial(protocol, laddress, target, allow_custom_protocol=False)

Dial to a P2P listener.

Parameters:
  • peer (str) – Remote Peer ID

  • protocol (str) – protocol identifier

  • address (str) – multiaddr to listen for connection/s (default: /ip4/127.0.0.1/tcp/0)

coroutine forward(protocol, laddress, target, allow_custom_protocol=False)

Dial to a P2P listener.

Parameters:
  • peer (str) – Remote Peer ID

  • protocol (str) – protocol identifier

  • address (str) – multiaddr to listen for connection/s (default: /ip4/127.0.0.1/tcp/0)

coroutine listen(protocol, address, allow_custom_protocol=False, report_peerid=False)

Open a P2P listener

Parameters:
  • protocol (str) – protocol name associated with the listener

  • address (str) – address for the listener, in multiaddr format

coroutine listener_close(protocol, listen_address=None, target_address=None, all=False)

Close a previously opened P2P listener

Parameters:
  • protocol (str) – protocol name associated with the listener

  • all (bool) – if True, closes all listeners on the node

coroutine listener_ls(headers=False)

List P2P listeners

Parameters:

headers (bool) – print all headers (HandlerID, Protocol, …)

coroutine listener_open(protocol, address, allow_custom_protocol=False, report_peerid=False)

Open a P2P listener

Parameters:
  • protocol (str) – protocol name associated with the listener

  • address (str) – address for the listener, in multiaddr format

coroutine ls(headers=False)

List P2P listeners

Parameters:

headers (bool) – print all headers (HandlerID, Protocol, …)

coroutine stream_close(stream_id=None, all=False)

Close active P2P stream.

coroutine stream_dial(protocol, laddress, target, allow_custom_protocol=False)

Dial to a P2P listener.

Parameters:
  • peer (str) – Remote Peer ID

  • protocol (str) – protocol identifier

  • address (str) – multiaddr to listen for connection/s (default: /ip4/127.0.0.1/tcp/0)

coroutine stream_ls(headers=False)

List active P2P streams.

class aioipfs.apis.p2p.P2PDialerMixin

APIs to help with dialing remote p2p services

dial_endpoint(p2pEndpointAddr: str, address=None, auto=True, allow_loopback=False)

Dial a remote p2p service by passing an endpoint address.

/p2p/12D3KooWAci7T5tA1ZaxBBREVEdLX5FJkH2GBcgbJGW6LqJtBgOp/x/hello

Returns an async context manager:

async with client.p2p.dial_endpoint(‘/p2p/…’) as ctx:

Parameters:
  • p2pEndpointAddr (str) – Endpoint address

  • address (str) – Multiaddr for the connection

  • auto (bool) – Automatically assign a multiaddr (only works if the kubo daemon is local)

  • allow_loopback (bool) – Allow dialing a service on this node

dial_service(peer: str, protocol: str, address=None, auto=True, allow_loopback=False)

Dial a remote IPFS p2p service.

Returns an async context manager:

async with client.p2p.dial_service(…) as ctx:

print(ctx.maddr_host, ctx.maddr_port)

Parameters:
  • peer (str) – Peer ID

  • protocol (str) – Service protocol (e.g /x/helloworld)

  • address (str) – Multiaddr for the connection

  • auto (bool) – Automatically assign a multiaddr (only works if the kubo daemon is local)

  • allow_loopback (bool) – Allow dialing a service on this node

class aioipfs.apis.p2p.TunnelDialerContext(client, peerId: str, proto: str, maddr: Multiaddr)

Service dial context manager

property failed

Returns True if the service dial has failed

httpUrl(path: str, query: str = '', fragment: str = '', scheme: str = 'http') URL

Returns an HTTP URL targeting the remote P2P service associated with this context.

Parameters:
  • path (str) – HTTP path

  • query (str) – HTTP query

  • fragment (str) – HTTP fragment

  • scheme (str) – URL scheme (http or https)

Return type:

URL

property maddr_host

The connection hostname/ip

property maddr_port

The connection TCP port

aioipfs.apis.pubsub module

class aioipfs.apis.pubsub.PubSubAPI(driver)
coroutine ls()

List the names of the subscribed pubsub topics.

Rtype dict:

coroutine peers(topic=None)

List peers communicating over pubsub with this node.

coroutine pub(topic, data: Union[str, bytes])

Publish a message to a given pubsub topic.

Parameters:
  • topic (str) – topic to publish the message to

  • data – message data (bytes or str)

async sub(topic: str, discover: bool = True, timeout: int = 0, read_timeout: int = 0)

Subscribe to messages on a given topic.

This is an async generator yielding messages as they are read on the pubsub topic.

Parameters:
  • topic (str) – topic to subscribe to

  • discover (bool) – try to discover other peers subscribed to the same topic

  • timeout (int) – global coroutine timeout

  • read_timeout (int) – read timeout (between each message read)

aioipfs.apis.swarm module

class aioipfs.apis.swarm.SwarmAPI(driver)
coroutine addrs()

List known addresses. Useful for debugging.

coroutine addrs_listen()

List interface listening addresses.

coroutine addrs_local(id=False)

List local addresses.

coroutine connect(peer)

Open connection to a given address.

Parameters:

peer (str) – address of peer to connect to

coroutine disconnect(peer)

Close connection to a given address.

Parameters:

peer (str) – address of peer to disconnect from

coroutine filters_add(filter)

Add an address filter.

Parameters:

filter (str) – Multiaddr to filter

coroutine filters_rm(filter)

Remove an address filter.

Parameters:

filter (str) – Multiaddr filter to remove

coroutine limit(filepath, scope: str)

Get or set resource limits for a scope

Parameters:
  • filepath (str) – path to the (JSON) file containing the limits

  • scope (str) – scope of the limit

coroutine peers(verbose=True, streams=False, latency=False, direction=False)

List peers with open connections.

Parameters:
  • verbose (bool) – display all extra information

  • streams (bool) – Also list information about open streams for each peer

  • latency (bool) – Also list information about latency to each peer

  • direction (bool) – Also list information about the direction of connection

coroutine resources()

Get a summary of all resources accounted for by the libp2p Resource Manager.

coroutine stats(scope: str)

Report resource usage for a scope

Parameters:

scope (str) – scope of the stat report

class aioipfs.apis.swarm.SwarmPeeringAPI(driver)
coroutine add(peer: str)

Add peers into the peering subsystem.

Parameters:

peer (str) – address of peer to add into the peering subsystem

coroutine ls()

List peers registered in the peering subsystem.

coroutine rm(peer: str)

Remove a peer from the peering subsystem.

Parameters:

peer (str) – ID of peer to remove from the peering subsystem

aioipfs.util module

exception aioipfs.util.CARDecoderMissing
class aioipfs.util.DotJSON(data)

Based on edict, described here:

https://gist.github.com/markhu/fbbab71359af00e527d0

coroutine aioipfs.util.car_bytes(stream, cid: str) bytes

CAR stream to bytes

Parameters:
  • stream – CAR stream

  • cid (str) – CID of the UnixFS file to export

Return type:

bytes

aioipfs.util.car_open(car_path: Path)

Open a Content-Addressable aRchive file and return the CAR stream.

Parameters:

car_path (Path) – CAR file path

aioipfs.exceptions module

exception aioipfs.exceptions.APIError(code=-1, message='', http_status=-1)

Bases: Exception

IPFS API error

Parameters:
  • code (int) – IPFS error code

  • message (str) – Error message

  • http_status (int) – HTTP status code

classmethod match(message: str)
Parameters:

message (str) – Error message string returned by kubo

Return type:

bool

exception aioipfs.exceptions.EndpointNotFoundError(code=-1, message='', http_status=-1)

Bases: APIError

Exception for when a RPC endpoint is not found (HTTP 404)

exception aioipfs.exceptions.IPFSConnectionError

Bases: Exception

exception aioipfs.exceptions.InvalidCIDError(code=-1, message='', http_status=-1)

Bases: APIError

Invalid CID or selected encoding not supported

classmethod match(message: str)
Parameters:

message (str) – Error message string returned by kubo

Return type:

bool

exception aioipfs.exceptions.InvalidNodeAddressError

Bases: Exception

exception aioipfs.exceptions.InvalidPubMessageError

Bases: Exception

Invalid pubsub message encoding error

exception aioipfs.exceptions.IpnsKeyError(code=-1, message='', http_status=-1)

Bases: APIError

IPNS key errors

classmethod match(message: str)
Parameters:

message (str) – Error message string returned by kubo

Return type:

bool

exception aioipfs.exceptions.NoSuchLinkError(code=-1, message='', http_status=-1)

Bases: APIError

No link by that name

classmethod match(message: str)
Parameters:

message (str) – Error message string returned by kubo

Return type:

bool

exception aioipfs.exceptions.NotPinnedError(code=-1, message='', http_status=-1)

Bases: APIError

Content not pinned or pinned indirectly

classmethod match(message: str)
Parameters:

message (str) – Error message string returned by kubo

Return type:

bool

exception aioipfs.exceptions.PinRemoteError(code=-1, message='', http_status=-1)

Bases: APIError

Any kind of error ocurring when interacting with a remote pinning service.

classmethod match(message: str)
Parameters:

message (str) – Error message string returned by kubo

Return type:

bool

exception aioipfs.exceptions.RPCAccessDenied

Bases: Exception

RPC request denied due to invalid authentication credentials

exception aioipfs.exceptions.UnknownAPIError(code=-1, message='', http_status=-1)

Bases: APIError