Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/streamr-dev/streamr-client-python
Python library for accessing Streamr API
https://github.com/streamr-dev/streamr-client-python
client-library decentralized decentralized-web json pubsub python realtime realtime-messaging streamr streamr-client web3
Last synced: 2 months ago
JSON representation
Python library for accessing Streamr API
- Host: GitHub
- URL: https://github.com/streamr-dev/streamr-client-python
- Owner: streamr-dev
- License: apache-2.0
- Created: 2019-01-02T17:17:15.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2022-12-27T15:33:41.000Z (about 2 years ago)
- Last Synced: 2024-03-20T02:10:41.085Z (10 months ago)
- Topics: client-library, decentralized, decentralized-web, json, pubsub, python, realtime, realtime-messaging, streamr, streamr-client, web3
- Language: Python
- Size: 146 KB
- Stars: 9
- Watchers: 5
- Forks: 4
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# This library has been deprecated.
## Authenticating with an API key has been deprecated.
## Support for email/password authentication will be dropped in the future and cryptographic keys/wallets will be the only supported method.
## Streamr-Client-Python
By using this client, you can easily interact with the [Streamr](http://www.streamr.com) API from python environments. You can, for example, subscribe to real-time data in Streams, produce new data to Streams, and create new Streams.
This library is work-in-progress
### Installation
1. download
2. `cd streamr-client-python`
3. `pip install .`
### Tests
You can test the integration functions using the following steps.`client_test.py`: you can run following commands to test.
```
$ cd streamr-client-python
$ pytest
```### Usage
Here are some quick examples.
#### Importing streamr-client-python module
```
from streamr import Client, Option
```#### Creating a StreamrClient instance with given option
```
option = Option.get_default_option()
option.api_key = 'your-api-key'
option.auto_connect = False
option.auto_disconnect = False
client = Client(option)
```
#### getting or creating a stream by name```
stream = client.get_or_create_stream('stream-test')```
#### getting the stream id
```
stream_id = stream[0]['id']```
#### getting stream by stream_name or stream_id
```
stream = client.get_stream_by_name('stream-test')
```
```
stream = client.get_stream_by_id(stream_id)
```#### checking the state of connection
```
print(client.connection.state)
```#### connect to server
```
client.connect()
while(not client.is_connected()):
pass
```#### Subscribing to stream
```
def callback(msg,_):
print('message received . The Content is : %s'%(msg))subscription = client.subscribe(stream_id, callback)
```#### publishing data to stream
```
import time
data = [{"name":'google',"age":19},{"name":"yahoo","age":11},{"name":"facebook","age":13},{"name":"twitter","age":1}]
stream_id = 'your stream ID'
for d in data:
client.publish(subscription, d)
time.sleep(0.01)
```#### disconnect from server
```
client.disconnect()
```