Skip to main content

Gemini Web Client (gemini-web-client)

PyPI version Python Version License: GPL v3

A modern Python client package for automating Google Gemini Web UI using Playwright.

✨ Features

  • Google Account Authentication: Login helper tool (gemini-login) to save persistent sessions securely in a local browser profile.
  • Model Discovery & Switching: List available models (list_models()) and switch active model (select_model()).
  • Async & Sync API: Simple Python interface to send messages, stream responses, and manage multi-turn chat sessions.
  • Multimodal Support: Attach images (PNG/JPG/WEBP) or documents (PDF, TXT, CSV, Python files) to your prompts.
  • Image Generation Extraction: Detects inline generated images (Imagen / Gemini Web) and downloads them to disk.
  • Chat History & Navigation: List past conversation threads from the Gemini sidebar and switch between chats.
  • Markdown & Code Parsing: Structured response parsing for markdown code blocks (GeminiResponse.code_blocks).
  • Interactive Terminal CLI: Built-in CLI runner (gemini-web) to chat directly from your shell.

🚀 Quick Start

1. Installation

Install directly from PyPI:

pip install gemini-web-client
playwright install chromium

(For local development from source):

git clone https://github.com/hpnquoc/gemini-web-client.git
cd gemini-web-client
pip install -e .
playwright install chromium

2. Login to Google Account

Run the login assistant to sign in to your Google Account once:

gemini-login

Follow the prompt to log in in the opened browser window. Your session will be saved locally to ./.user_data.


💡 Code Examples

Basic Prompt Execution

import asyncio
from gemini_web import GeminiWebClient

async def main():
    async with GeminiWebClient(headless=True) as client:
        response = await client.send_message("Explain quantum computing in simple terms.")
        print(response.text)

if __name__ == "__main__":
    asyncio.run(main())

Model Discovery & Switching

import asyncio
from gemini_web import GeminiWebClient

async def main():
    async with GeminiWebClient(headless=True) as client:
        # List models in UI
        models = await client.list_models()
        print("Available Models:", models)

        # Switch to a specific model
        if models:
            await client.select_model("3.5 Flash-Lite")
            response = await client.send_message("What model are you?")
            print(response.text)

if __name__ == "__main__":
    asyncio.run(main())

Real-Time Response Streaming

import asyncio
from gemini_web import GeminiWebClient

async def main():
    async with GeminiWebClient(headless=True) as client:
        async for chunk in client.send_message_stream("Write a short story about an AI."):
            print(chunk, end="", flush=True)

if __name__ == "__main__":
    asyncio.run(main())

Multi-Turn Chat Session

import asyncio
from gemini_web import GeminiWebClient

async def main():
    async with GeminiWebClient(headless=True) as client:
        chat = client.start_chat()
        
        r1 = await chat.send_message("Hi, my name is Alice.")
        print(r1.text)
        
        r2 = await chat.send_message("What is my name?")
        print(r2.text)

if __name__ == "__main__":
    asyncio.run(main())

Chat History & Thread Navigation

import asyncio
from gemini_web import GeminiWebClient

async def main():
    async with GeminiWebClient(headless=True) as client:
        # List all past chats in sidebar
        chats = await client.list_chats()
        for chat in chats:
            print(f"ID: {chat['id']} | Title: {chat['title']}")

        # Switch to a specific thread
        if chats:
            await client.switch_chat(chats[0]['id'])
            turns = await client.get_conversation_turns()
            print(f"Extracted {len(turns)} messages.")

if __name__ == "__main__":
    asyncio.run(main())

🛠️ CLI Usage

Interactive Chat REPL:

gemini-web --user-data-dir ./.user_data

Login Assistant:

gemini-login --user-data-dir ./.user_data

📜 Changelog

See CHANGELOG.md for release history and version release notes.


📄 License

GNU General Public License v3.0 (GPL-3.0)

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gemini_web_client-0.4.2.tar.gz (25.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gemini_web_client-0.4.2-py3-none-any.whl (26.0 kB view details)

Uploaded Python 3

File details

Details for the file gemini_web_client-0.4.2.tar.gz.

File metadata

  • Download URL: gemini_web_client-0.4.2.tar.gz
  • Upload date:
  • Size: 25.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for gemini_web_client-0.4.2.tar.gz
Algorithm Hash digest
SHA256 39fb9b6ae339f6ca8f63276e823bbdfc8424a8c4c02307d01276736d588f2646
MD5 2fcdc9a93a2af744c610ea39a2588819
BLAKE2b-256 9d71c29629a944614d7bd77714996b790e85fd28c6ec899f88fae6185ccbd8b1

See more details on using hashes here.

File details

Details for the file gemini_web_client-0.4.2-py3-none-any.whl.

File metadata

File hashes

Hashes for gemini_web_client-0.4.2-py3-none-any.whl
Algorithm Hash digest
SHA256 fc65a9cf712ee49e5a6ca40a1d86fadc642ca2a7544d01b3c97018dc26b5a69c
MD5 08b6b2ad5be4b0179763bbb8fbda8312
BLAKE2b-256 a89910139476f42046bbbf2cd85dd00af5d14b8d21b3cb1ab295cf2b8afd8888

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page