Get Started
Get started with Genkit using Python (alpha)
The Genkit libraries for Python are now available for preview! Because the Python libraries are currently in Alpha, you might see API and functional changes as development progresses. We recommend using it only for prototyping and exploration.
If you discover issues with the libraries or this documentation please report them in our GitHub repository.
This guide shows you how to get started with Genkit in a Python app.
Requirements
-
Python 3.10 or later. See Download and install in the official Python docs.
-
Node.js 20 or later (for the Genkit CLI and UI). See the below for a brief guide on installing Node.
Create and explore a sample project
-
Create a new project directory:
-
(recommended) Create a Python virtual environment:
(activate if necessary, depending on the environment)
-
Install dependencies
Or create a
requirements.txt
fileand run:
-
Configure your model API key
The simplest way to get started is with Google AI Gemini API. Make sure it's available in your region.
Generate an API key for the Gemini API using Google AI Studio. Then, set the
GEMINI_API_KEY
environment variable to your key: -
Create
main.py
file:import json from pydantic import BaseModel, Field from genkit.ai import Genkit from genkit.plugins.google_genai import GoogleAI ai = Genkit( plugins=[GoogleAI()], model='googleai/gemini-2.0-flash', ) class RpgCharacter(BaseModel): name: str = Field(description='name of the character') back_story: str = Field(description='back story') abilities: list[str] = Field(description='list of abilities (3-4)') @ai.flow() async def generate_character(name: str): result = await ai.generate( prompt=f'generate an RPG character named {name}', output_schema=RpgCharacter, ) return result.output async def main() -> None: print(json.dumps(await generate_character('Goblorb'), indent=2)) ai.run_main(main())
-
Run your app. Genkit apps are just regular python application. Run them however you normally run your app.
-
Inspect your app with the Genkit Dev UI
See instructions for installing the Genkit CLI (which includes the Dev UI) below.
To inspect your app with Genkit Dev UI run with
genkit start -- <app>
command. E.g.:The command will print the Dev UI URL. E.g.:
Install Genkit CLI
-
If you don't already have Node 20 or newer on your system, install it now.
Recommendation: The
nvm
andnvm-windows
tools are a convenient way to install specific versions of Node if it's not already installed on your system. These tools install Node on a per-user basis, so you don't need to make system-wide changes.To install
nvm
:Run the following command:
Download and run the installer as described in the nvm-windows docs.
Then, to install Node and
npm
, open a new shell and run the following command: -
Install the Genkit CLI by running the following command:
This command installs the Genkit CLI into your Node installation directory so that it can be used outside of a Node project.