ibmjstart/py-ipfs-api

Name: py-ipfs-api

Owner: IBM jStart

Description: A python client library for the IPFS API

Forked from: ipfs/py-ipfs-api

Created: 2016-07-22 15:15:52.0

Updated: 2016-07-22 15:15:53.0

Pushed: 2016-08-10 19:39:22.0

Homepage:

Size: 371

Language: Python

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

py-ipfs-api

standard-readme compliant

A python client library for the IPFS API

Check out ipfs and the API command reference for more information about the IPFS API.

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.3rc2. You may experience compatibility issues when attempting to use it with other versions of go-ipfs.

Table of Contents
Install

Install with pip:

install ipfs-api
Usage

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

import ipfsApi
api = ipfsApi.Client('127.0.0.1', 5001)
res = api.add('test.txt')
res
sh': 'QmWxS5aNTFEc9XbMX1ASvLET1zrqEaTssqt33rVZQCQb22', 'Name': 'test.txt'}
api.cat(res['Hash'])
afkljdskafjaksdjf\n'

Administrative functions:

api.id()
dresses': ['/ip4/127.0.0.1/tcp/4001/ipfs/QmS2C4MjZsv2iP1UDMMLCYqJ4WeJw8n3vXx1VKxW1UbqHS',
           '/ip6/::1/tcp/4001/ipfs/QmS2C4MjZsv2iP1UDMMLCYqJ4WeJw8n3vXx1VKxW1UbqHS'],
entVersion': 'go-ipfs/0.3.8-dev',
': 'QmS2C4MjZsv2iP1UDMMLCYqJ4WeJw8n3vXx1VKxW1UbqHS',
otocolVersion': 'ipfs/0.1.0',
blicKey': 'CAASpgIwgg ... 3FcjAgMBAAE='}

Pass in API options:

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

Add a directory and match against a filename pattern:

api.add('photos', match='*.jpg')
ash': 'QmcqBstfu5AWpXUqbucwimmWdJbu89qqYmE3WXVktvaXhX',
ame': 'photos/photo1.jpg'},
ash': 'QmSbmgg7kYwkSNzGLvWELnw1KthvTAMszN5TNg3XQ799Fu',
ame': 'photos/photo2.jpg'},
ash': 'Qma6K85PJ8dN3qWjxgsDNaMjWjTNy8ygUWXH2kfoq9bVxH',
ame': 'photos/photo3.jpg'}]

Or add a directory recursively:

api.add('fake_dir', recursive=True)
ash': 'QmQcCtMgLVwvMQGu6mvsRYLjwqrZJcYtH4mboM9urWW9vX',
ame': 'fake_dir/fsdfgh'},
ash': 'QmNuvmuFeeWWpxjCQwLkHshr8iqhGLWXFzSGzafBeawTTZ',
ame': 'fake_dir/test2/llllg'},
ash': 'QmX1dd5DtkgoiYRKaPQPTCtXArUu4jEZ62rJBUcd5WhxAZ',
ame': 'fake_dir/test2'},
ash': 'Qmenzb5J4fR9c69BbpbBhPTSp2Snjthu2hKPWGPPJUHb9M',
ame': '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)
Fqz1ABQtbMBDfjpMubTaginvpVnf58Y87gheRzGfe4i'
api.get_pyobj(_)
77, 'lol']
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.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.