Skip to content

Commit 5bcfbaf

Browse files
committed
test for README
1 parent e5a5a8f commit 5bcfbaf

File tree

1 file changed

+31
-13
lines changed

1 file changed

+31
-13
lines changed

README.md

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -43,27 +43,45 @@ pip install numpy-flight
4343

4444
### Basic Setup
4545

46+
We introduce the Baseclass 'Server':
47+
4648
```python
47-
import numpy as np
48-
from np.flight import Client
49+
>>> from np.flight import Server
50+
51+
>>> class TestServer(Server):
52+
... def f(self, matrices):
53+
... self.logger.info(f"{matrices.keys()}")
54+
... # Simple implementation for testing - just return the input
55+
... return {key : 2*value for key, value in matrices.items()}
56+
```
4957

50-
# Initialize the Flight client
51-
with Client('grpc://localhost:8815') as client:
52-
...
58+
All complexity is hidden in the class 'Server' which is itself a child
59+
of the pyarrrow's FlightServerBase class. It is enough to implement
60+
the method 'f' which is expecting a dictionary of numpy arrays. It will
61+
also return a dictionary of numpy arrays.
5362

63+
The server can be started locally with
64+
65+
```python
66+
>>> server = TestServer.start(host="127.0.0.1", port=5555)
5467
```
5568

56-
### Sending Data
69+
While the server is running we can use a client for computations
5770

5871
```python
59-
# Prepare your NumPy arrays
60-
data = {
61-
'values': np.array([1, 2, 3, 4, 5]),
62-
'labels': np.array(['a', 'b', 'c', 'd', 'e'])
63-
}
72+
>>> import numpy as np
73+
>>> from np.flight import Client
6474

65-
# Send data to the server
66-
client.write('store_data', data)
75+
>>> with Client(location="grpc://127.0.0.1:5555") as client:
76+
... output = client.compute(command="compute", data={"input": np.array([1,2,3])})
77+
78+
>>> print(output["input"])
79+
[2 4 6]
80+
81+
```
82+
83+
```python
84+
server.shutdown()
6785
```
6886

6987
### Retrieving Data

0 commit comments

Comments
 (0)