IPFS API Bindings for Python
Project description
IPFS API Bindings for Python
Check out ipfs and the api command reference for more information about the IPFS Api.
Install with pip:
pip install ipfs-api
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
{'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(opts={'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']
How to 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.txt in this repository.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file ipfs-api-0.2.3.tar.gz
.
File metadata
- Download URL: ipfs-api-0.2.3.tar.gz
- Upload date:
- Size: 13.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 709b2b61c53c6682e7188733ea8399bdc125da1dac1d6f9ff371aa1a3d00c38a |
|
MD5 | 13ebadb837d0ceb069cf79c00051e8ee |
|
BLAKE2b-256 | 78482255573a91afd063e73cf6800fa0dda16c7e13988506ce83f2108c9ce26a |