Skip to content

Commit f81537a

Browse files
committed
Improve many things about the documentation
* Better signature for the `connect` function (fixes ipfs-shipyard#150) * Document the `stream` parameter * Return values are now *documented*, not *commented* on (syntactial change) * Document the JSON object keys of several methods separately
1 parent 01c8b29 commit f81537a

18 files changed

+334
-127
lines changed

docs/conf.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464

6565
# General information about the project.
6666
project = 'Python IPFS HTTP Client'
67-
copyright = '2016, py-ipfs-http-client team'
67+
copyright = '2019, py-ipfs-http-client team'
6868
author = 'py-ipfs-http-client team'
6969

7070
# The version info for the project you're documenting, acts as replacement for
@@ -313,7 +313,8 @@
313313

314314
# External documentation link mapping
315315
intersphinx_mapping = {
316-
'python': ('https://docs.python.org/3', None)
316+
'python': ('https://docs.python.org/3', None),
317+
'cid': ('https://py-cid.readthedocs.io/en/master/', None)
317318
}
318319

319320
# -- Napoleon settings ----------------------------------------------------

docs/http_client_ref.md

+39-6
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,52 @@ All commands are accessed through the ``ipfshttpclient.Client`` class.
1111
```
1212

1313

14+
### Utility Functions
1415

15-
### The HTTP Client
16+
```eval_rst
17+
.. data:: ipfshttpclient.DEFAULT_HOST
1618
17-
All methods accept the following parameters in their ``kwargs``:
19+
The default hostname that the client library will attempt to connect to.
20+
This may be overwritten on a per-client-instance basis using the ``host``
21+
parameter of the :func:`~ipfshttpclient.connect` function.
1822
19-
* **opts** (*dict*) – A dictionary of custom parameters to be sent with the
20-
HTTP request
23+
.. data:: ipfshttpclient.DEFAULT_PORT
2124
22-
```eval_rst
23-
.. autofunction:: ipfshttpclient.connect
25+
The default port number that the client library will attempt to connect to.
26+
This may be overwritten on a per-client-instance basis using the ``port``
27+
parameter of the :func:`~ipfshttpclient.connect` function.
28+
29+
.. data:: ipfshttpclient.DEFAULT_BASE
30+
31+
The default HTTP URL prefix (or “base”) that the client library will use.
32+
This may be overwritten on a per-client-instance basis using the ``base``
33+
parameter of the :func:`~ipfshttpclient.connect` function.
34+
35+
.. autofunction:: ipfshttpclient.connect(host=DEFAULT_HOST, port=DEFAULT_PORT, base=DEFAULT_BASE)
2436
2537
.. autofunction:: ipfshttpclient.assert_version
2638
39+
```
40+
41+
### The API Client
42+
43+
All methods accept the following parameters in their `kwargs`:
44+
45+
* **opts** (*dict*) – A mapping of custom IPFS API parameters to be sent along
46+
with the regular parameters generated by the client
47+
library
48+
* Values specified here will always override their respective counterparts
49+
of the client library itself.
50+
* **stream** (*bool*) – Return results incrementally as they arrive?
51+
* Each method called with `stream=True` will return a generator instead
52+
of the documented value. If the return type is of type `list` then each
53+
item of the given list will be yielded separately; if it is of type
54+
`bytes` then arbitrary bags of bytes will be yielded that together form
55+
a stream; finally, if it is of type `dict` then the single dictonary item
56+
will be yielded once.
57+
58+
```eval_rst
59+
2760
.. autoclientclass:: ipfshttpclient.Client
2861
:members:
2962
:inherited-members:

ipfshttpclient/client/__init__.py

+23-9
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ def assert_version(version, minimum=VERSION_MINIMUM, maximum=VERSION_MAXIMUM):
4949
Parameters
5050
----------
5151
version : str
52-
The version of an IPFS daemon.
52+
The actual version of an IPFS daemon
5353
minimum : str
54-
The minimal IPFS version to allow.
54+
The minimal IPFS daemon version to allowed
5555
maximum : str
56-
The maximum IPFS version to allow.
56+
The maximum IPFS daemon version to allowed
5757
"""
5858
# Convert version strings to integer tuples
5959
version = list(map(int, version.split('-', 1)[0].split('.')))
@@ -84,7 +84,7 @@ def connect(host=DEFAULT_HOST, port=DEFAULT_PORT, base=DEFAULT_BASE,
8484
8585
Returns
8686
-------
87-
~ipfshttpclient.Client
87+
:class:`~ipfshttpclient.Client`
8888
"""
8989
# Create client instance
9090
client = Client(host, port, base, chunk_size, **defaults)
@@ -96,6 +96,16 @@ def connect(host=DEFAULT_HOST, port=DEFAULT_PORT, base=DEFAULT_BASE,
9696

9797

9898
class Client(files.Base, miscellaneous.Base):
99+
"""The main IPFS HTTP client class
100+
101+
Allows access to an IPFS daemon instance using its HTTP API by exposing an
102+
`IPFS Interface Core <https://github.com/ipfs/interface-ipfs-core/tree/master/SPEC>`__
103+
compatible set of methods.
104+
105+
It is possible to instantiate this class directly, using the same parameters
106+
as :func:`connect`, to prevent the client from checking for an active and
107+
compatible version of the daemon.
108+
"""
99109
bitswap = base.SectionProperty(bitswap.Section)
100110
block = base.SectionProperty(block.Section)
101111
bootstrap = base.SectionProperty(bootstrap.Section)
@@ -134,7 +144,8 @@ def add_bytes(self, data, **kwargs):
134144
135145
Returns
136146
-------
137-
str : Hash of the added IPFS object
147+
str
148+
Hash of the added IPFS object
138149
"""
139150
body, headers = multipart.stream_bytes(data, self.chunk_size)
140151
return self._client.request('/add', decoder='json',
@@ -159,7 +170,8 @@ def add_str(self, string, **kwargs):
159170
160171
Returns
161172
-------
162-
str : Hash of the added IPFS object
173+
str
174+
Hash of the added IPFS object
163175
"""
164176
body, headers = multipart.stream_text(string, self.chunk_size)
165177
return self._client.request('/add', decoder='json',
@@ -180,7 +192,8 @@ def add_json(self, json_obj, **kwargs):
180192
181193
Returns
182194
-------
183-
str : Hash of the added IPFS object
195+
str
196+
Hash of the added IPFS object
184197
"""
185198
return self.add_bytes(encoding.Json().encode(json_obj), **kwargs)
186199

@@ -196,11 +209,12 @@ def get_json(self, cid, **kwargs):
196209
197210
Parameters
198211
----------
199-
cid : Union[str, cid.BaseCID]
212+
cid : Union[str, cid.CIDv0, cid.CIDv1]
200213
CID of the IPFS object to load
201214
202215
Returns
203216
-------
204-
object : Deserialized IPFS JSON object value
217+
object
218+
Deserialized IPFS JSON object value
205219
"""
206220
return self.cat(cid, decoder='json', **kwargs)

ipfshttpclient/client/bitswap.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ def wantlist(self, peer=None, **kwargs):
2525
2626
Returns
2727
-------
28-
dict : List of wanted blocks
28+
dict
29+
30+
+------+----------------------------------------------------+
31+
| Keys | List of blocks the connected daemon is looking for |
32+
+------+----------------------------------------------------+
2933
"""
3034
args = (peer,)
3135
return self._client.request('/bitswap/wantlist', args, decoder='json', **kwargs)
@@ -57,6 +61,7 @@ def stat(self, **kwargs):
5761
5862
Returns
5963
-------
60-
dict : Statistics, peers and wanted blocks
64+
dict
65+
Statistics, peers and wanted blocks
6166
"""
6267
return self._client.request('/bitswap/stat', decoder='json', **kwargs)

ipfshttpclient/client/block.py

+12-9
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,13 @@ def get(self, cid, **kwargs):
2121
2222
Parameters
2323
----------
24-
cid : Union[str, cid.BaseCID]
25-
The base58 CID of an existing block to get
24+
cid : Union[str, cid.CIDv0, cid.CIDv1]
25+
The CID of an existing block to get
2626
2727
Returns
2828
-------
29-
bytes : Value of the requested block
29+
bytes
30+
Contents of the requested block
3031
"""
3132
args = (str(cid),)
3233
return self._client.request('/block/get', args, **kwargs)
@@ -49,9 +50,10 @@ def put(self, file, **kwargs):
4950
5051
Returns
5152
-------
52-
dict : Information about the new block
53-
54-
See :meth:`~ipfshttpclient.Client.block.stat`
53+
dict
54+
Information about the new block
55+
56+
See :meth:`~ipfshttpclient.Client.block.stat`
5557
"""
5658
body, headers = multipart.stream_files(file, self.chunk_size)
5759
return self._client.request('/block/put', decoder='json', data=body,
@@ -70,12 +72,13 @@ def stat(self, cid, **kwargs):
7072
7173
Parameters
7274
----------
73-
cid : Union[str, cid.BaseCID]
74-
The base58 CID of an existing block to stat
75+
cid : Union[str, cid.CIDv0, cid.CIDv1]
76+
The CID of an existing block to stat
7577
7678
Returns
7779
-------
78-
dict : Information about the requested block
80+
dict
81+
Information about the requested block
7982
"""
8083
args = (str(cid),)
8184
return self._client.request('/block/stat', args, decoder='json', **kwargs)

ipfshttpclient/client/bootstrap.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,16 @@ def list(self, **kwargs):
3737
'/ip4/104.236.176.52/tcp/4001/ipfs/QmSoLnSGccFuZQJzRa … ca9z',
3838
'/ip4/104.236.179.241/tcp/4001/ipfs/QmSoLPppuBtQSGwKD … KrGM',
3939
40-
'/ip4/178.62.61.185/tcp/4001/ipfs/QmSoLMeWqB7YGVLJN3p … QBU3']}
40+
'/ip4/178.62.61.185/tcp/4001/ipfs/QmSoLMeWqB7YGVLJN3p … QBU3'
41+
]}
4142
4243
Returns
4344
-------
44-
dict : List of known bootstrap peers
45+
dict
46+
47+
+-------+-------------------------------+
48+
| Peers | List of known bootstrap peers |
49+
+-------+-------------------------------+
4550
"""
4651
return self._client.request('/bootstrap', decoder='json', **kwargs)
4752

ipfshttpclient/client/config.py

+14-12
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,6 @@ def get(self, **kwargs):
1010
#TODO: Support the optional `key` parameter
1111
"""Returns the current used server configuration.
1212
13-
.. warning::
14-
15-
The configuration file contains private key data that must be
16-
handled with care.
17-
1813
.. code-block:: python
1914
2015
>>> config = client.config.get()
@@ -27,30 +22,31 @@ def get(self, **kwargs):
2722
2823
Returns
2924
-------
30-
dict : The entire IPFS daemon configuration
25+
dict
26+
The entire IPFS daemon configuration
3127
"""
3228
return self._client.request('/config/show', decoder='json', **kwargs)
3329

3430

3531
@base.returns_single_item
3632
def replace(self, config, **kwargs):
37-
"""Replaces the existing config with a user-defined config.
33+
"""Replaces the existing configuration with a new configuration tree.
3834
3935
Make sure to back up the config file first if neccessary, as this
40-
operation can't be undone.
36+
operation can not be undone.
4137
"""
4238
return self._client.request('/config/replace', (config,), decoder='json', **kwargs)
4339

