whatisgithub

What is python-genai?

googleapis/python-genai — explained in plain English

Analysis updated 2026-07-03

3,695PythonAudience · developerComplexity · 2/5Setup · easy

In one sentence

Official Python library from Google for calling Gemini AI models, send text, images, or files to Gemini 2.5 and get AI-generated responses, with support for streaming, multi-turn chat, function calling, and agents.

Mindmap

mindmap
  root((repo))
    What it does
      Call Gemini AI models
      Text and image input
      Chat and agents
    Tech stack
      Python
      Google Gemini API
      Vertex AI
    Use cases
      Build AI chatbots
      Add AI to Python apps
      Let AI call your code
    Audience
      Developers
      Data scientists
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

What do people build with it?

USE CASE 1

Add Gemini AI text generation to a Python script with a single pip install and a free API key from Google AI Studio.

USE CASE 2

Build a multi-turn AI chatbot in Python using the library's built-in chat session support that retains conversation history.

USE CASE 3

Let Gemini trigger functions in your Python app by defining function-calling tools the model can invoke during a conversation.

USE CASE 4

Stream AI responses token by token to display immediate feedback in a web or CLI application.

What is it built with?

PythonGoogle Gemini APIVertex AIasyncio

How does it compare?

googleapis/python-genaigeneralmills/pytrendsoctodns/octodns
Stars3,6953,6953,695
LanguagePythonPythonPython
Setup difficultyeasyeasymoderate
Complexity2/52/53/5
Audiencedeveloperdataops devops

Figures from each repo's GitHub metadata at analysis time.

How do you get it running?

Difficulty · easy Time to first run · 5min

Requires a free Google AI Studio API key or a Google Cloud project for Vertex AI, install with pip install google-genai.

So what is it?

This is the official Python library from Google for working with their Gemini AI models. You install it with a single pip command, add your API key, and then your Python code can send text to Gemini and get AI-generated responses back. It supports both the free Gemini Developer API (which you access with an API key from Google AI Studio) and the enterprise Vertex AI platform (which ties into Google Cloud projects). The core of the library is a client object. You create one with your credentials, then call methods on it to generate text, work with files, start chat sessions, create AI agents, and more. The README walks through each of these capabilities with working code examples. For generating text, you pick a model name (such as gemini-2.5-flash) and pass in your prompt. The library handles sending the request to Google's servers and returning the result. Beyond simple text generation, the library covers streaming responses (where text arrives word by word rather than all at once), multi-turn conversations, function calling (where the AI can trigger specific code in your application), image and file inputs, and building agents that can take sequences of actions. There is also an async version of every method for applications that need to handle many requests at the same time without blocking. Setup requires choosing which API backend to use. The Gemini Developer API needs only an API key stored as an environment variable. Vertex AI needs a Google Cloud project ID and a region. Both options use the same client interface once configured, so switching between them mostly means changing the client initialization. The README also includes guidance on features like cached content (to reduce costs when reusing the same large context), code execution, and grounding responses with Google Search. Configuration options such as temperature and safety filters are passed as typed objects from the library's types module, though plain Python dictionaries work too. The full README is longer than what was shown.

Copy-paste prompts

Prompt 1
Show me a minimal Python script using google-genai that sends a text prompt to gemini-2.5-flash and prints the response. Include the API key setup.
Prompt 2
Using google-genai, build a multi-turn chat session in Python that keeps conversation history across several messages. Show the full code.
Prompt 3
How do I use function calling in google-genai so Gemini can trigger a Python function that fetches the current weather? Include the tool definition and the result-handling code.
Prompt 4
Show me how to stream a Gemini response word by word with google-genai so tokens display as they arrive in a Python CLI app.
Prompt 5
I'm moving from the Gemini Developer API to Vertex AI. What changes do I need in my google-genai client initialization? Show before and after.

Frequently asked questions

What is python-genai?

Official Python library from Google for calling Gemini AI models, send text, images, or files to Gemini 2.5 and get AI-generated responses, with support for streaming, multi-turn chat, function calling, and agents.

What language is python-genai written in?

Mainly Python. The stack also includes Python, Google Gemini API, Vertex AI.

How hard is python-genai to set up?

Setup difficulty is rated easy, with roughly 5min to a first successful run.

Who is python-genai for?

Mainly developer.

Open on GitHub → Ask about another repo

This repo across BitVibe Labs

Verify against the repo before relying on details.