Skip to main content

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

Project description

Python SDK for Numaflow

Build black License Release Version

This is the Python SDK for Numaflow.

This SDK provides the interface for writing different functionalities of Numaflow like UDFs, UDSinks, UDSources and SideInput in Python.

Installation

Install the package using pip.

pip install pynumaflow

Build locally

This project uses Poetry for dependency management and packaging. To build the package locally, run the following command from the root of the project.

make setup

To run unit tests:

make test

To format code style using black and ruff:

make lint

Setup pre-commit hooks:

pre-commit install

Implementing different functionalities

Server Types

There are different types of gRPC server mechanisms which can be used to serve the UDFs, UDSinks and UDSource. These have different functionalities and are used for different use cases.

Currently we support the following server types:

  • Sync Server
  • Asyncronous Server
  • MultiProcessing Server

Not all of the above are supported for all UDFs, UDSource and UDSinks.

For each of the UDFs, UDSource and UDSinks, there are seperate classes for each of the server types. 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.

SyncServer

Syncronous Server is the simplest server type. It is a multithreaded threaded server which can be used for simple UDFs and UDSinks. 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.

grpc_server = MapServer(handler)

AsyncServer

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. The handler function for such a server should be an async function.

grpc_server = MapAsyncServer(handler)

MultiProcessServer

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. 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.

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.

Thus this server type is useful for UDFs which are CPU intensive.

grpc_server = MapMultiProcServer(mapper_instance=handler, server_count=2)

Currently Supported Server Types for each functionality

These are the class names for the server types supported by each of the functionalities.

  • UDFs
    • Map
      • MapServer
      • MapAsyncServer
      • MapMultiProcServer
    • Reduce
      • ReduceAsyncServer
    • MapStream
      • MapStreamAsyncServer
    • BatchMap
      • BatchMapAsyncServer
    • Source Transform
      • SourceTransformServer
      • SourceTransformMultiProcServer
  • UDSource
    • SourceServer
    • SourceAsyncServer
  • UDSink
    • SinkServer
    • SinkAsyncServer
  • SideInput
    • SideInputServer

Handler Function and Classes

All the server types take a instance of a handler class or a handler function as an argument. The handler function or class is the function or class which implements the functionality of the UDF, UDSource or UDSink. For ease of use the user can pass either of the two to the server and the server will handle the rest.

The handler for each of the servers has a specific signature which is defined by the server type and the implentation of the handlers should follow the same signature.

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. The base handler class for each of the functionalities has the same signature as the handler function for the respective server type. The list of base handler classes for each of the functionalities is given below:

  • UDFs
    • Map
      • Mapper
    • Reduce
      • Reducer
    • MapStream
      • MapStreamer
    • Source Transform
      • SourceTransformer
    • Batch Map
      • BatchMapper
  • UDSource
    • Sourcer
  • UDSink
    • Sinker
  • SideInput
    • SideInput

More details about the signature of the handler function for each of the server types is given in the documentation of the respective server type.

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.12.1.tar.gz (92.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pynumaflow-0.12.1-py3-none-any.whl (157.8 kB view details)

Uploaded Python 3

File details

Details for the file pynumaflow-0.12.1.tar.gz.

File metadata

  • Download URL: pynumaflow-0.12.1.tar.gz
  • Upload date:
  • Size: 92.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.2 CPython/3.12.3 Linux/6.11.0-1018-azure

File hashes

Hashes for pynumaflow-0.12.1.tar.gz
Algorithm Hash digest
SHA256 cc41015c0942b87f5c4da1cae4e002147352b8e6fae881260c1ea27ab3cd81d4
MD5 49cdb5f4efcead4cc327e9ae5b74b6ce
BLAKE2b-256 4ff51ea49b8873eabe8a187cabf910cce56232f3174fa473b1afc38e6b248b7e

See more details on using hashes here.

File details

Details for the file pynumaflow-0.12.1-py3-none-any.whl.

File metadata

  • Download URL: pynumaflow-0.12.1-py3-none-any.whl
  • Upload date:
  • Size: 157.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.2 CPython/3.12.3 Linux/6.11.0-1018-azure

File hashes

Hashes for pynumaflow-0.12.1-py3-none-any.whl
Algorithm Hash digest
SHA256 936e3ee6d845632edb5927eb303d31bb0b29c0496573947abb3e61a03d9c1841
MD5 3f99f0bb9c570031666abb9edc468c2f
BLAKE2b-256 0c5187bbe8091509070a31430ef0d16e81319b34826fd4315d92b49902dff743

See more details on using hashes here.

Supported by

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