Skip to main content

Asynchronous IPFS client library

Project description

info:Asynchronous IPFS client library

aioipfs is a python3 library providing an asynchronous API for IPFS,

Installation

pip install aioipfs

Usage examples

Get an IPFS resource

import sys
import asyncio

import aioipfs

async def get(ipfshash):
    client = aioipfs.AsyncIPFS()
    await client.get(ipfshash, dstdir='.')
    await client.close()

loop = asyncio.get_event_loop()
loop.run_until_complete(get(sys.argv[1]))
loop.close()

Add some files

This example will import all files and directories specified on the command line. Note that the add API function is an asynchronous generator and therefore needs to be used with the async for syntax.

import sys
import asyncio

import aioipfs

async def add_files(files):
    client = aioipfs.AsyncIPFS()

    async for added_file in client.add(*files, recursive=True):
        print('Imported file {0}, CID: {1}'.format(
            added_file['Name'], added_file['Hash']))

    await client.close()

loop = asyncio.get_event_loop()
loop.run_until_complete(add_files(sys.argv[1:]))
loop.close()

Pubsub service

async def pubsub_serve(topic):
    async with aioipfs.AsyncIPFS() as cli:
        async for message in cli.pubsub.sub(topic):
            print('Received message from', message['from'])
            await cli.pubsub.pub(topic, message['data'])

Features

Async file writing on get operations

The aiofiles library is used to asynchronously write data retrieved from the IPFS daemon when using the /api/v0/get API call, to avoid blocking the event loop. TAR extraction is done in asyncio’s threadpool.

Requirements

License

aioipfs is offered under the GNU Lesser GPL3 (LGPL3) license.

Author

David Ferlier

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
aioipfs-0.4.1-py3-none-any.whl (17.7 kB) Copy SHA256 hash SHA256 Wheel py3
aioipfs-0.4.1.tar.gz (21.2 kB) Copy SHA256 hash SHA256 Source None

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page