googleapis/python-genai

Google Gen AI Python SDK provides an interface for developers to integrate Google's generative models into their Python applications.

Google Gen AI SDK (python‑genai)

What it is – A first‑party Python client library that lets you call Google’s Gemini generative‑AI models (both the public Gemini Developer API and the Gemini Enterprise Agent Platform). It handles authentication, request construction, streaming, async usage, and response parsing so you can focus on the prompt and the result.

Key capabilities

  • Create a genai.Client with an API key or enterprise credentials.
  • Call client.models.generate_content(...) to get text, images, or videos from Gemini models such as gemini-flash-latest or gemini-3.1-pro-preview.
  • Supports both synchronous and asynchronous usage (Client().aio).
  • Flexible input: plain strings, types.Part objects, file uploads, or function‑call parts.
  • Configuration via Pydantic models or plain dictionaries (e.g., GenerateContentConfig, SafetySetting).
  • Automatic function calling (AFC) – pass Python callables as tools and let the model invoke them, with an option to disable.
  • Streaming, real‑time, and proxy support; optional fast async client via aiohttp.
  • Context‑manager helpers to ensure HTTP connections are closed.

Typical workflow

from google import genai
from google.genai import types

client = genai.Client(api_key='YOUR_KEY')
response = client.models.generate_content(
    model='gemini-flash-latest',
    contents='Why is the sky blue?',
    config=types.GenerateContentConfig(max_output_tokens=50)
)
print(response.text)
client.close()

Who it’s for – Python developers who want to integrate Gemini’s large language‑model capabilities (text generation, image generation, function calling, safety controls, etc.) into applications, scripts, or services without dealing with low‑level HTTP details.

Where to learn more – Full docs at https://googleapis.github.io/python-genai/, PyPI page, and the Gemini API reference linked in the README.

Related

  • Project
  • Project
  • Project
  • Project
  • Project