• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

pinnaculum/aioipfs: Asynchronous python3 IPFS client library

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

pinnaculum/aioipfs

开源软件地址:

https://github.com/pinnaculum/aioipfs

开源编程语言:

Python 100.0%

开源软件介绍:

aioipfs

info:Asynchronous IPFS client library

aioipfs is a python3 library providing an asynchronous API for IPFS. Supported python versions: 3.6, 3.7, 3.8, 3.9

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.




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap