• Stars
    star
    661
  • Rank 68,192 (Top 2 %)
  • Language
    Python
  • License
    MIT License
  • Created about 9 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A python client library for the IPFS API

Under Active Development

py-ipfs-http-client

Made by the IPFS Community IRC #py-ipfs on chat.freenode.net Matrix #py-ipfs:ninetailed.ninja Standard README Compliant PyPI Package ipfshttpclient Build Status

Python IPFS HTTP Client Library

Check out the HTTP Client reference for the full command reference.

Note: The ipfsapi PIP package and Python module have both been renamed to ipfshttpclient! See the relevant section of the CHANGELOG for details. There is also a ipfsApi library from which this library originated that is completely unmaintained and does not work with any recent go-IPFS version.

Note: This library occasionally has to change to stay compatible with the IPFS HTTP API. Currently, this library is tested against go-ipfs v0.8.0. We strive to support the last 5 releases of go-IPFS at any given time; go-IPFS v0.5.0 therefore being to oldest supported version at this time.

Table of Contents

Install

Install with pip:

pip install ipfshttpclient

Development install from Source

# Clone the source repository
git clone https://github.com/ipfs/py-ipfs-http-client.git
cd py-ipfs-http-client

# Link ipfs-api-client into your Python Path
flit install --pth-file

Usage

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

>>> import ipfshttpclient
>>> client = ipfshttpclient.connect()  # Connects to: /dns/localhost/tcp/5001/http
>>> res = client.add('test.txt')
>>> res
{'Hash': 'QmWxS5aNTFEc9XbMX1ASvLET1zrqEaTssqt33rVZQCQb22', 'Name': 'test.txt'}
>>> client.cat(res['Hash'])
'fdsafkljdskafjaksdjf\n'

Please note: You should specify the address for an IPFS API server, using the address of a gateway (such as the public ipfs.io one at /dns/ipfs.io/tcp/443/https) will only give you extremely limited access and may not work at all. If you are only interested in downloading IPFS content through public gateway servers then this library is unlikely of being of much help.

For real-world scripts you can reuse TCP connections using a context manager or manually closing the session after use:

import ipfshttpclient

# Share TCP connections using a context manager
with ipfshttpclient.connect() as client:
	hash = client.add('test.txt')['Hash']
	print(client.stat(hash))

# Share TCP connections until the client session is closed
class SomeObject:
	def __init__(self):
		self._client = ipfshttpclient.connect(session=True)

	def do_something(self):
		hash = self._client.add('test.txt')['Hash']
		print(self._client.stat(hash))

	def close(self):  # Call this when your done
		self._client.close()

Administrative functions:

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

Pass in API options:

