GenAI Processors is a lightweight Python library that enables efficient, parallel content processing.
https://github.com/google-gemini/genai-processors.git
Build Modular, Asynchronous, and Composable AI Pipelines for Generative AI.
GenAI Processors is a lightweight Python library that enables efficient, parallel content processing.
At the core of the GenAI Processors library lies the concept of a Processor. A
Processor encapsulates a unit of work with a simple API: it takes a stream of
ProcessorParts (i.e. a data part representing a text, image, etc.) as input
and returns a stream of ProcessorParts (or compatible types) as output.
# Any class inheriting from processor.Processor and
# implementing this function is a processor.
async def call(
content: AsyncIterable[ProcessorPart]
) -> AsyncIterable[ProcessorPartTypes]
You can apply a Processor to any input stream and easily iterate through its
output stream:
from genai_processors import content_api
from genai_processors import streams
# Create an input stream (strings are automatically cast into Parts).
input_parts = ["Hello", content_api.ProcessorPart("World")]
input_stream = streams.stream_content(input_parts)
# Apply a processor to a stream of parts and iterate over the result
async for part in simple_text_processor(input_stream):
print(part.text)
...
The concept of Processor provides a common abstraction for Gemini model calls
and increasingly complex behaviors built around them, accommodating both
turn-based interactions and live streaming.
Processor andPartProcessor units, which are easily chained (+) or parallelized (//)
to create sophisticated data flows and agentic behaviors.
GenaiModel for turn-based API calls and LiveProcessor for real-time
streaming interactions.
ProcessorPart: A wrapper around genai.types.Part enriched withasyncioProcessorParts.
The GenAI Processors library requires Python 3.10+.
Install it with:
pip install genai-processors
Check the following colabs to get familiar with GenAI processors (we recommend following them in order):
explains the basics ofProcessorPart, ProcessorContent, and how to
create them.
an introduction to the core concepts of GenAI Processors.
a walkthrough of the typical steps to create a Processor or a
PartProcessor.
a couple of examples of real-time processors built from the Gemini Live API
using the LiveProcessor class.
Explore the examples/ directory for practical demonstrations:
ProcessorParts, etc.
The core/ directory contains a set of basic processors that you can leverage in your own applications. It includes the generic building blocks needed for most real-time applications and will evolve over time to include more core components.
Community contributions expanding the set of built-in processors are located under contrib/ - see the section below on how to add code to the GenAI Processor library.
Contributions are welcome! Please see CONTRIBUTING.md for guidelines on how to contribute to this project.
This project is licensed under the Apache License, Version 2.0. See the LICENSE file for details.
If you make use of Gemini via the Genai Processors framework, please ensure you review the Terms of Service.