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 Python SDK
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 wraps the REST endpoints in a convenient, typed interface and handles authentication, HTTP transport, and response parsing.
Key capabilities
- Create a
genai.Clientwith either an API key (public Gemini) or enterprise credentials (project, location). - Call
client.models.generate_contentto get text, images, or video from Gemini models such asgemini-3.5-flashorgemini-2.5-flash. - Provide inputs as plain strings, dictionaries, or the richer
google.genai.typesPydantic models (e.g.Part.from_text,Part.from_uri,Part.from_function_call). - Configure generation with
GenerateContentConfig(temperature, top‑p/k, max tokens, safety settings, system instructions, response modalities, etc.). - Use automatic function calling: pass Python callables as tools and the model can invoke them, or disable it to receive explicit function‑call objects.
- Support for streaming, async calls (via
client.aio), and a fastaiohttptransport option. - Built‑in handling for proxies, custom base URLs, and API version selection (
v1,v1alpha). - Context‑manager support for automatic resource cleanup, and explicit
close()/aclose()methods. - Helper utilities for listing models, uploading files, and setting safety settings.
Typical usage
from google import genai
from google.genai import types
client = genai.Client(api_key="YOUR_GEMINI_API_KEY")
response = client.models.generate_content(
model="gemini-3.5-flash",
contents=types.Part.from_text("Why is the sky blue?"),
config=types.GenerateContentConfig(temperature=0, top_p=0.95),
)
print(response.text)
Why it matters – It abstracts away the low‑level HTTP details of Google’s Gemini APIs, provides type‑safe request building, and integrates advanced features like function calling and safety controls, making it easier for Python developers to embed state‑of‑the‑art generative AI into applications, services, or research notebooks.
Documentation & install
- Docs: https://googleapis.github.io/python-genai/
- Install:
pip install google-genai(oruv pip install google-genai)
Related
- Project
- Project
- Project
- Project
- Project