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.33.0
4,040 stars
Apache License 2.0

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
94 /100 Excellent
Development Activity 100
Maintenance 100
Community 92
Maturity 44
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
80 /100 Excellent
Architecture 85
Code Quality 82
Innovation 80
Learning Curve 72

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 22 apps in this directory

Python
51%
AGPL 3.0

Khoj

AI Assistants · Knowledge Management · Productivity

37,802

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
62
Repo Health
82
Technical
66
Dependency
Built with
Python 51%
TypeScript 36%
Updated 2 months ago
Rust
43%
Apache 2.0

LanceDB

AI Development · Databases

11,757

Open-source, embedded vector database built on the Lance columnar format for fast multimodal search across billions of vectors, backed by Y Combinator (W23).

View details
90
Repo Health
86
Technical
72
Dependency
Built with
Rust 43%
Python 27%
HTML 21%
Updated 5 days ago
Python
53%
AGPL 3.0

LearnHouse

CMS · Learning Management

2,413

Open-source LMS with AI tutoring, real-time collaboration boards, live code execution, and built-in course monetization — self-hosted in minutes.

View details
90
Repo Health
77
Technical
65
Dependency
Built with
Python 53%
TypeScript 45%
Updated 5 days ago
Python
84%
MIT

LiteLLM

AI Development · Developer Tools

61,933

Open source AI gateway and Python SDK that gives you one OpenAI-compatible interface to call 100+ LLM providers, with built-in routing, cost tracking, guardrails, and virtual keys.

View details
93
Repo Health
81
Technical
69
Dependency
Built with
Python 84%
TypeScript 11%
Updated 5 days ago
Python
66%
Other

Morphik

AI Development · Databases · Search

3,717

Morphik is an AI-native ingestion and retrieval engine that lets developers store, search, and reason over visually rich documents — scanned PDFs, manuals, slides, and video — without duct-taping together OCR, an embedding model, and a vector database.

View details
64
Repo Health
71
Technical
67
Dependency
Built with
Python 66%
TypeScript 23%
Updated 1 weeks ago
TypeScript
84%
Apache 2.0

nao

AI Development · Analytics

1,949

Build and deploy an open-source analytics agent that understands your data warehouse and answers business questions in plain English.

View details
85
Repo Health
76
Technical
67
Dependency
Built with
TypeScript 84%
Python 15%
Updated 5 days ago
Python
64%
Other

Onyx

AI Agents · AI Assistants · Knowledge Management

32,935

Self-hostable AI platform with agentic RAG, 50+ connectors, deep research, code execution, and support for every major LLM provider.

View details
92
Repo Health
83
Technical
68
Dependency
Built with
Python 64%
TypeScript 26%
Updated 5 days ago
Python
38%
Other

Open WebUI

AI Agents · AI Assistants

156,607

The extensible, privacy-first AI platform that runs Ollama, OpenAI, and any LLM backend behind a polished, feature-packed web interface.

View details
92
Repo Health
75
Technical
66
Dependency
Built with
Python 38%
Svelte 35%
JavaScript 19%
Updated 5 days ago
TypeScript
92%
Other

OpenHands

AI Code Assistants · AI Development

91,695

The self-hosted developer control center for running AI coding agents — locally, in Docker, on VMs, or across cloud backends — with automation workflows for GitHub, Slack, and more.

View details
91
Repo Health
82
Technical
67
Dependency
Built with
TypeScript 92%
Updated 6 days 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