4440

4541
@base.returns_single_item
4642
def set(self, key, value=None, **kwargs):
47-
"""Add or replace a configuration value.
43+
"""Add or replace a single configuration value.
4844
4945
.. code-block:: python
5046
51-
>>> client.config("Addresses.Gateway")
47+
>>> client.config.set("Addresses.Gateway")
5248
{'Key': 'Addresses.Gateway', 'Value': '/ip4/127.0.0.1/tcp/8080'}
53-
>>> client.config("Addresses.Gateway", "/ip4/127.0.0.1/tcp/8081")
49+
>>> client.config.set("Addresses.Gateway", "/ip4/127.0.0.1/tcp/8081")
5450
{'Key': 'Addresses.Gateway', 'Value': '/ip4/127.0.0.1/tcp/8081'}
5551
5652
Parameters
@@ -62,7 +58,13 @@ def set(self, key, value=None, **kwargs):
6258
6359
Returns
6460
-------
65-
dict : Requested/updated key and its (new) value
61+
dict
62+
63+
+-------+---------------------------------------------+
64+
| Key | The requested configuration key |
65+
+-------+---------------------------------------------+
66+
| Value | The new value of the this configuration key |
67+
+-------+---------------------------------------------+
6668
"""
6769
args = (key, value)
6870
return self._client.request('/config', args, decoder='json', **kwargs)

ipfshttpclient/client/dht.py

+11-8
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def findpeer(self, peer_id, *peer_ids, **kwargs):
1313
1414
.. code-block:: python
1515
16-
>>> client.dht_findpeer("QmaxqKpiYNr62uSFBhxJAMmEMkT6dvc3oHkrZN … MTLZ")
16+
>>> client.dht.findpeer("QmaxqKpiYNr62uSFBhxJAMmEMkT6dvc3oHkrZN … MTLZ")
1717
[{'ID': 'QmfVGMFrwW6AV6fTWmD6eocaTybffqAvkVLXQEFrYdk6yc',
1818
'Extra': '', 'Type': 6, 'Responses': None},
1919
{'ID': 'QmTKiUdjbRjeN9yPhNhG1X38YNuBdjeiV9JXYWzCAJ4mj5',
@@ -38,7 +38,8 @@ def findpeer(self, peer_id, *peer_ids, **kwargs):
3838
3939
Returns
4040
-------
41-
dict : List of multiaddrs
41+
dict
42+
List of multiaddrs
4243
"""
4344
args = (peer_id,) + peer_ids
4445
return self._client.request('/dht/findpeer', args, decoder='json', **kwargs)
@@ -49,7 +50,7 @@ def findprovs(self, cid, *cids, **kwargs):
4950
5051
.. code-block:: python
5152
52-
>>> client.dht_findprovs("QmNPXDC6wTXVmZ9Uoc8X1oqxRRJr4f1sDuyQu … mpW2")
53+
>>> client.dht.findprovs("QmNPXDC6wTXVmZ9Uoc8X1oqxRRJr4f1sDuyQu … mpW2")
5354
[{'ID': 'QmaxqKpiYNr62uSFBhxJAMmEMkT6dvc3oHkrZNpH2VMTLZ',
5455
'Extra': '', 'Type': 6, 'Responses': None},
5556
{'ID': 'QmaK6Aj5WXkfnWGoWq7V8pGUYzcHPZp4jKQ5JtmRvSzQGk',
@@ -72,12 +73,13 @@ def findprovs(self, cid, *cids, **kwargs):
7273
7374
Parameters
7475
----------
75-
cid : Union[str, cid.BaseCID]
76+
cid : Union[str, cid.CIDv0, cid.CIDv1]
7677
The DHT key to find providers for
7778
7879
Returns
7980
-------
80-
dict : List of provider Peer IDs
81+
dict
82+
List of provider Peer IDs
8183
"""
8284
args = (str(cid),) + tuple(str(c) for c in cids)
8385
return self._client.request('/dht/findprovs', args, decoder='json', **kwargs)
@@ -138,7 +140,7 @@ def put(self, key, value, **kwargs):
138140
139141
.. code-block:: python
140142
141-
>>> client.dht_put("QmVgNoP89mzpgEAAqK8owYoDEyB97Mkc … E9Uc", "test123")
143+
>>> client.dht.put("QmVgNoP89mzpgEAAqK8owYoDEyB97Mkc … E9Uc", "test123")
142144
[{'ID': 'QmfLy2aqbhU1RqZnGQyqHSovV8tDufLUaPfN1LNtg5CvDZ',
143145
'Extra': '', 'Type': 5, 'Responses': None},
144146
{'ID': 'QmZ5qTkNvvZ5eFq9T4dcCEK7kX8L7iysYEpvQmij9vokGE',
@@ -169,7 +171,7 @@ def query(self, peer_id, *peer_ids, **kwargs):
169171
170172
.. code-block:: python
171173
172-
>>> client.dht_query("/ip4/104.131.131.82/tcp/4001/ipfs/QmaCpDM … uvuJ")
174+
>>> client.dht.query("/ip4/104.131.131.82/tcp/4001/ipfs/QmaCpDM … uvuJ")
173175
[{'ID': 'QmPkFbxAQ7DeKD5VGSh9HQrdS574pyNzDmxJeGrRJxoucF',
174176
'Extra': '', 'Type': 2, 'Responses': None},
175177
{'ID': 'QmR1MhHVLJSLt9ZthsNNhudb1ny1WdhY4FPW21ZYFWec4f',
@@ -187,7 +189,8 @@ def query(self, peer_id, *peer_ids, **kwargs):
187189
188190
Returns
189191
-------
190-
dict : List of peers IDs
192+
dict
193+
List of peers IDs
191194
"""
192195
args = (peer_id,) + peer_ids
193196
return self._client.request('/dht/query', args, decoder='json', **kwargs)

0 commit comments

Comments
 (0)