### Install aioipfs Source: https://aioipfs.readthedocs.io Commands to install the base library and optional extras. ```bash pip install aioipfs ``` ```bash pip install 'aioipfs[car]' ``` ```bash pip install 'aioipfs[orjson]' ``` ```bash pip install 'aioipfs[bohort]' ``` -------------------------------- ### Core API - Get Object Source: https://aioipfs.readthedocs.io Method for downloading IPFS objects by their CID. ```APIDOC ## Core API - Get Object ### Description Method for downloading IPFS objects by their CID. ### Method `client.core.get(cid, dstdir=None)` ### Parameters - `cid` (str): The CID of the object to download. - `dstdir` (str, optional): The destination directory to save the object. ### Request Example: Downloading an object ```python await client.core.get('QmRGqvWK44oWu8re5whp43P2M7j5XEDLHmPB3wncYFmCNg') await client.core.get('QmRGqvWK44oWu8re5whp43P2M7j5XEDLHmPB3wncYFmCNg', dstdir='/tmp') ``` ``` -------------------------------- ### Get node information Source: https://aioipfs.readthedocs.io Retrieve information about the current IPFS node. ```python info = await client.core.id() ``` -------------------------------- ### Dial Remote HTTP Service Source: https://aioipfs.readthedocs.io Dial a remote HTTP service using 'dial_service' and access its content via an HTTP GET request. Requires the 'aiohttp' library for making the request. ```python async with client.p2p.dial_service( '12D3KooWRd9Pt1Fri5F4W32uhGm8fBG4pvxEiFwgMru85zmajxcd', '/x/http1') as ctx: async with aiohttp.ClientSession() as sess: async with sess.get(ctx.httpUrl('/')) as resp: print(await resp.read()) ``` -------------------------------- ### Initialize AsyncIPFS Client Source: https://aioipfs.readthedocs.io Methods for creating an AsyncIPFS client instance using multiaddr or host/port parameters. ```python import aioipfs client = aioipfs.AsyncIPFS(maddr='/ip4/127.0.0.1/tcp/5001') client = aioipfs.AsyncIPFS(maddr='/dns4/localhost/tcp/5001') ``` ```python client = aioipfs.AsyncIPFS() client = aioipfs.AsyncIPFS(host='10.0.12.3', port=5003) ``` -------------------------------- ### Configure RPC Authentication Source: https://aioipfs.readthedocs.io Setting up Basic Auth or Bearer tokens for RPC access. ```python client = aioipfs.AsyncIPFS(auth=aioipfs.BasicAuth('john', 'password123')) client = aioipfs.AsyncIPFS(auth=aioipfs.BearerAuth('my-secret-token')) ``` ```python client.auth = aioipfs.BasicAuth('alice', 'anotherpass') client.auth = None ``` -------------------------------- ### Use Async Context Manager Source: https://aioipfs.readthedocs.io Managing the client lifecycle using an asynchronous context manager. ```python async with aioipfs.AsyncIPFS() as client: async for reply in client.ping(peer_id): ... ``` -------------------------------- ### Set Connection Parameters Source: https://aioipfs.readthedocs.io Configuring maximum HTTP connections and read timeouts. ```python client = aioipfs.AsyncIPFS(host='localhost', port=5008, conns_max=20) client = aioipfs.AsyncIPFS(host='localhost', port=5008, read_timeout=30) ``` -------------------------------- ### Dial a P2P Service Source: https://aioipfs.readthedocs.io Use the 'dial_service' context manager to establish a connection to a P2P service. The multiaddr, host, and port are accessible within the context. ```python async with client.p2p.dial_service( '12D3KooWRd9Pt1Fri5F4W32uhGm8fBG4pvxEiFwgMru85zmajxcd', '/x/myservice') as ctx: if ctx.failed: # Dialing failed raise Exception('....') # The multiaddr is available as 'ctx.maddr' print(f'Multiaddr': {ctx.maddr}) # The host/port can be retrieved via maddr_host and maddr_port print(f'Host: {ctx.maddr_host}, port: {ctx.maddr_port}') ``` -------------------------------- ### Core API - Add Files Source: https://aioipfs.readthedocs.io Methods for adding files and directories to IPFS using the Core API. ```APIDOC ## Core API - Add Files ### Description Methods for adding files and directories to IPFS using the Core API. ### Method `client.core.add(source, **kwargs)` ### Parameters - `source`: Path to file/directory or list of paths/data. - `recursive` (bool): If True, recursively add directories. - `wrap_with_directory` (bool): If True, wrap added items in a directory. - `to_files` (str): Path in MFS to link the added object. - `ignore_rules_path` (str): Path to a file containing ignore rules (e.g., .ipfsignore). ### Request Example: Adding a file recursively ```python async for added in client.core.add('file1.txt', '/usr/local/src', recursive=True): print(added['Hash']) ``` ### Request Example: Adding multiple items and wrapping with a directory ```python async for added in client.core.add(['one', 'two', 'three'], wrap_with_directory=True): ... ``` ### Request Example: Adding a file and linking it in MFS ```python async for added in client.core.add('file1.txt', to_files='/file1.txt'): print(added['Hash']) ``` ### Request Example: Using ignore rules ```python async for added in client.core.add('directory', recursive=True, ignore_rules_path='.ipfsignore'): print(added['Hash']) ``` ### Response Entries yielded are dictionaries with 'Name', 'Hash', and 'Size' keys. ``` -------------------------------- ### Add bytes and strings Source: https://aioipfs.readthedocs.io Add raw bytes or UTF-8 strings to IPFS, optionally linking to MFS. ```python >>> entry = await client.core.add_bytes(b'ABCD') {'Name': 'QmZ655k2oftYnsocBxqTWzDer3GNui2XQTtcA4ZUbhpz5N', 'Hash': 'QmZ655k2oftYnsocBxqTWzDer3GNui2XQTtcA4ZUbhpz5N', 'Size': '12'} entry = await client.core.add_bytes('ABCD', to_files='/abcd') ``` ```python entry = await client.core.add_str('ABCD') entry = await client.core.add_str('ABCD', to_files='/abcd') ``` -------------------------------- ### Retrieve IPFS objects Source: https://aioipfs.readthedocs.io Download objects, read raw data, or list directory contents. ```python await client.core.get('QmRGqvWK44oWu8re5whp43P2M7j5XEDLHmPB3wncYFmCNg') await client.core.get('QmRGqvWK44oWu8re5whp43P2M7j5XEDLHmPB3wncYFmCNg', dstdir='/tmp') ``` ```python bytes = await client.core.cat(cid) ``` ```python listing = await client.core.ls(path) ``` -------------------------------- ### Core API - List Source: https://aioipfs.readthedocs.io Method for listing the contents of a path or CID. ```APIDOC ## Core API - List ### Description Method for listing the contents of a path or CID. ### Method `client.core.ls(path)` ### Parameters - `path` (str): The path or CID to list. ### Response - `listing`: A representation of the listing (details depend on IPFS implementation). ### Request Example ```python listing = await client.core.ls(path) ``` ``` -------------------------------- ### Configure HTTPS RPC Source: https://aioipfs.readthedocs.io Connecting to nodes that serve the RPC API over HTTPS. ```python client = aioipfs.AsyncIPFS(maddr='/ip4/10.0.1.4/tcp/5001/https') client = aioipfs.AsyncIPFS(host='10.0.1.4', scheme='https') ``` -------------------------------- ### CAR File Handling Utilities Source: https://aioipfs.readthedocs.io Utilities for opening CAR files and extracting their content. ```APIDOC ## CAR File Handling Utilities ### Description Utilities for opening CAR files and extracting their content. ### Functions - `aioipfs.util.car_open(file_path)`: Opens a .car archive file and returns a FileByteStream. - `aioipfs.util.car_bytes(car_stream, cid)`: Extracts raw bytes content from a CAR stream for a given UnixFS file CID. ### Request Example: Reading CAR file content ```python from pathlib import Path from aioipfs import util data = await util.car_bytes( util.car_open(Path('docs.car')), 'bafybeiawyahkjt4kzrzc3bjylqupniukbpnbvys7pt536c64gxg7onq36m' ) ``` ``` -------------------------------- ### Add files to IPFS Source: https://aioipfs.readthedocs.io Add files or directories to the IPFS repository, optionally linking them to MFS or using ignore rules. ```python async for added in client.core.add('file1.txt', '/usr/local/src', recursive=True): print(added['Hash']) async for added in client.core.add(['one', 'two', 'three'], wrap_with_directory=True): ... cids = [entry['Hash'] async for entry in client.add(dir_path)] ``` ```python async for added in client.core.add('file1.txt', to_files='/file1.txt'): print(added['Hash']) ``` ```python async for added in client.core.add('directory', recursive=True, ignore_rules_path='.ipfsignore'): print(added['Hash']) ``` -------------------------------- ### Tail IPFS Event Log Source: https://aioipfs.readthedocs.io Access the IPFS event log to stream messages. Requires importing the 'pprint' module for formatted output. ```python import pprint async for msg in client.log.tail(): print(pprint.pprint(msg)) ``` -------------------------------- ### Add and Pin CID Source: https://aioipfs.readthedocs.io Pin a CID or an IPFS path to the local storage. The progress of the pinning operation is yielded asynchronously. ```python async for pinned in client.pin.add(cid): print('Pin progress', pinned['Progress']) ``` -------------------------------- ### Core API - Add Bytes/String Source: https://aioipfs.readthedocs.io Methods for adding raw bytes or UTF-8 strings to IPFS. ```APIDOC ## Core API - Add Bytes/String ### Description Methods for adding raw bytes or UTF-8 strings to IPFS. ### Method: `client.core.add_bytes(data, **kwargs)` ### Parameters - `data` (bytes): The bytes data to add. - `to_files` (str, optional): Path in MFS to link the added object. ### Request Example: Adding bytes ```python entry = await client.core.add_bytes(b'ABCD') # {'Name': 'QmZ655k2oftYnsocBxqTWzDer3GNui2XQTtcA4ZUbhpz5N', 'Hash': 'QmZ655k2oftYnsocBxqTWzDer3GNui2XQTtcA4ZUbhpz5N', 'Size': '12'} entry = await client.core.add_bytes('ABCD', to_files='/abcd') ``` ### Method: `client.core.add_str(data, **kwargs)` ### Parameters - `data` (str): The UTF-8 string data to add. - `to_files` (str, optional): Path in MFS to link the added object. ### Request Example: Adding a string ```python entry = await client.core.add_str('ABCD') entry = await client.core.add_str('ABCD', to_files='/abcd') ``` ``` -------------------------------- ### Core API - Node Info Source: https://aioipfs.readthedocs.io Method for retrieving information about the IPFS node. ```APIDOC ## Core API - Node Info ### Description Method for retrieving information about the IPFS node. ### Method `client.core.id()` ### Response - `info`: An object containing IPFS node information. ### Request Example ```python info = await client.core.id() ``` ``` -------------------------------- ### Export DAG to CAR Source: https://aioipfs.readthedocs.io Export a DAG to a CAR file or unpack it directly into a directory. ```python from pathlib import Path import aioipfs async with aioipfs.AsyncIPFS() as client: await client.dag.export( 'bafybeiawyahkjt4kzrzc3bjylqupniukbpnbvys7pt536c64gxg7onq36m', output_path=Path('output.car') ) ``` ```python from pathlib import Path import aioipfs async with aioipfs.AsyncIPFS() as client: await client.dag.export_to_directory( 'bafybeiawyahkjt4kzrzc3bjylqupniukbpnbvys7pt536c64gxg7onq36m', Path('car-contents') ) ``` -------------------------------- ### List Pinned Objects Source: https://aioipfs.readthedocs.io Retrieve a list of all CIDs that are currently pinned. ```python pinned = await client.pin.ls() ``` -------------------------------- ### Core API - Cat Source: https://aioipfs.readthedocs.io Method for retrieving the raw data of an IPFS object. ```APIDOC ## Core API - Cat ### Description Method for retrieving the raw data of an IPFS object. ### Method `client.core.cat(cid)` ### Parameters - `cid` (str): The CID of the object. ### Response - `bytes`: The raw data of the object. ### Request Example ```python bytes = await client.core.cat(cid) ``` ``` -------------------------------- ### DAG Export API Source: https://aioipfs.readthedocs.io APIs for exporting DAGs to CAR files or unpacking them to directories. ```APIDOC ## DAG Export API ### Description APIs for exporting DAGs to CAR files or unpacking them to directories. ### Endpoints - `client.dag.export(cid, output_path)`: Exports a DAG to a .car file. - `client.dag.export_to_directory(cid, output_path)`: Exports a UnixFS DAG to a CAR and unpacks it to a directory. ### Request Example: Exporting DAG to CAR file ```python from pathlib import Path import aioipfs async with aioipfs.AsyncIPFS() as client: await client.dag.export( 'bafybeiawyahkjt4kzrzc3bjylqupniukbpnbvys7pt536c64gxg7onq36m', output_path=Path('output.car') ) ``` ### Request Example: Exporting DAG to directory ```python from pathlib import Path import aioipfs async with aioipfs.AsyncIPFS() as client: await client.dag.export_to_directory( 'bafybeiawyahkjt4kzrzc3bjylqupniukbpnbvys7pt536c64gxg7onq36m', Path('car-contents') ) ``` ``` -------------------------------- ### Close Client Connection Source: https://aioipfs.readthedocs.io Explicitly closing the client connection. ```python await client.close() ``` -------------------------------- ### Remove Pin Source: https://aioipfs.readthedocs.io Unpin a specified CID or IPFS path, removing it from the local storage. ```python await client.pin.rm(path) ``` -------------------------------- ### Decode CAR files Source: https://aioipfs.readthedocs.io Use car_bytes to extract raw data from a CAR stream using a specific CID. ```python from pathlib import Path from aioipfs import util data = await util.car_bytes( util.car_open(Path('docs.car')), 'bafybeiawyahkjt4kzrzc3bjylqupniukbpnbvys7pt536c64gxg7onq36m' ) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.