Google Gen AI Python SDK

The official Python SDK for calling Google's Gemini and generative AI models via the Gemini API and Vertex AI.

SDK
PyPI
v2.18.1
3,929stars
Apache License 2.0

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
94/100Excellent
Development Activity100
Maintenance100
Community92
Maturity44
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
80/100Excellent
Architecture85
Code Quality82
Innovation80
Learning Curve72

google-genai is Google’s official Python SDK for integrating generative models — including the Gemini family — into Python applications. A single Client object provides a unified interface to both the Gemini Developer API and Vertex AI, covering text and chat generation, streaming, function calling, file and cache management, batch jobs, live/realtime sessions, and embeddings.

The SDK is organized around resource-oriented submodules (chats, files, caches, batches, live, live_music) built on a shared HTTP/auth layer (_api_client.py), with dedicated sync and async client surfaces, automatic function-calling support, and a replay-based test harness for recording and replaying API interactions in tests.

What You Get

  • A unified Client object that targets either the Gemini Developer API or Vertex AI with the same interface
  • Sync and async APIs for text/chat generation, streaming responses, and multi-turn chats sessions
  • Automatic function calling, letting the model invoke Python functions passed directly to the client
  • File, cache, and batch job management (files.py, caches.py, batches.py) for large-context and asynchronous workloads
  • Live/realtime session support (live.py, live_music.py) for streaming audio/text interactions

Common Use Cases

  • Building chat or agent applications on top of Gemini models from Python backends
  • Switching between the Gemini Developer API and Vertex AI without rewriting client code
  • Running batch generation jobs or managing large uploaded files/context caches for long-context prompts
  • Building realtime, streaming voice or text assistants using the live session API

Under The Hood

Architecture The SDK centers on a Client entry point (client.py) that wires together resource-specific modules — chats.py, files.py, caches.py, batches.py, documents.py, interactions.py, live.py, live_music.py — each delegating HTTP calls to a shared _api_client.py layer that handles authentication (API key or Google Cloud credentials via google-auth), request/response transformation, and switching between the Gemini Developer API and Vertex AI endpoints. _transformers.py and _automatic_function_calling_util.py handle converting Python types and functions into the request/response shapes each backend expects.

Tech Stack Pure Python (>=3.10, tested through 3.14), built with setuptools, depending on httpx for HTTP, anyio for async support, pydantic for schema validation, google-auth for credential handling, and websockets for the live session transport.

Code Quality Tests live alongside the source under google/genai/tests, and the SDK includes a dedicated _replay_api_client.py that records and replays real API responses for deterministic testing without live network calls — a pattern purpose-built for testing an SDK whose backend behavior can’t be fully mocked. Internal modules are prefixed with underscores to clearly separate public surface from implementation detail.

API Design The client exposes both synchronous and asynchronous variants of nearly every operation, and automatic function calling lets callers pass plain Python functions as tool definitions without hand-writing JSON schemas — reducing the boilerplate typically required to wire up model tool-use. A single Client(vertexai=True/False) toggle switches the entire SDK between the Gemini Developer API and Vertex AI, avoiding the need for separate client libraries per backend.

Used by 20 apps in this directory

Python
66%
Apache 2.0

Agent Control

AI Agents

295

An open-source runtime control plane for AI agents — define safety guardrails once, apply them across agents built on LangChain, CrewAI, Google ADK, or AWS Strands, and update controls without redeploying code.

View details
79
Repo Health
71
Technical
70
Dependency
Built with
Python66%
TypeScript33%
Updated yesterday
Python
100%
Apache 2.0

Agno

Devops · AI Development · Automation

41,774

Build, run, and manage agent platforms with a full production stack — SDK, runtime, and control plane included.

View details
93
Repo Health
87
Technical
67
Dependency
Built with
Python100%
Updated today
Python
90%
Apache 2.0

Apache Airflow

Data Engineering

46,530

Define, schedule, and monitor complex data workflows as Python code — with a powerful UI, 80+ provider integrations, and battle-tested scalability across thousands of production deployments.

View details
96
Repo Health
89
Technical
66
Dependency
Built with
Python90%
Updated today
Python
62%
MIT

AutoGen

AI Development · Automation

60,518

Build autonomous and human-in-the-loop multi-agent AI systems with a layered, event-driven Python and .NET framework pioneered at Microsoft Research.

View details
57
Repo Health
78
Technical
75
Dependency
Built with
Python62%
C#25%
TypeScript12%
Updated 4 months ago
TypeScript
48%
AGPL 3.0

Banana Slides

AI Design Tools · Productivity

15,476

AI-native PPT generator with Vibe editing, multi-LLM support, and fully editable PPTX export

View details
83
Repo Health
82
Technical
71
Dependency
Built with
TypeScript48%
Python47%
Updated 3 days ago
Python
99%
MIT

deepagents

AI Agents · AI Development

27,919

The batteries-included Python agent harness — planning, sub-agents, filesystem, shell, memory, and skills bundled in, built on LangGraph.

View details
88
Repo Health
83
Technical
74
Dependency
Built with
Python99%
Updated today
TypeScript
72%
AGPL 3.0

Firecrawl

AI Development · Developer Tools

169,311

Turn any website into clean, LLM-ready data with a single API call — no proxy headaches, no scraping complexity.

View details
89
Repo Health
83
Technical
66
Dependency
Built with
TypeScript72%
Python14%
Updated today
Python
63%
Apache 2.0

GPT Researcher

Productivity · AI Assistants

29,039

The pioneering open-source autonomous AI agent that conducts deep, multi-source research and produces citation-backed reports exceeding 2,000 words — faster and more reliably than any human researcher.

View details
88
Repo Health
91
Technical
64
Dependency
Built with
Python63%
TypeScript23%
Updated 1 months ago
Python
51%
AGPL 3.0

Khoj

AI Assistants · Knowledge Management · Productivity

36,555

A self-hostable AI second brain that chats with your documents, searches the web, builds custom agents, and runs entirely on your own LLM.

View details
77
Repo Health
82
Technical
70
Dependency
Built with
Python51%
TypeScript36%
Updated 2 weeks ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search