You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is the Python SDK for [Numaflow](https://numaflow.numaproj.io/).
9
-
10
-
This SDK provides the interface for writing different functionalities of Numaflow like [UDFs](https://numaflow.numaproj.io/user-guide/user-defined-functions/user-defined-functions/), [UDSinks](https://numaflow.numaproj.io/user-guide/sinks/user-defined-sinks/), [UDSources](https://numaflow.numaproj.io/user-guide/sources/user-defined-sources/) and [SideInput](https://numaflow.numaproj.io/specifications/side-inputs/) in Python.
8
+
`pynumaflow` is the Python SDK for [Numaflow](https://numaflow.numaproj.io/), a Kubernetes-native stream processing framework. Write a Python function, wire it to a server class, and Numaflow handles the gRPC transport, autoscaling, and deployment — no boilerplate required. The SDK supports synchronous and asynchronous execution models, and both function-based and class-based handler styles.
11
9
12
10
## Installation
13
11
14
-
Install the package using pip.
15
12
```bash
16
13
pip install pynumaflow
17
14
```
18
15
19
-
### Build locally
16
+
<details>
17
+
<summary>Build & develop locally</summary>
20
18
21
19
This project uses [uv](https://docs.astral.sh/uv/) for dependency management and packaging.
22
20
To build the package locally, run the following command from the root of the project.
-[Implement User Defined Sinks](https://github.com/numaproj/numaflow-python/tree/main/packages/pynumaflow/examples/sink)
52
-
-[Implement User Defined SideInputs](https://github.com/numaproj/numaflow-python/tree/main/packages/pynumaflow/examples/sideinput)
53
-
54
-
## Server Types
55
-
56
-
There are different types of gRPC server mechanisms which can be used to serve the UDFs, UDSinks and UDSource.
57
-
These have different functionalities and are used for different use cases.
58
-
59
-
Currently we support the following server types:
60
-
61
-
- Sync Server
62
-
- Asyncronous Server
63
-
- MultiProcessing Server
41
+
</details>
64
42
65
-
Not all of the above are supported for all UDFs, UDSource and UDSinks.
43
+
## Capabilities
66
44
67
-
For each of the UDFs, UDSource and UDSinks, there are seperate classes for each of the server types.
68
-
This helps in keeping the interface simple and easy to use, and the user can start the specific server type based on the use case.
45
+
The SDK covers the full range of Numaflow extension points. Each capability maps to a dedicated set of server classes and handler interfaces.
69
46
47
+
> [!TIP]
48
+
> Each capability below links to working examples in both function-based and class-based handler styles. See the full [examples directory](https://github.com/numaproj/numaflow-python/tree/main/packages/pynumaflow/examples) for all implementations.
|[**User-Defined Sources (UDSource)**](https://numaflow.numaproj.io/user-guide/sources/user-defined-sources/)| Ingest data from custom sources with read, ack, pending, and partition handlers |[Sourcer](https://numaproj.io/numaflow-python/latest/api/sourcer/) · [Source Transform](https://numaproj.io/numaflow-python/latest/api/sourcetransformer/)|
54
+
|[**User-Defined Sinks (UDSink)**](https://numaflow.numaproj.io/user-guide/sinks/user-defined-sinks/)| Deliver data to custom destinations with per-message acknowledgment |[Sinker](https://numaproj.io/numaflow-python/latest/api/sinker/)|
55
+
|[**Side Inputs**](https://numaflow.numaproj.io/specifications/side-inputs/)| Broadcast slow-changing reference data to UDF vertices without passing it through the pipeline |[Side Input](https://numaproj.io/numaflow-python/latest/api/sideinput/)|
72
56
73
-
Syncronous Server is the simplest server type. It is a multithreaded threaded server which can be used for simple UDFs and UDSinks.
74
-
Here the server will invoke the handler function for each message. The messaging is synchronous and the server will wait for the handler to return before processing the next message.
57
+
## Choosing Your Server Type
75
58
76
-
```
77
-
grpc_server = MapServer(handler)
78
-
```
59
+
Each functionality is served by a dedicated server class. Choose the server type that matches your workload characteristics:
Asyncronous Server is a multi threaded server which can be used for UDFs which are asyncronous. Here we utilize the asyncronous capabilities of Python to process multiple messages in parallel. The server will invoke the handler function for each message. The messaging is asyncronous and the server will not wait for the handler to return before processing the next message. Thus this server type is useful for UDFs which are asyncronous.
83
-
The handler function for such a server should be an async function.
MultiProcess Server is a multi process server which can be used for UDFs which are CPU intensive. Here we utilize the multi process capabilities of Python to process multiple messages in parallel by forking multiple servers in different processes.
92
-
The server will invoke the handler function for each message. Individually at the server level the messaging is synchronous and the server will wait for the handler to return before processing the next message. But since we have multiple servers running in parallel, the overall messaging also executes in parallel.
85
+
-**Function-based** — pass a plain `def` or `async def` directly to the server. Best for simple, stateless logic.
86
+
-**Class-based** — inherit from the corresponding base class (e.g., `Mapper`, `Reducer`, `Sinker`) and implement the `handler` method. Useful when your handler needs initialization arguments, internal state, or helper methods.
93
87
94
-
This could be an alternative to creating multiple replicas of the same UDF container as here we are using the multi processing capabilities of the system to process multiple messages in parallel but within the same container.
88
+
The linked examples above demonstrate both styles for each functionality.
95
89
96
-
Thus this server type is useful for UDFs which are CPU intensive.
#### Currently Supported Server Types for each functionality
102
-
103
-
These are the class names for the server types supported by each of the functionalities.
104
-
105
-
- UDFs
106
-
- Map
107
-
- MapServer
108
-
- MapAsyncServer
109
-
- MapMultiProcServer
110
-
- Reduce
111
-
- ReduceAsyncServer
112
-
- MapStream
113
-
- MapStreamAsyncServer
114
-
- BatchMap
115
-
- BatchMapAsyncServer
116
-
- Source Transform
117
-
- SourceTransformServer
118
-
- SourceTransformMultiProcServer
119
-
- UDSource
120
-
- SourceServer
121
-
- SourceAsyncServer
122
-
- UDSink
123
-
- SinkServer
124
-
- SinkAsyncServer
125
-
- SideInput
126
-
- SideInputServer
127
-
128
-
129
-
130
-
131
-
### Handler Function and Classes
132
-
133
-
All the server types take a instance of a handler class or a handler function as an argument.
134
-
The handler function or class is the function or class which implements the functionality of the UDF, UDSource or UDSink.
135
-
For ease of use the user can pass either of the two to the server and the server will handle the rest.
136
-
137
-
The handler for each of the servers has a specific signature which is defined by the server type and the implentation of the handlers
138
-
should follow the same signature.
139
-
140
-
For using the class based handlers the user can inherit from the base handler class for each of the functionalities and implement the handler function.
141
-
The base handler class for each of the functionalities has the same signature as the handler function for the respective server type.
142
-
The list of base handler classes for each of the functionalities is given below:
143
-
144
-
- UDFs
145
-
- Map
146
-
- Mapper
147
-
- Reduce
148
-
- Reducer
149
-
- MapStream
150
-
- MapStreamer
151
-
- Source Transform
152
-
- SourceTransformer
153
-
- Batch Map
154
-
- BatchMapper
155
-
- UDSource
156
-
- Sourcer
157
-
- UDSink
158
-
- Sinker
159
-
- SideInput
160
-
- SideInput
161
-
162
-
More details about the signature of the handler function for each of the server types is given in the
163
-
documentation of the respective server type.
92
+
For SDK development workflow, testing against a live pipeline, and adding new examples, see the [Developer Guide](../../development.md).
93
+
For general contribution guidelines, see the [Numaproj Contributing Guide](https://github.com/numaproj/numaproj/blob/main/CONTRIBUTING.md).
0 commit comments