Drive the Gemini web UI from Python via Playwright
Project description
Gemx
Drive the Gemini web UI from Python. A play on "Gemini" — Gemx treats
gemini.google.com as if it were an API, using Playwright to enter a prompt,
submit it, and capture the structured reply.
It exists because the obvious approaches don't work: Gemini's editor is
Quill, which keeps its own document model and ignores
DOM surgery, Playwright fill(), and synthetic input events — those leave the
model empty and the turn errors with "I encountered an error." Gemx injects
text via execCommand('insertText') (the same trusted input pipeline a manual
paste uses), reads the reply from message-content .markdown, and retains the
peak streamed text because Gemini re-mounts the response node mid-stream.
Install
uv add gemx
# Playwright needs a browser the first time:
uv run playwright install chromium
CLI
# JSON (default)
gemx "List 3 NBA teams as a JSON array"
# XML
gemx --format xml "Describe the solar system as XML"
# Plain text, reading the prompt from stdin
echo "Summarize the plot of Dune in one sentence" | gemx --format txt
# Watch the browser while it works
gemx --headful --verbose "Hello there"
The chosen --format (json, xml, or txt) is appended to the prompt as an
instruction and drives how Gemx parses the reply.
| Option | Description |
|---|---|
-f, --format {json,xml,txt} |
Output format (default: json). |
-p, --profile-dir PATH |
Chrome profile dir (default: ~/.gemx/profile). |
--headful |
Show the browser window. |
--response-timeout SECONDS |
Wait for a response to start (default: 180). |
-v, --verbose |
Log progress to stderr. |
Library
import asyncio
from pathlib import Path
from gemx import Gemx, GemxConfig, OutputFormat
async def main() -> None:
config = GemxConfig(profile_dir=Path("~/.gemx/profile"))
async with Gemx(config) as gemx:
data = await gemx.ask("List 3 fruits as JSON", OutputFormat.JSON)
print(data)
asyncio.run(main())
Authentication
Gemx drives a real, signed-in Gemini session. Point --profile-dir at a Chrome
profile that is already logged into your Google account (run once with
--headful to sign in); subsequent runs reuse that profile.
Development
uv sync
uv run ruff check .
uv run mypy
uv run pylint src/gemx
uv run pytest
The browser-console debugging scripts used to discover and verify the current
Gemini selectors live in tests/scripts/.
License
MIT © ra0x3 — Stonehedge Labs
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file gemx-0.1.0.tar.gz.
File metadata
- Download URL: gemx-0.1.0.tar.gz
- Upload date:
- Size: 15.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.0 {"installer":{"name":"uv","version":"0.10.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ba7c85234f3f07d24667b36ff5cec603994fde0f2609e5de4d17a4a394695c90
|
|
| MD5 |
6dc096d25df5d33a13d87d21e795015e
|
|
| BLAKE2b-256 |
b0d94cc992db8910dc456aa063f2c6d2e426ff31bbe0299a2a9806d53622359d
|
File details
Details for the file gemx-0.1.0-py3-none-any.whl.
File metadata
- Download URL: gemx-0.1.0-py3-none-any.whl
- Upload date:
- Size: 10.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.0 {"installer":{"name":"uv","version":"0.10.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3f2f136b51143352bb23f37c9d509a47189fe9dcaedf171080dd72367da56eb5
|
|
| MD5 |
c452a152906310ddf1f6ec69c66ebe84
|
|
| BLAKE2b-256 |
689d472a2e42ec9b47de1a30b0cffadb68fc4873ad53a3486f96e7e449ca2136
|