From 6850e012e1f23ef3c4417202d08346c0fa086c1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20B=C3=A9raud?= <adrienberaud@gmail.com> Date: Wed, 9 Sep 2015 17:36:36 -0400 Subject: [PATCH] Add python API example --- README.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/README.md b/README.md index f0dfaf02..d8d30dc4 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,7 @@ See the wiki: <https://github.com/savoirfairelinux/opendht/wiki> Examples - +### C++ example The `tools` directory includes simple example programs : * `dhtnode`, a command line tool, mostly used for debuging, allowing to perform operations supported by the library (get, put etc.) with text values. * `dhtchat`, a very simple IM client working over the dht. @@ -59,6 +60,24 @@ int main() return 0; } ``` +### Python 3 example +```python +import opendht as dht + +r = dht.DhtRunner() +r.run() + +# Join the network through any running node, +# here using a known bootstrap node. +r.bootstrap("bootstrap.ring.cx", "4222") + +r.put(dht.InfoHash.get("unique_key"), dht.Value(b'some binary data')) + +# blocking call (provide a get_cb and an optional done_cb argument to make the call non-blocking) +results = r.get(dht.InfoHash.get("unique_key")) +for r in results: + print(r) +``` How-to build and install - -- GitLab