Name | aioipfs JSON |
Version |
0.7.1
JSON |
| download |
home_page | None |
Summary | Asynchronous IPFS client library |
upload_time | 2024-04-19 08:44:18 |
maintainer | None |
docs_url | None |
author | None |
requires_python | None |
license | LGPLv3 |
keywords |
asyncio
aiohttp
ipfs
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
=======
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*, *3.10*, *3.11*, *3.12*.
This library supports the
`RPC API specifications <https://docs.ipfs.tech/reference/kubo/rpc>`_
for kubo_ version *0.28.0*. Unit tests are run against
most major go-ipfs releases and all kubo_
releases, see the *CI* section below.
See the documentation `here <https://aioipfs.readthedocs.io/en/latest>`_.
.. image:: https://gitlab.com/cipres/aioipfs/badges/master/coverage.svg
Installation
============
.. code-block:: shell
pip install aioipfs
To install the requirements for `bohort <https://aioipfs.readthedocs.io/en/latest/bohort.html>`_, a REPL tool for making RPC calls on kubo nodes:
.. code-block:: shell
pip install 'aioipfs[bohort]'
Support for CAR (Content-Addressable Archives) decoding (with the
`ipfs-car-decoder package <https://github.com/kralverde/py-ipfs-car-decoder/>`_)
can be enabled with the *car* extra:
.. code-block:: shell
pip install 'aioipfs[car]'
By default the *json* module from the standard Python library is used
to decode JSON messages, but orjson_ will be used if it is installed:
.. code-block:: shell
pip install 'aioipfs[orjson]'
Usage
=====
Client instantiation
--------------------
The recommended way to specify the kubo node's RPC API address is
to pass a multiaddr_.
.. code-block:: python
client = aioipfs.AsyncIPFS(maddr='/ip4/127.0.0.1/tcp/5001')
client = aioipfs.AsyncIPFS(maddr='/dns4/localhost/tcp/5001')
You can also pass a *multiaddr.Multiaddr* instance.
.. code-block:: python
from multiaddr import Multiaddr
client = aioipfs.AsyncIPFS(maddr=Multiaddr('/ip4/127.0.0.1/tcp/5001'))
Otherwise just pass *host* and *port* separately:
.. code-block:: python
client = aioipfs.AsyncIPFS(host='localhost', port=5001)
client = aioipfs.AsyncIPFS(host='::1', port=5201)
If the kubo server requires authentication, you can pass the RPC authentication
credentials via the constructor's *auth* keyword argument:
.. code-block:: python
client = aioipfs.AsyncIPFS(auth=aioipfs.BasicAuth('john', 'password123'))
client = aioipfs.AsyncIPFS(auth=aioipfs.BearerAuth('my-secret-token'))
Get an IPFS resource
--------------------
.. code-block:: python
import sys
import asyncio
import aioipfs
async def get(cid: str):
client = aioipfs.AsyncIPFS()
await client.get(cid, dstdir='.')
await client.close()
loop = asyncio.get_event_loop()
loop.run_until_complete(get(sys.argv[1]))
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 should be used with the *async for* syntax.
.. code-block:: python
import sys
import asyncio
import aioipfs
async def add_files(files: list):
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:]))
You can also use the async list generator syntax:
.. code-block:: python
cids = [entry['Hash'] async for entry in client.add(dir_path)]
Pubsub service
--------------
.. code-block:: python
async def pubsub_serve(topic: str):
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'])
Dialing a P2P service
---------------------
.. code-block:: python
async with aioipfs.AsyncIPFS() as client:
async with client.p2p.dial_service(peer_id, '/x/echo') as dial:
print(f'Dial host: {dial.maddr_host}, port: {dial.maddr_port}')
# Connect to the service now
....
CI
==
The Gitlab CI workflow runs unit tests against the following
go-ipfs/kubo releases (`go here <https://gitlab.com/cipres/aioipfs/-/jobs>`_
for the CI jobs overview).
- go-ipfs >=0.11.0,<=0.13.0
- kubo >=0.14.0,<=0.28.0
.. image:: https://github.com/pinnaculum/aioipfs/workflows/aioipfs-build/badge.svg
:target: https://github.com/pinnaculum/aioipfs/actions
.. image:: https://gitlab.com/cipres/aioipfs/badges/master/pipeline.svg
:target: https://gitlab.com/cipres/aioipfs/-/jobs
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
============
- Python >= 3.6, <= 3.12
- aiohttp_
- aiofiles_
- py-multibase_
- yarl_
.. _aiohttp: https://pypi.python.org/pypi/aiohttp
.. _aiofiles: https://pypi.python.org/pypi/aiofiles
.. _multiaddr: https://multiformats.io/multiaddr/
.. _py-multibase: https://pypi.python.org/pypi/py-multibase
.. _yarl: https://pypi.python.org/pypi/yarl
.. _IPFS: https://ipfs.io
.. _kubo: https://github.com/ipfs/kubo
.. _orjson: https://github.com/ijl/orjson
License
=======
**aioipfs** is offered under the GNU Lesser GPL3 (LGPL3) license.
Raw data
{
"_id": null,
"home_page": null,
"name": "aioipfs",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": "asyncio, aiohttp, ipfs",
"author": null,
"author_email": "cipres <alkaline@gmx.co.uk>",
"download_url": "https://files.pythonhosted.org/packages/e5/c8/25cea79e0ec17ee11f664dbdca36a82197ad5e9c64a7242846c49a6a2e45/aioipfs-0.7.1.tar.gz",
"platform": null,
"description": "=======\naioipfs\n=======\n\n:info: Asynchronous IPFS_ client library\n\n**aioipfs** is a python3 library providing an asynchronous API for IPFS_.\nSupported python versions: *3.6*, *3.7*, *3.8*, *3.9*, *3.10*, *3.11*, *3.12*.\n\nThis library supports the\n`RPC API specifications <https://docs.ipfs.tech/reference/kubo/rpc>`_\nfor kubo_ version *0.28.0*. Unit tests are run against\nmost major go-ipfs releases and all kubo_\nreleases, see the *CI* section below.\n\nSee the documentation `here <https://aioipfs.readthedocs.io/en/latest>`_.\n\n.. image:: https://gitlab.com/cipres/aioipfs/badges/master/coverage.svg\n\nInstallation\n============\n\n.. code-block:: shell\n\n pip install aioipfs\n\nTo install the requirements for `bohort <https://aioipfs.readthedocs.io/en/latest/bohort.html>`_, a REPL tool for making RPC calls on kubo nodes:\n\n.. code-block:: shell\n\n pip install 'aioipfs[bohort]'\n\nSupport for CAR (Content-Addressable Archives) decoding (with the\n`ipfs-car-decoder package <https://github.com/kralverde/py-ipfs-car-decoder/>`_)\ncan be enabled with the *car* extra:\n\n.. code-block:: shell\n\n pip install 'aioipfs[car]'\n\nBy default the *json* module from the standard Python library is used\nto decode JSON messages, but orjson_ will be used if it is installed:\n\n.. code-block:: shell\n\n pip install 'aioipfs[orjson]'\n\nUsage\n=====\n\nClient instantiation\n--------------------\n\nThe recommended way to specify the kubo node's RPC API address is\nto pass a multiaddr_.\n\n.. code-block:: python\n\n client = aioipfs.AsyncIPFS(maddr='/ip4/127.0.0.1/tcp/5001')\n\n client = aioipfs.AsyncIPFS(maddr='/dns4/localhost/tcp/5001')\n\nYou can also pass a *multiaddr.Multiaddr* instance.\n\n.. code-block:: python\n\n from multiaddr import Multiaddr\n\n client = aioipfs.AsyncIPFS(maddr=Multiaddr('/ip4/127.0.0.1/tcp/5001'))\n\nOtherwise just pass *host* and *port* separately:\n\n.. code-block:: python\n\n client = aioipfs.AsyncIPFS(host='localhost', port=5001)\n\n client = aioipfs.AsyncIPFS(host='::1', port=5201)\n\nIf the kubo server requires authentication, you can pass the RPC authentication\ncredentials via the constructor's *auth* keyword argument:\n\n.. code-block:: python\n\n client = aioipfs.AsyncIPFS(auth=aioipfs.BasicAuth('john', 'password123'))\n\n client = aioipfs.AsyncIPFS(auth=aioipfs.BearerAuth('my-secret-token'))\n\nGet an IPFS resource\n--------------------\n\n.. code-block:: python\n\n import sys\n import asyncio\n\n import aioipfs\n\n async def get(cid: str):\n client = aioipfs.AsyncIPFS()\n\n await client.get(cid, dstdir='.')\n await client.close()\n\n loop = asyncio.get_event_loop()\n loop.run_until_complete(get(sys.argv[1]))\n\nAdd some files\n--------------\n\nThis example will import all files and directories specified on the command\nline. Note that the **add** API function is an asynchronous generator and\ntherefore should be used with the *async for* syntax.\n\n.. code-block:: python\n\n import sys\n import asyncio\n\n import aioipfs\n\n async def add_files(files: list):\n client = aioipfs.AsyncIPFS()\n\n async for added_file in client.add(*files, recursive=True):\n print('Imported file {0}, CID: {1}'.format(\n added_file['Name'], added_file['Hash']))\n\n await client.close()\n\n loop = asyncio.get_event_loop()\n loop.run_until_complete(add_files(sys.argv[1:]))\n\nYou can also use the async list generator syntax:\n\n.. code-block:: python\n\n cids = [entry['Hash'] async for entry in client.add(dir_path)]\n\nPubsub service\n--------------\n\n.. code-block:: python\n\n async def pubsub_serve(topic: str):\n async with aioipfs.AsyncIPFS() as cli:\n async for message in cli.pubsub.sub(topic):\n print('Received message from', message['from'])\n\n await cli.pubsub.pub(topic, message['data'])\n\n\nDialing a P2P service\n---------------------\n\n.. code-block:: python\n\n async with aioipfs.AsyncIPFS() as client:\n async with client.p2p.dial_service(peer_id, '/x/echo') as dial:\n print(f'Dial host: {dial.maddr_host}, port: {dial.maddr_port}')\n\n # Connect to the service now\n ....\n\nCI\n==\n\nThe Gitlab CI workflow runs unit tests against the following\ngo-ipfs/kubo releases (`go here <https://gitlab.com/cipres/aioipfs/-/jobs>`_\nfor the CI jobs overview).\n\n- go-ipfs >=0.11.0,<=0.13.0\n- kubo >=0.14.0,<=0.28.0\n\n.. image:: https://github.com/pinnaculum/aioipfs/workflows/aioipfs-build/badge.svg\n :target: https://github.com/pinnaculum/aioipfs/actions\n\n.. image:: https://gitlab.com/cipres/aioipfs/badges/master/pipeline.svg\n :target: https://gitlab.com/cipres/aioipfs/-/jobs\n\nFeatures\n========\n\nAsync file writing on get operations\n------------------------------------\n\nThe **aiofiles** library is used to asynchronously write data retrieved from\nthe IPFS daemon when using the */api/v0/get* API call, to avoid blocking the\nevent loop. TAR extraction is done in asyncio's threadpool.\n\nRequirements\n============\n\n- Python >= 3.6, <= 3.12\n- aiohttp_\n- aiofiles_\n- py-multibase_\n- yarl_\n\n.. _aiohttp: https://pypi.python.org/pypi/aiohttp\n.. _aiofiles: https://pypi.python.org/pypi/aiofiles\n.. _multiaddr: https://multiformats.io/multiaddr/\n.. _py-multibase: https://pypi.python.org/pypi/py-multibase\n.. _yarl: https://pypi.python.org/pypi/yarl\n.. _IPFS: https://ipfs.io\n.. _kubo: https://github.com/ipfs/kubo\n.. _orjson: https://github.com/ijl/orjson\n\nLicense\n=======\n\n**aioipfs** is offered under the GNU Lesser GPL3 (LGPL3) license.\n",
"bugtrack_url": null,
"license": "LGPLv3",
"summary": "Asynchronous IPFS client library",
"version": "0.7.1",
"project_urls": {
"Homepage": "https://gitlab.com/cipres/aioipfs"
},
"split_keywords": [
"asyncio",
" aiohttp",
" ipfs"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "1f9c58177dae5dc22ec8e01a48fbd5057a7be2b2a5a8c5206eb29c762644cec3",
"md5": "86916b2f496a717f4451de0250baaf73",
"sha256": "be0834ef413b2f853c02c202f037950ebead57fb48ed6a73842ae97d3f36e69b"
},
"downloads": -1,
"filename": "aioipfs-0.7.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "86916b2f496a717f4451de0250baaf73",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 45758,
"upload_time": "2024-04-19T08:44:16",
"upload_time_iso_8601": "2024-04-19T08:44:16.416822Z",
"url": "https://files.pythonhosted.org/packages/1f/9c/58177dae5dc22ec8e01a48fbd5057a7be2b2a5a8c5206eb29c762644cec3/aioipfs-0.7.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "e5c825cea79e0ec17ee11f664dbdca36a82197ad5e9c64a7242846c49a6a2e45",
"md5": "af7d95fb44637a0f133401b301c1ed33",
"sha256": "3f9e883344f764c357836d8d25f466bbe1212c51798b03522f31e1d143155fa0"
},
"downloads": -1,
"filename": "aioipfs-0.7.1.tar.gz",
"has_sig": false,
"md5_digest": "af7d95fb44637a0f133401b301c1ed33",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 49705,
"upload_time": "2024-04-19T08:44:18",
"upload_time_iso_8601": "2024-04-19T08:44:18.108305Z",
"url": "https://files.pythonhosted.org/packages/e5/c8/25cea79e0ec17ee11f664dbdca36a82197ad5e9c64a7242846c49a6a2e45/aioipfs-0.7.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-04-19 08:44:18",
"github": false,
"gitlab": true,
"bitbucket": false,
"codeberg": false,
"gitlab_user": "cipres",
"gitlab_project": "aioipfs",
"lcname": "aioipfs"
}