update README.md

This commit is contained in:
Adrien Béraud committed 2025-09-04 23:22:10 -04:00
1 parent 416de4b4f8
commit 0139e7a2d4
2 files changed
+57 -39

No files matched your search

+28 -19
View File
@@ -13,7 +13,7 @@ OpenDHT is a lightweight Distributed Hash Table implementation providing an easy
Every node in the network can read and write values to the store. Values are distributed over the network with redundancy.
## Install
## Installation
Install on Linux, macOS and Windows with:
```sh
@@ -43,30 +43,39 @@ for value in results:
Or using asyncio:
```python
import asyncio
import opendht.aio as dht
async with dht.DhtRunner() as node:
node.bootstrap("bootstrap.jami.net", "4222")
async def dht_async_demo(key_str: str):
# Start a new node using an async context manager.
# It is also possible to call run()/await shutdown() manually.
async with dht.DhtRunner(
bootstrap=(("bootstrap.jami.net", "4222"),)
) as node:
# compute key hash
key = dht.InfoHash.get(key_str)
# put data, waiting for completion
await node.put(dht.InfoHash.get("unique_key"), dht.Value(b'tata data'))
# put data, waiting for completion
await node.put(key, dht.Value(b'tata data'))
# get all values at key
results = await node.getAll(dht.InfoHash.get("unique_key"))
for value in results:
print(value)
# same operation, but stream values as they come from the network
with node.get(dht.InfoHash.get("unique_key")) as results:
async for value in results:
# get all values at key
results = await node.getAll(key)
for value in results:
print(value)
# same operation, but stream values as they come from the network
with node.get(key) as results:
async for value in results:
print(value)
# listen for changes of values at key
with node.listen(dht.InfoHash.get("unique_key")) as values:
async for value, expired in values:
print(value)
if value.data == b'tata data':
break
# listen for change of values at key
with node.listen(key) as values:
async for value, expired in values:
print(value)
if value.data == b'tata data':
break
asyncio.run(dht_async_demo("unique_key"))
```
## Documentation