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.
  • ModelInterface Bridge Architecture: Structured Model ↔ CLI bridge with model-driven content classification (chat vs working), topic tracking, and local device tool execution (LocalToolRegistry).
  • Modelfile System Pre-Knowledge: Embedded prompt contract instructing the model on available local tools and metadata output formats.
  • Model Discovery & Switching: List available models (list_models()) and switch active model (select_model()) or use /model <number>.
  • 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.
  • HTML Table & Markdown Parsing: Renders clean Markdown tables and code blocks directly in your terminal.
  • Interactive Terminal CLI: Built-in CLI runner (gemini-web) with Rich syntax highlighting, slash commands, and real-time streaming.

🚀 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)

Metadata

Release files for gemini-web-client 0.5.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for gemini-web-client 0.5.0
File Size Uploaded
gemini_web_client-0.5.0.tar.gz 43.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for gemini-web-client 0.5.0
File Interpreter ABI Platform
gemini_web_client-0.5.0-py3-none-any.whl Python 3 none any Details

Total release size: 84.8 kB

Release files / gemini_web_client-0.5.0.tar.gz

Download URL gemini_web_client-0.5.0.tar.gz
Size 43.4 kB
Tags Source
SHA-256 checksum
How to use checksums
b96f3974d21b72f6d8263f64f45ee6657e9e966bf0874ff0e107f85322aad38d
BLAKE2b-256 checksum
How to use checksums
bf9178a6f4d1cdc23fe240dde9d79aaa3437cd0b53a2aa53273b31021d94b76f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.14

Release files / gemini_web_client-0.5.0-py3-none-any.whl

Download URL gemini_web_client-0.5.0-py3-none-any.whl
Size 41.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
29352a2e2ee747cdd54116971f08e63f6afd6679fb3e549491742313d1affc24
BLAKE2b-256 checksum
How to use checksums
f746b7352ddd30c6d19175647bbbb0399ee7c66944482e99c79986bfd2b747ff
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.14

Release history Release notifications | RSS feed

This release

0.5.0 This release

2 release files

0.4.2

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page