-
Notifications
You must be signed in to change notification settings - Fork 0
/
python.qmd
65 lines (48 loc) · 1.34 KB
/
python.qmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
---
title: "Python"
---
The [`rembus`](https://pypi.org/project/rembus/) Python package provide both a synchronous and an
asynchronous interface.
```python
# async API
import rembus
```
```python
# sync API
import rembus.sync as rembus
```
## Getting Started
```bash
pip install rembus
```
Then create a component object to interact with the others components:
```python
# sync API
rb = rembus.component()
# async API
rb = await rembus.component()
```
The `rb` object provides methods for exposing functions implementation, for subscribing to topics, for message publishing and for service requests:
- rpc
- publish
- expose
- subscribe
## Request a service (RPC)
This example is a demo of requesting the service [`stats`](julia.qmd#implements-a-service-rpc) implemented in Julia.
- A python pandas dataframe is created;
- The pandas dataframe is used as an argument of the rpc service `stats`;
- On the RPC server side the `stats` method receive a Julia DataFrame;
- The return value of `stats` is a Julia Dictionary;
- On the client RPC side the response is a python dictionary.
```python
import rembus.sync as rembus
from random import random
import pandas as pd
df = pd.DataFrame({
"name": [f"kpi_{i}" for i in range(1,6)],
"ts": range(1,6),
"value": [random() for i in range(1,6)]
})
rb = rembus.component()
summary = rb.rpc("stats", df)
```