# google-genai: The Official Python SDK for Gemini Developer and Enterprise APIs

> The googleapis/python-genai package is Google's official Python SDK for the Gemini API, supporting both the Gemini Developer API and the Gemini Enterprise Agent Platform. It provides synchronous and asynchronous clients, streaming, function calling, live sessions, and Pydantic-based types.

**googleapis/python-genai** — Google Gen AI Python SDK provides an interface for developers to integrate Google's generative models into their Python applications.

- Repository: https://github.com/googleapis/python-genai
- Website: https://googleapis.github.io/python-genai/
- Stars: 3,999 · Forks: 1,020
- Language: Python
- License: Apache-2.0
- Published: 2026-09-23 · Updated: 2026-09-23 · Language: en
- Canonical page: https://hysenlabs.com/projects/googleapis-python-genai

## What the SDK Does and Which API Backends It Supports

The google-genai package is Google's official Python SDK for calling Gemini generative models. It supports two distinct backends: the Gemini Developer API, which is accessed with an API key and targets individual developers and applications, and the Gemini Enterprise Agent Platform (formerly known as Vertex AI Gemini), which is accessed with a Google Cloud project ID and location and targets enterprise workloads.

The SDK provides a unified `Client` object that works with both backends. The only difference at construction time is which credentials you pass. For developer API access:

```python
from google import genai
client = genai.Client(api_key='GEMINI_API_KEY')
```

For Enterprise Agent Platform access:

```python
from google import genai
client = genai.Client(
    enterprise=True, project='your-project-id', location='global'
)
```

The SDK is published on PyPI as `google-genai`. The current version as of the latest release is 2.25.0, released on 2026-09-22. It requires Python 3.10 or later.

## Installation and the First Request

Install the package with pip or uv:

```sh
pip install google-genai
```

With uv:

```sh
uv pip install google-genai
```

Set the API key as an environment variable so the client picks it up automatically:

```bash
export GEMINI_API_KEY='your-api-key'
```

Once the key is set, the first content generation call looks like this:

```python
from google import genai
from google.genai import types

client = genai.Client()
response = client.models.generate_content(
    model='gemini-flash-latest',
    contents=types.Part.from_text(text='Why is the sky blue?')
)
```

The SDK also accepts dictionaries in place of typed objects. Passing `contents={'text': 'Why is the sky blue?'}` produces the same result. The `types` module, imported from `google.genai`, provides Pydantic models for all API inputs and outputs.

The README notes that if both `GEMINI_API_KEY` and `GOOGLE_API_KEY` are set, `GOOGLE_API_KEY` takes precedence. Setting only one is recommended.

## Sync and Async Clients, Context Managers, and Resource Cleanup

The SDK exposes synchronous and asynchronous clients. The async client is accessed through the `.aio` attribute of a `Client` instance. Both clients should be explicitly closed when no longer needed to release underlying HTTP connections.

For the synchronous client:

```python
from google.genai import Client
client = Client()
response_1 = client.models.generate_content(model=MODEL_ID, contents='Hello')
client.close()
```

For the async client:

```python
from google.genai import Client
aclient = Client().aio
response_1 = await aclient.models.generate_content(model=MODEL_ID, contents='Hello')
await aclient.aclose()
```

Context managers handle cleanup automatically. The sync context manager closes the underlying HTTP client on exit, avoiding the `client has been closed` error that appears in some long-running applications. The async context manager works the same way in an `async with` block.

The SDK defaults to beta API endpoints to expose preview features. To use the stable v1 endpoints, pass `http_options` with the API version set to `v1` at client construction time.

## Breaking Changes Expected in Version 3.0.0

The README includes a prominent warning about Automatic Function Calling behavior changes coming in the next major version. Engineers who depend on current AFC behavior should pin the dependency to `< 3.0.0` until they are ready to migrate.

The specific methods and fields being removed include `Live.send` and `Live.start_stream`, which should be replaced with `send_client_content`, `send_realtime_input`, `send_tool_response`, and `receive`. The `LiveConnectConfig.generation_config` field is being replaced with direct fields on `LiveConnectConfig`. Video generation will move from the `prompt`, `text`, and `image` arguments to a `source` argument. The `GenerationConfigThinkingConfig` class is being renamed to `ThinkingConfig`.

After the 3.0.0 breaking changes, AFC will only be invocable from the `Chats` module rather than from direct calls to `Models.generate_content`. Code that relies on AFC through `generate_content` will need to migrate to `Chats` before upgrading past 2.x.

The 3.0.0 migration also affects the `Live` module's stream and send interfaces, so any application using real-time audio or video will require code changes before upgrading. The README table lists the exact methods and fields being removed, which is the authoritative migration reference.

