Genkit class is the primary entry point for using Genkit in Python.
Initialization
Parameters
list[Plugin] | None
List of plugins to initialize
str | None
Default model name to use
str | Path | None
Directory to load prompts from (defaults to
./prompts if it exists)ServerSpec | None
Reflection server configuration
generate()
Generates text or structured data using a model.Parameters
str | None
Model name (e.g.,
"gemini-2.0-flash")str | Part | list[Part] | None
User prompt (text, Part, or list of Parts)
str | Part | list[Part] | None
System instructions
list[Message] | None
Conversation history
list[str] | None
Tool names to enable
ToolChoice | None
Control tool usage (
"auto", "required", "none")dict | GenerationCommonConfig | None
Generation configuration (temperature, max_tokens, etc.)
Output[T] | OutputConfig | dict | None
Output configuration for structured dataUse
Output(schema=YourModel) for typed responseslist[DocumentData] | None
Context documents for grounding
ModelStreamingCallback | None
Callback for streaming chunks
list[ModelMiddleware] | None
Middleware to apply
Returns
GenerateResponseWrapper[T]
Response wrapper with
.text, .output, and .message propertiesgenerate_stream()
Generates with streaming.Returns
AsyncIterator[GenerateStreamResponse]
Async iterator yielding chunksGenerateStreamResponse fields:
done: bool- True when completeresponse: GenerateResponseWrapper- Final response (when done)content: list[Part]- Chunk content (when !done)
flow()
Decorator to define a flow.Parameters
str | None
Flow name (defaults to function name)
type | dict | None
Input schema for validation
type | dict | None
Output schema for validation
Returns
Callable
Flow decorator that wraps the function
tool()
Decorator to define a tool.Parameters
str | None
Tool name (defaults to function name)
str | None
Tool description (defaults to function docstring)
Returns
Callable
Tool decorator
embed()
Generates embeddings.Parameters
str | EmbedderRef
Embedder name or reference
str | list[str] | list[DocumentData]
Text or documents to embed
dict | None
Embedder-specific options
Returns
list[Embedding]
List of embedding vectors
retrieve()
Retrieves documents.Parameters
str | RetrieverRef
Retriever name or reference
str | DocumentData
Query text or document
dict | None
Retriever-specific options
Returns
list[Document]
Retrieved documents
evaluate()
Runs an evaluator on a dataset.Parameters
str | EvaluatorRef
Evaluator name or reference
list[BaseDataPoint]
Dataset to evaluate
dict | None
Evaluator-specific options
Returns
list[EvalResponse]
Evaluation results