Skip to main content

Provides the interfaces of writing Python User Defined Functions and Sinks for NumaFlow.

Project description

Python SDK for Numaflow

This SDK provides the interface for writing UDFs and UDSinks in Python.

Implement a User Defined Function (UDF)

from pynumaflow.function import Messages, Message, Datum, UserDefinedFunctionServicer


def function_handler(key: str, datum: Datum) -> Messages:
    """
    Simple UDF that relays an incoming message.
    """
    val = datum.value
    _ = datum.event_time
    _ = datum.watermark
    messages = Messages(Message(key=key, value=val))
    return messages


if __name__ == "__main__":
    grpc_server = UserDefinedFunctionServicer(function_handler)
    grpc_server.start()

Sample Image (TODO)

Implement a User Defined Sink (UDSink)

from typing import List
from pynumaflow.sink import Datum, Responses, Response, UserDefinedSinkServicer


def udsink_handler(datums: List[Datum]) -> Responses:
    responses = Responses()
    for msg in datums:
        print("User Defined Sink", msg)
        responses.append(Response.as_success(msg.id))
    return responses


if __name__ == "__main__":
    grpc_server = UserDefinedSinkServicer(udsink_handler)
    grpc_server.start()

Sample Image

A sample UDSink Dockerfile is provided under examples.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pynumaflow-0.3.0.tar.gz (19.4 kB view hashes)

Uploaded Source

Built Distribution

pynumaflow-0.3.0-py3-none-any.whl (27.8 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page