@@ -43,27 +43,45 @@ pip install numpy-flight
43
43
44
44
### Basic Setup
45
45
46
+ We introduce the Baseclass 'Server':
47
+
46
48
``` 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
+ ```
49
57
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.
53
62
63
+ The server can be started locally with
64
+
65
+ ``` python
66
+ >> > server = TestServer.start(host = " 127.0.0.1" , port = 5555 )
54
67
```
55
68
56
- ### Sending Data
69
+ While the server is running we can use a client for computations
57
70
58
71
``` 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
64
74
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()
67
85
```
68
86
69
87
### Retrieving Data
0 commit comments