Skip to main content
Python support is currently in Alpha. The core features are functional, but the API may change in future releases.
This guide will help you create your first AI-powered application using Genkit for Python. You’ll learn how to initialize Genkit, make your first generation request, and work with flows.

Prerequisites

  • Python 3.10 or later
  • pip or uv package manager
  • A Google AI API key (get one at Google AI Studio)

Step 1: Install Genkit

Install Genkit with the Google AI plugin:

Step 2: Install Genkit CLI

The CLI is the same across all languages:

Step 3: Set Your API Key

Set your Google AI API key as an environment variable:
Create a .env file in your project root:

Step 4: Create Your First Application

Create a file named app.py:
app.py
Genkit for Python uses async/await. You’ll need to run this in an async context.

Step 5: Run Your Application

Since Genkit uses async functions, you need to run it properly:
app.py
Run with the Genkit CLI for tracing:
Or run directly:

Access the Developer UI

When running with genkit start, open http://localhost:4000 to access the Developer UI.

Create a Flow

Flows are the primary abstraction in Genkit for encapsulating AI logic:

Generate Structured Output

Genkit can generate type-safe structured data using Pydantic models:

Define Tools

Tools allow AI models to call your Python functions:

Create an HTTP Server

Deploy your flows as HTTP endpoints using the built-in flow server:
Run the server:
Test your endpoint:

Use with Flask

You can also integrate Genkit with Flask:

Try Other Model Providers

Genkit supports multiple AI providers:

Development with uv

For faster dependency management, use uv:

Learn More

Python API Reference

Explore the complete Python API

Structured Output

Generate type-safe responses with Pydantic

Flask Integration

Deploy flows with Flask

Deployment

Deploy your Python applications