## SDK Capabilities: Streaming, Tool Use, Live Sessions, and Local Tokenization

The SDK covers the full surface of the Gemini API. Beyond basic content generation, it includes streaming responses, multi-turn chat via the `Chats` module, function calling and tool use, and real-time live sessions for bidirectional audio and video.

For local tokenization without a network call, the SDK provides an optional `local-tokenizer` extra that bundles sentencepiece, protobuf, pillow, PyTorch, torchvision, and transformers. This extra enables counting tokens locally, which reduces latency and cost in applications that need to check token budgets before sending requests. The optional extra name is `local-tokenizer` as listed in the `[project.optional-dependencies]` section of pyproject.toml.

An MCP (Model Context Protocol) dependency is listed in the requirements for Python versions above 3.9, indicating the SDK supports MCP-based tool integrations. The requirements.txt specifies `mcp>=1.14.0,<2.0.0` for this purpose.

The Agent Skills recommended in the README (google-gemini/gemini-skills for the Developer API and google/skills for the Enterprise Platform) are separate repositories that inject correct usage patterns into AI coding tools. They address the fact that LLMs and coding assistants trained on static datasets may suggest outdated API patterns.

The SDK supports Python 3.10 through 3.14 as declared in pyproject.toml. Key runtime dependencies include httpx for HTTP transport, pydantic for types, anyio for async support, tenacity for retry logic, and websockets for live session connectivity.

## Limitations and the Older google-generativeai Package

The google-genai package is distinct from the older `google-generativeai` package. Engineers migrating from the legacy SDK need to update import paths and constructor calls. The two packages are not drop-in replacements for each other and use different client initialization patterns.

The SDK requires Python 3.10 or later as specified in pyproject.toml. Applications running on Python 3.9 or earlier cannot use it without a runtime upgrade. The declared classifiers cover Python 3.10 through 3.14.

The Langchain and LlamaIndex integrations for Gemini are not part of this package. Teams using those frameworks access Gemini through their own Gemini connectors, which are maintained separately from googleapis/python-genai.

The SDK does not include fine-tuning or model training capabilities. It covers inference only. Teams that need to fine-tune a Gemini model must use the Gemini API's fine-tuning endpoints directly or through the Google Cloud Console.

When both `GEMINI_API_KEY` and `GOOGLE_API_KEY` environment variables are set, `GOOGLE_API_KEY` takes precedence. Setting only one is the recommended approach to avoid confusion. The README states this explicitly in the installation section.

For the Enterprise Agent Platform, three environment variables handle authentication: `GOOGLE_GENAI_USE_ENTERPRISE`, `GOOGLE_CLOUD_PROJECT`, and `GOOGLE_CLOUD_LOCATION`. Setting all three allows a client to be constructed with no explicit arguments, relying entirely on the environment for configuration.

The last push to the repository was on 2026-09-27, and the three most recent releases (v2.23.0, v2.24.0, v2.25.0) shipped within two weeks of each other in September 2026, indicating an actively maintained project on a frequent release cadence. The package is Apache-2.0 licensed, permitting commercial use without restriction.

## Conclusion

The google-genai SDK is the correct choice for Python developers integrating Gemini models into applications, whether through the Gemini Developer API with an API key or the Gemini Enterprise Agent Platform with a project and location. Pin the dependency to `< 3.0.0` until the breaking changes to Automatic Function Calling and the Live module ship. The SDK requires Python 3.10 or later; teams on older runtimes must upgrade before adopting it. The Apache-2.0 license permits commercial use without restriction.

## FAQ

### How do I install the Google GenAI Python SDK?

Run `pip install google-genai` to install the package. For faster installs with uv, use `uv pip install google-genai`. The package requires Python 3.10 or later.

### What is the Google Gen AI Python SDK?

The google-genai package is Google's official Python SDK for calling Gemini generative models. It supports both the Gemini Developer API (with an API key) and the Gemini Enterprise Agent Platform (with a Cloud project and location), and covers content generation, streaming, function calling, chat, and live sessions.

### What is the difference between google-genai and google-generativeai?

They are two separate packages. The google-genai package is the current official SDK; google-generativeai is the older package. They are not drop-in replacements for each other and require different import paths and client construction calls.

## Sources

- [googleapis/python-genai on GitHub](https://github.com/googleapis/python-genai)
- [License: Apache-2.0](https://github.com/googleapis/python-genai/blob/main/LICENSE)
- [Project website](https://googleapis.github.io/python-genai/)
- [README](https://github.com/googleapis/python-genai/blob/main/README.md)
- [Releases](https://github.com/googleapis/python-genai/releases)

---

Hysen Labs editorial analysis, written from the project's own repository and release notes. Cite the canonical page: https://hysenlabs.com/projects/googleapis-python-genai
