Skip to main content

IPFS API Bindings for Python

Project description

image0 image1 image2 standard-readme compliant image4 image5

A python client library for the IPFS API

Check out the client API reference for the full command reference.

Note: This library constantly has to change to stay compatible with the IPFS HTTP API. Currently, this library is tested against go-ipfs v0.4.3rc4. You may experience compatibility issues when attempting to use it with other versions of go-ipfs.

Table of Contents

Install

Install with pip:

pip install ipfsapi

Usage

Basic use-case (requires a running instance of IPFS daemon):

>>> import ipfsapi
>>> api = ipfsapi.connect('127.0.0.1', 5001)
>>> res = api.add('test.txt')
>>> res
{'Hash': 'QmWxS5aNTFEc9XbMX1ASvLET1zrqEaTssqt33rVZQCQb22', 'Name': 'test.txt'}
>>> api.cat(res['Hash'])
'fdsafkljdskafjaksdjf\n'

Administrative functions:

>>> api.id()
{'Addresses': ['/ip4/127.0.0.1/tcp/4001/ipfs/QmS2C4MjZsv2iP1UDMMLCYqJ4WeJw8n3vXx1VKxW1UbqHS',
               '/ip6/::1/tcp/4001/ipfs/QmS2C4MjZsv2iP1UDMMLCYqJ4WeJw8n3vXx1VKxW1UbqHS'],
 'AgentVersion': 'go-ipfs/0.3.8-dev',
 'ID': 'QmS2C4MjZsv2iP1UDMMLCYqJ4WeJw8n3vXx1VKxW1UbqHS',
 'ProtocolVersion': 'ipfs/0.1.0',
 'PublicKey': 'CAASpgIwgg ... 3FcjAgMBAAE='}

Pass in API options:

>>> api.pin_ls(type='all')
{'Keys': {'QmNMELyizsfFdNZW3yKTi1SE2pErifwDTXx6vvQBfwcJbU': {'Count': 1,
                                                             'Type': 'indirect'},
          'QmNQ1h6o1xJARvYzwmySPsuv9L5XfzS4WTvJSTAWwYRSd8': {'Count': 1,
                                                             'Type': 'indirect'},
          

Add a directory and match against a filename pattern:

>>> api.add('photos', match='*.jpg')
[{'Hash': 'QmcqBstfu5AWpXUqbucwimmWdJbu89qqYmE3WXVktvaXhX',
  'Name': 'photos/photo1.jpg'},
 {'Hash': 'QmSbmgg7kYwkSNzGLvWELnw1KthvTAMszN5TNg3XQ799Fu',
  'Name': 'photos/photo2.jpg'},
 {'Hash': 'Qma6K85PJ8dN3qWjxgsDNaMjWjTNy8ygUWXH2kfoq9bVxH',
  'Name': 'photos/photo3.jpg'}]

Or add a directory recursively:

>>> api.add('fake_dir', recursive=True)
[{'Hash': 'QmQcCtMgLVwvMQGu6mvsRYLjwqrZJcYtH4mboM9urWW9vX',
  'Name': 'fake_dir/fsdfgh'},
 {'Hash': 'QmNuvmuFeeWWpxjCQwLkHshr8iqhGLWXFzSGzafBeawTTZ',
  'Name': 'fake_dir/test2/llllg'},
 {'Hash': 'QmX1dd5DtkgoiYRKaPQPTCtXArUu4jEZ62rJBUcd5WhxAZ',
  'Name': 'fake_dir/test2'},
 {'Hash': 'Qmenzb5J4fR9c69BbpbBhPTSp2Snjthu2hKPWGPPJUHb9M',
  'Name': 'fake_dir'}]

This module also contains some helper functions for adding strings, json, and even python objects to IPFS:

>>> lst = [1, 77, 'lol']
>>> api.add_pyobj(lst)
'QmRFqz1ABQtbMBDfjpMubTaginvpVnf58Y87gheRzGfe4i'
>>> api.get_pyobj(_)
[1, 77, 'lol']

Documentation

Documentation (currently mostly API documentation unfortunately) is available on IPFS:

https://ipfs.io/ipns/QmZ86ow1byeyhNRJEatWxGPJKcnQKG7s51MtbHdxxUddTH/Software/Python/ipfsapi/

The ipfs command-line Client documentation may also be useful in some cases.

Contribute

IRC

Join us on IRC at #ipfs on chat.freenode.net if you have any suggestions or questions, or if you just want to discuss IPFS and python.

Bug reports

You can submit bug reports using the GitHub issue tracker.

Pull requests

Pull requests are welcome. Before submitting a new pull request, please make sure that your code passes both the pep8 formatting check:

$ tox -e pep8

And the unit tests:

$ tox

You can arrange to run the pep8 tests automatically before each commit by installing a pre-commit hook:

$ ./tools/pre-commit --install

Please make sure to include new unit tests for new features or changes in behavior.

License

This code is distributed under the terms of the MIT license. Details can be found in the file LICENSE in this repository.

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

ipfsapi-0.4.0.tar.gz (31.8 kB view details)

Uploaded Source

Built Distribution

ipfsapi-0.4.0-py2.py3-none-any.whl (36.4 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file ipfsapi-0.4.0.tar.gz.

File metadata

  • Download URL: ipfsapi-0.4.0.tar.gz
  • Upload date:
  • Size: 31.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for ipfsapi-0.4.0.tar.gz
Algorithm Hash digest
SHA256 83b1c6a8fe45e13e58ecfddc55100b8f777714b349b28f2256bf5bab60d41857
MD5 f266a11ec889898d65af8c5242a448cf
BLAKE2b-256 88a0de1c466478c9535ade8ca5b48f9de59287f244bdfe8dd741c856ce5c1f70

See more details on using hashes here.

Provenance

File details

Details for the file ipfsapi-0.4.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for ipfsapi-0.4.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 21127684b06f9e6d2be5edc5ae3605fc8512090e3d23b6aa12520a3e3e936f54
MD5 a7ee375cbae357953a60c7fa9b7fad48
BLAKE2b-256 6329c741462c5a08999ad8dab38da45c986d7dbd8218b29879b86b9e19228633

See more details on using hashes here.

Provenance

Supported by

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