Skip to main content

A python library by Algovera to interact with IPFS and IPFS ecosystem such as the common pinning services

Project description

Welcome to IPFSPy by Algovera

What is IPFSPy?

IPFSPy is a python library by Algovera to interact with IPFS and IPFS ecosystem such as the common pinning services. It is designed by data scientists for data scientists to interact with the IPFS ecosystem without leaving the comfort of python and jupyter notebook.

You can learn more about IPFS here.

IPFS is built using the go-lang or javascript. With IPFSPy, you can interact with IPFS using the exposed HTTP RPC API.

Ipfspy has two different implementations to interact with IPFS

  1. Access to most of what HTTP RPC API through ipfspy.ipfshttpapi

    With ipfspy.ipfshttpapi, you can either use local, infura or public nodes. In order to use local node, you will need a IPFS deamon running in the form of IPFS Desktop, IPFS Campanion or IPFS CLI. As an alternative, you can connect via the Infura’s dedicated IPFS gateway.

  2. fsspec-like implementation through ipfspy.ipfspec

    What is ipfsspec?

    ipfsspec is the fsspec-like implementation for IPFS. Through ipfspy.ipfsspec, you get access to both local and infura nodes but the public node is read-only. Local node offers both read and write. In order to use local node, you will need a local node running locally through IPFS Desktop or IPFS Companion or the IPFS CLI.

    Advantages of fsspec-like implementations

    • many data science libraries like dask, pandas and xarray uses fsspec for path and file handling
    • provides an uniform APIs

    Since many data science use fsspec, by implementing ipfsspec, fsspec supports IPFS.

Installing

You can install the library simply through

pip install ipfspy

If you plan to contribute to this library, 1. clone the repo locally git clone https://github.com/algoveraai/ipfspy

  1. Install an editable version of the repo pip install -e .[dev]

  2. submit PR

How to use

ipfshttpapi

Extend the IPFSApi

api = IPFSApi()
Changed to local node

Change to other nodes like below. You can choose one of local infura or public

api.change_gateway_type = 'infura'
Changed to infura node
api.change_gateway_type = 'local'
Changed to local node

To add a file to IPFS,

res, obj = api.add_items('output/test.txt'); obj
[{'Name': 'test.txt', 'Bytes': 20},
 {'Name': 'test.txt',
  'Hash': 'QmbwFKzLj9m2qwBFYTVrBotf4QujvzTb1GBV9wFcNPMctm',
  'Size': '28'}]

To retrieve a file from IPFS

response, content = api.cat_items(cid='QmbwFKzLj9m2qwBFYTVrBotf4QujvzTb1GBV9wFcNPMctm'); content
"\n'''\nFirst file\n'''\n"

ipfsspec

import fsspec, io, os, asyncio
from ipfspy.ipfsspec.asyn import AsyncIPFSFileSystem
from fsspec import register_implementation

Register the ipfsspec to fsspec

register_implementation(AsyncIPFSFileSystem.protocol, AsyncIPFSFileSystem)
class fs:
    ipfs = fsspec.filesystem("ipfs")
    file = fsspec.filesystem("file")
Changed to local node

Like ipfspy.ipfshttpapi, you can change the node as such

fs.ipfs.change_gateway_type = 'public'
Changed to public node
fs.ipfs.change_gateway_type = 'local'
Changed to local node

Add a file to IPFS using fsspec-like api

put_file_res = fs.ipfs.put(path='output/test.txt', rpath='/test_put_file'); put_file_res
'QmbwFKzLj9m2qwBFYTVrBotf4QujvzTb1GBV9wFcNPMctm'

Retrieve a file from IPFs using fsspec-like api

fs.ipfs.cat('QmbwFKzLj9m2qwBFYTVrBotf4QujvzTb1GBV9wFcNPMctm')
b"\n'''\nFirst file\n'''\n"

Project details


Download files

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

Source Distribution

ipfspy-0.0.15.tar.gz (35.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ipfspy-0.0.15-py3-none-any.whl (35.6 kB view details)

Uploaded Python 3

File details

Details for the file ipfspy-0.0.15.tar.gz.

File metadata

  • Download URL: ipfspy-0.0.15.tar.gz
  • Upload date:
  • Size: 35.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.12

File hashes

Hashes for ipfspy-0.0.15.tar.gz
Algorithm Hash digest
SHA256 7263861d60352e4e68c3f43e74b7a1aab2586aef6d1ec09699488aac67fc303d
MD5 22fc32bcda2e2aaf9d56067110cd4827
BLAKE2b-256 f2945cd785be11989b48d414ce73f33ce436f00d3a4b14f0d52c035c33619956

See more details on using hashes here.

File details

Details for the file ipfspy-0.0.15-py3-none-any.whl.

File metadata

  • Download URL: ipfspy-0.0.15-py3-none-any.whl
  • Upload date:
  • Size: 35.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.12

File hashes

Hashes for ipfspy-0.0.15-py3-none-any.whl
Algorithm Hash digest
SHA256 11358e5d615a397c188453561b8b5270b6b1b2bee5c100f213597d55ba939de8
MD5 088654b96eed52839bbeebbab4482dc3
BLAKE2b-256 f6f2e64803afa3cdcf2676e7a33f434b79b32a992ef1b2a5dd3f31358c4fd68c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page