>>> client.pin.ls(type='all')
{'Keys': {'QmNMELyizsfFdNZW3yKTi1SE2pErifwDTXx6vvQBfwcJbU': {'Count': 1,
                                                             'Type': 'indirect'},
          'QmNQ1h6o1xJARvYzwmySPsuv9L5XfzS4WTvJSTAWwYRSd8': {'Count': 1,
                                                             'Type': 'indirect'},
          โ€ฆ

Add a directory and match against a filename pattern:

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

Or add a directory recursively:

>>> client.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 and JSON to IPFS:

>>> lst = [1, 77, 'lol']
>>> client.add_json(lst)
'QmQ4R5cCUYBWiJpNL7mFe4LDrwD6qBr5Re17BoRAY9VNpd'
>>> client.get_json(_)
[1, 77, 'lol']

Use an IPFS server with basic auth (replace username and password with real creds):

>>> import ipfshttpclient
>>> client = ipfshttpclient.connect('/dns/ipfs-api.example.com/tcp/443/https', auth=("username", "password"))

Pass custom headers to the IPFS daemon with each request:

>>> import ipfshttpclient
>>> headers = {"CustomHeader": "foobar"}
>>> client = ipfshttpclient.connect('/dns/ipfs-api.example.com/tcp/443/https', headers=headers)

Connect to the IPFS daemon using a Unix domain socket (plain HTTP only):

>>> import ipfshttpclient
>>> client = ipfshttpclient.connect("/unix/run/ipfs/ipfs.sock")

Documentation

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

https://ipfs.io/ipns/12D3KooWEqnTdgqHnkkwarSrJjeMP2ZJiADWLYADaNvUb6SQNyPF/docs/

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

Migrating from 0.4.x to 0.6.0

Please see the CHANGELOG for the minor breaking changes between these releases.

Featured Projects

Projects that currently use py-ipfs-http-client. If your project isn't here, feel free to submit a PR to add it!

Contributing

Easy Tasks

Over time many smaller day-to-day tasks have piled up (mostly supporting some newer APIs). If want to help out without getting too involved picking up one of tasks of our help wanted issue list would go a long way towards making this library more feature-complete. ๐Ÿ‘

Bug reports

You can submit bug reports using the GitHub issue tracker.

Setting up a local development environment

  1. Follow the instructions in the IPFS documentation to install go-IPFS into your ${PATH}:
    https://docs.ipfs.io/install/command-line/
  2. Follow the instructions in the (Python) tox documentation to install the tox Python environment runner:
    https://tox.readthedocs.io/en/latest/install.html
  3. Clone the GIT repository if you haven't already:
    git clone https://github.com/ipfs-shipyard/py-ipfs-http-client.git

If you want to you can also make your local development version of py-ipfs-http-client available to your Python environment by installing flit and running flit install --pth-file from the repository root.

Please see the next section for how to run tests and contribute code back into the project.

Pull requests

Pull requests are welcome. Before submitting a new pull request, please make sure that your code passes both the code formatting (PEP-8 with tab indentation) and typing (PEP-484 using mypy) checks:

$ tox -e styleck -e typeck

As well as the unit tests:

$ tox -e py3 -e py3-httpx

If you are unsure, don't hesitate to just submit your code, and a human will take a look. ๐Ÿ™‚

If you can, Please make sure to include new unit tests for new features or changes in behavior. We aim to bring coverage to 100% at some point.

Installing the pre-commit Hook

You can arrange for the code style and typing tests to be run automatically before each commit by installing the GIT pre-commit hook:

$ ./tools/pre-commit --install

Chat with Us (IRC/Matrix)

You can find us on #py-ipfs on chat.freenode.org or in our Matrix chat room. Join us if you have any suggestions, questions or if you just want to discuss IPFS and Python in general.

Please note that the channel is not monitored all the time and hence you may only receive a reply to your message later that day. Using Matrix makes it easier to stay connected in the background, so please prefer the Matrix option or use an IRC bouncer.

License

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

More Repositories

1

ipfs-deploy

Zero-Config CLI to Deploy Static Websites to IPFS
JavaScript
1,160
star
2

java-ipfs-http-client

A Java implementation of the HTTP IPFS API
Java
537
star
3

py-ipfs

python implementation of ipfs
Python
475
star
4

npm-on-ipfs

๐Ÿ“ฆ Install npm modules through IPFS!
JavaScript
464
star
5

gomobile-ipfs

IPFS and libp2p on Mobile, with Gomobile
Java
318
star
6

ipfs-primer

A primer explaining IPFS and the Decentralized Web, viewable as a website, pdf or e-book
CSS
287
star
7

ipfs-pubsub-room

IPFS Pubsub room
JavaScript
283
star
8

ipscend

๐Ÿš€ Publish all your Web pages to IPFS, track released versions and more!
JavaScript
262
star
9

swift-ipfs-http-client

A Swift client library for the IPFS HTTP API.
Swift
196
star
10

ipfs-share-files

Share files via IPFS
JavaScript
145
star
11

git-remote-ipld

Go
144
star
12

nft-school-examples

JavaScript
143
star
13

is-ipfs

A set of utilities to help identify IPFS resources on the web
TypeScript
126
star
14

shared-editing-demo

Demo of shared text editing using Yjs and IPFS
JavaScript
104
star
15

ipfs-service-worker-demos

[INACTIVE/DEPRECATED] Demo ~2017: run an IPFS node inside a Service Worker and serve all your IPFS URLs directly from IPFS!
JavaScript
84
star
16

ipfs-pack

ipfs-pack filesystem packing tool
Go
72
star
17

ipfs-geoip

geoip lookup over DAG-CBOR dataset loaded from IPFS
JavaScript
70
star
18

IGiS

Interplanetary Git Service
JavaScript
69
star
19

ipfs-github-action

Pin your site to IPFS from a GitHub Action
Shell
68
star
20

pm-idm

IDM project management repository
63
star
21

dnslink-cloudflare

Update dnslink TXT records in Cloudflare
JavaScript
63
star
22

service-worker-gateway-2019-poc

[ARCHIVED] 2019 PoC of IPFS gateway fully running on a Service Worker. For modern (2024+) version see https://github.com/ipfs-shipyard/service-worker-gateway
JavaScript
61
star
23

peer-crdt

Peer CRDT
JavaScript
60
star
24

tevere

๐Ÿž Decentralized DB over IPFS
JavaScript
59
star
25

dnslink-deploy

Set the DNS records on Digital Ocean programmatically
JavaScript
58
star
26

y-ipfs-connector

Y.js connector over IPFS
JavaScript
57
star
27

ipfs-blob-store

An abstract-blob-store compatible implementation built using IPFS as the storage backend
JavaScript
56
star
28

ipfs-pubsub-room-demo

IPFS Pubsub room demo
JavaScript
53
star
29

Durin

Native mobile apps for share actions on iOS and Android
TypeScript
46
star
30

shipyard

Main entry repo for the IPFS Shipyard
45
star
31

container-demos

ipfs container demos
Makefile
44
star
32

discussify-browser-extension

Discussify's browser extension app
JavaScript
40
star
33

ipfs-dns-deploy

A circleci friendly Docker image for pinning things to cluster and updating dns
Shell
38
star
34

net-ipfs-http-client

InterPlanetary File System client for .Net (C#, VB, F# ...)
C#
38
star
35

scala-ipfs-api

A wrapper of the IPFS Client HTTP-API for Scala.
Scala
34
star
36

js-ipfs-http-client-lite

An alternative client library for the IPFS HTTP API, aiming to be as lightweight as possible (<20kB) in the browser.
JavaScript
34
star
37

js-human-crypto-keys

Generate and import human-friendly cryptographic keys using mnemonics, QR codes and other methods
JavaScript
33
star
38

ipfs-provider

Connect to IPFS via an available provider
JavaScript
33
star
39

cube

IPFS Cube will help people deploy and manage their own IPFS pinning services on top of existing cheap hardware, or cloud storage.
Clojure
32
star
40

js-ipfs-level

Leveldown over IPFS
JavaScript
30
star
41

workshop-todo-dapp

A workshop into adding realtime collaboration in a typical To-do app
JavaScript
29
star
42

dataviz

ipfs data visualizations
CoffeeScript
29
star
43

react-native-ipfs-demo

Demo app exploring IPFS in React Native.
JavaScript
29
star
44

ipfs-live-db

Live CRDT DB over IPFS
28
star
45

ipfs-check

A tool for checking the accessibility of your data by IPFS peers
Go
27
star
46

ecosystem-dashboard

A dashboard for monitoring the ecosystem around an open source project.
Ruby
27
star
47

ipfs-npm-OLD

Please refer to https://github.com/ipfs-shipyard/npm-on-ipfs
JavaScript
27
star
48

ipfs-cohost

A CLI to co-host websites published to IPFS
JavaScript
26
star
49

vole

a collection of tools for digging around IPFS nodes
Go
26
star
50

demo-ipfs-id-qr-codes

Generates a QR Code of your IPNS URL and Public Key
HTML
25
star
51

cohosting

A set of light tools and conventions for cohosting public websites and files on IPFS
Shell
25
star
52

ipfs-pubsub-1on1

1-to-1 communication channel over IPFS Pubsub between two peers
JavaScript
25
star
53

ipfs-css

The single-purpose css class names and font-face config to IPFS up your UI.
HTML
24
star
54

ipfs-dag-builder-vis

See how the DAGs get built
JavaScript
24
star
55

rb-pinning-service-api

A rails app that implements the IPFS Pinning Service API
Ruby
23
star
56

i18n

IPFS Translation Project
22
star
57

peer-pad-core

๐Ÿ“ PeerPad core API (no UI)
JavaScript
22
star
58

nopfs

Say NO with NOpfs! NOpfs provides content-blocking-layer capabilities for IPFS (Kubo).
Go
21
star
59

ipfs-senc

Simple tarball encryption
CSS
21
star
60

js-did-ipid

The IPID DID method implementation in JavaScript
JavaScript
21
star
61

peer-crdt-ipfs

peer-crdt network and store over IPFS
JavaScript
20
star
62

net-ipfs-core

C#
19
star
63

ipfs-npm-registry-mirror

Clone the NPM registry into IPFS
JavaScript
19
star
64

apt-on-ipfs

A Docker image that installs ubuntu packages via IPFS
Dockerfile
19
star
65

space

Rust
18
star
66

demo-ipfs-todo

Simple ToDo app using window.ipfs
JavaScript
17
star
67

ipfsx

Experimental IPFS API
JavaScript
17
star
68

pm-discussify

Discussify's project management repository
HTML
17
star
69

package-table

Auto generate a module table in markdown from JSON
JavaScript
16
star
70

integration-mini-projects

Ideas and tracking for small one week "mini projects" that integrate across IPFS
14
star
71

paperhub

Sharing scientific papers using ipfs
JavaScript
14
star
72

pinning-service-compliance

This repo checks the compliance of IPFS Pinning Services against the pinning spec
TypeScript
14
star
73

nomios.io

The https://nomios.io website repository
JavaScript
13
star
74

js-crypto-key-composer

A library to parse crypto keys in different types and formats
JavaScript
12
star
75

go-ipfs-desktop

Go
12
star
76

ipfs-thing-2022

ipfs-รพing-2022
JavaScript
12
star
77

ipfs-iiif-db

IIIF annotations JS client on top of IPFS
JavaScript
12
star
78

react-ipfs-url

Grab a URL from a IPFS path by using URL.createObjectURL
JavaScript
12
star
79

camp-course-c-demo

IPFS Camp 2019 Course C Materials
HTML
11
star
80

ipfs-npm-republish

๐Ÿ“ฆ Republish your node project's dependencies to IPFS as a micro-registry
JavaScript
11
star
81

ipfs-hubot

hubot for ipfs
CoffeeScript
11
star
82

js-idm-wallet

The reference implementation of the IDM Wallet in JavaScript
JavaScript
10
star
83

workshop-idm-chat-dapp

The IDM mini-chat DApp workshop
JavaScript
10
star
84

ipfs-http

A REST and GraphQL interface to IPFS
Go
10
star
85

go-ipfs-docker-examples

Shell
9
star
86

js-pinning-service-http-client

An IPFS Pinning Service HTTP Client for TypeScript / Javascript
TypeScript
9
star
87

DAGger

๐Ÿ—ก๏ธ - an elegant slicer for a more civilized age
Shell
8
star
88

thunderdome

Go
8
star
89

nomios-web-uikit

A collection of shared react components to be used in the Nomios Identity Wallet
JavaScript
8
star
90

ipfs-or-gateway

Download an hash via IPFS, falling back to an HTTP Gateway
JavaScript
8
star
91

w3rc

A Web3 Retrieval Client
Go
8
star
92

dnslink-dnsimple

Update dnslink TXT records in DNSimple
Go
8
star
93

nomios-web

The reference IDM wallet based on web technologies
JavaScript
8
star
94

ipfs-thing-2023

ipfs-รพing-2023
TypeScript
8
star
95

ipfs-pubsub-peer-monitor

Monitor peers joining and leaving an IPFS PubSub topic
JavaScript
8
star
96

someguy

A Delegated Routing V1 server and client for all your routing needs.
Go
7
star
97

js-libp2p-react-native

A demo app running js-libp2p in a React Native app
Java
7
star
98

js-mock-ipfs-pinning-service

Implementation of in-memory IPFS Pinning Service API
JavaScript
7
star
99

js-versidag

Concurrent version history based on a Merkle-DAG
JavaScript
6
star
100

go-dumpotron

Take pprof dumps when a go process eats too much ram or cpu
Go
6
star