Generative UI for Python agents. Your Python backend streams OpenUI Lang; your React app renders it as live cards, tables, forms and charts with OpenUI's open-source renderer.
See it in action: Wander
examples/wander is a full booking concierge built with genui: a Python agent on Gemini with real tools (search, availability, booking) and a React app with custom components (polaroid stay cards, a range calendar, a receipt, a boarding-pass ticket). The agent answers only in OpenUI Lang; genui handles the prompt, the tool events, the streaming and the button clicks.
A real run: Gemini agent → genui → React. Watch the full-quality video.
- Free, MIT.
pip install genui-py. No account, no API key, no paid tier. - Your data stays with you. Prompt generation, validation and streaming run in your process. Zero telemetry, zero network calls.
- Any model. OpenAI, Anthropic, Gemini, or local models through any OpenAI-compatible server (Ollama, vLLM, LM Studio).
- Any agent. Plain Python, LangGraph, OpenAI Agents SDK, Pydantic AI, CrewAI — if it yields text, genui can stream it.
- Spec-exact. Implements the OpenUI 1.0 spec and runs the official conformance fixtures in CI.
genui is a community project. It is not affiliated with or endorsed by Thesys, the authors of OpenUI.
How it fits
React (OpenUI renderer) Python (your agent + genui)
─────────────────────── ───────────────────────────
components (Zod + React) ──spec.json──▶ Library.from_spec()
library.system_prompt() → your LLM
<AgentInterface agUIAdapter()> ◀──SSE── stream_response(llm_stream)
button click @ToAssistant ──POST────▶ read_run(): clean history for the model
The frontend owns the components. npx @openuidev/cli generate src/library.ts --spec --out spec.json exports them, and genui reads that file, so the prompt and the renderer can never drift apart.
Quick start (FastAPI)
pip install "genui-py[fastapi,openai]"
from fastapi import FastAPI, Request
from openai import AsyncOpenAI
from genui import Library
from genui.integrations.fastapi import read_run, stream_response
library = Library.from_spec("spec.json")
SYSTEM_PROMPT = library.system_prompt()
client = AsyncOpenAI()
app = FastAPI()
@app.post("/api/chat")
async def chat(request: Request):
run = await read_run(request)
stream = await client.chat.completions.create(
model="gpt-5.5-mini",
messages=[{"role": "system", "content": SYSTEM_PROMPT}, *run.messages],
stream=True,
)
return stream_response(stream, run=run)
npm install genui-react
// React
import { GenUIChat } from "genui-react";
import "genui-react/styles.css";
<GenUIChat url="/api/chat" />;
Prefer composing OpenUI's components yourself? genuiLLM({ url }) returns the client for AgentInterface, and GenUIRenderer renders a single stored response.
Rendering your own components? Import from genui-react/core. It has the renderer, transport and storage without OpenUI's default component library: about 210 KB gzipped with React, against ~970 KB for the full chat.
A full working app is in examples/fastapi-react. Backend examples for Anthropic, Ollama (fully local), LangGraph, OpenAI Agents SDK, Pydantic AI and Flask are in examples/backends.
What you can stream
stream_response() (and genui.stream.encode() for other frameworks) accepts sync or async iterables of:
| item | example |
|---|---|
str |
yield 'root = Card([title])' from any agent |
| OpenAI Chat Completions chunks | await client.chat.completions.create(..., stream=True) |
| OpenAI Responses events | client.responses.create(..., stream=True) |
| Anthropic Messages events | client.messages.create(..., stream=True) |
| LangChain / LangGraph message chunks | graph.astream(..., stream_mode="messages") |
| genui events | ToolCallStart, ToolCallArgs, ToolResult, StreamError, … |
Output formats: "ag-ui" (default, for agUIAdapter()) or "openai" (for openAIAdapter()). Exceptions inside your agent become a RUN_ERROR the UI can show.
Validate and auto-fix model output
autofix() checks the program when the reply ends. If it has errors (an unknown component, a missing prop, no root), it asks the model again with the structured error list. The corrected program replaces the broken one in the same message, so the UI updates in place.
from genui import autofix
async def call_model(fix): # [] first, then the correction turns
return await client.chat.completions.create(
model=MODEL, messages=[system, *run.messages, *fix], stream=True)
return stream_response(autofix(call_model, library), run=run)
max_retries=1 by default. buffer=True holds the program back until it validates, so users never see a broken UI (they see nothing until it's ready). To check a program yourself:
from genui.lang import parse
result = parse(text, library.to_spec())
result.errors # structured errors with hints you can feed back to the model
StreamParser gives you snapshots while the reply streams. It re-reads only new text and reuses the statements it has already finished.
Server-side history
For agents that take actions, don't trust the history the browser sends. genui.threads keeps each conversation on your server: only the new user turn is read from the request, and the reply is stored when the stream finishes.
from genui.threads import MemoryThreadStore, history, record
store = MemoryThreadStore() # or Redis / Postgres: examples/threads
@app.post("/api/chat")
async def chat(request: Request, user=Depends(current_user)):
run = await read_run(request)
key = f"{user.id}:{run.thread_id}" # scope threads to the signed-in user
messages = await history(store, key, run)
stream = await client.chat.completions.create(model=MODEL, messages=[system, *messages], stream=True)
return stream_response(record(store, key, run, stream, include_tools=True), run=run)
include_tools=True also stores the tool calls your server ran and their results, so later turns know what was done. A turn that fails is not stored. Ready-made Redis and Postgres stores and a full app are in examples/threads.
Token costs
Each component adds ~55 tokens to the system prompt, and the OpenUI Lang rules cost ~500–1,100. A UI program is ~150–700 tokens, about 20–45% fewer than the same UI as JSON. A full Wander booking costs ~$0.025 on Gemini 3 Flash. docs/saving-tokens.md explains how to estimate your app and how to cut cost: prompt caching, compacting old UI programs in history, smaller per-agent libraries.
Message protocol
genui.messages reads and writes OpenUI's stored-message format (]]>openui:content marker lines), turns button clicks into model-ready turns, and strips markers before anything reaches the model.
Security
The chat history in each request comes from the browser, so genui treats it as untrusted:
-
Only
userandassistantturns reach your model.read_run()dropssystem,developerandtoolturns and client-senttoolCalls, so a user can't inject a system prompt or fake a tool result. Opt in withread_run(request, roles=(...), tool_calls=True)only if you verify those turns against server-side history. -
Request limits.
read_run()rejects bodies over 2 MB (HTTP 413) and keeps the newest 200 messages / 500,000 characters. Change these withmax_bytes,max_messagesandmax_chars. -
Never pass
run.toolsor uncheckedrun.extrafields (such as a model name) to your LLM. Check them against an allowlist. -
Errors stay on the server. An exception in your agent is logged (logger
genui) and the browser sees a genericRUN_ERROR. Usestream_response(..., expose_errors=True)in development, or yieldStreamError("...")for a message you want users to see. -
Bounded parsing.
genui.lang.parse()stops with aparse-exceptiononce a program expands past 200,000 values, so a short program that keeps doubling its references can't hang your server. -
Frontend.
GenUIChatopens@OpenUrllinks only forhttp(s),mailto,teland relative URLs, always withnoopener. History inlocalStorageis plain text: callclearChatHistory()on logout, or usestorageKey={false}or server storage for sensitive data. Dependency advisories. OpenUI's dependencies pull in an oldkatex(GHSA-238p-pmpm-9mq7). Fix it with an npm override in your app'spackage.json(overrides only apply in apps, not libraries):"overrides": { "katex": "^0.19.1" }
They also pull in
zod3.x through@ag-ui/core(GHSA-mrhx-c7xc-m3w5, memory exhaustion on oversized input). Here zod only validates the SSE events your own backend sends, so exploiting it needs control of your server's stream. Don't override it to zod 4: the app still runs, but@ag-ui/core's types turn intounknown. The fix has to come from an OpenUI release on@ag-ui/core1.x.
Status
Alpha. API may change before 1.0. Roadmap: Markdown → UI "beautify" mode.
Brand
Logo files are in assets/: logo.svg (icon), logo-wordmark-{light,dark}.svg, PNG sizes, and social-preview.png (1280×640) for the GitHub repo card.
License
MIT. The OpenUI spec and fixtures in spec/ are © Thesys, MIT — see spec/NOTICE.md.
Metadata
Release files for genui-py 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| genui_py-0.2.0.tar.gz | 84.4 kB | With provenance | Details for genui_py-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| genui_py-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for genui_py-0.2.0-py3-none-any.whl |
Total release size: 181.9 kB
Release files / genui_py-0.2.0.tar.gz
| Download URL | genui_py-0.2.0.tar.gz |
|---|---|
| Size | 84.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
710203f0fae8c73de597ed596e25ecce2539bbabf6fdeaaab7ea6c85b2b3a057
|
|
BLAKE2b-256 checksum How to use checksums |
c41715715b28ba66b178c67b6fc8330c2205cc2d6a49386f92da24f27afb1d77
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 31, 2026.
Transparency logRelease files / genui_py-0.2.0-py3-none-any.whl
| Download URL | genui_py-0.2.0-py3-none-any.whl |
|---|---|
| Size | 97.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f842b517b22c8a63e2a2f3dd680b0683532200e97dee0dbf08a932b5f0813a24
|
|
BLAKE2b-256 checksum How to use checksums |
3a34e5cd7a641c3a6154220e28f2234dd480535fe20a1598d4ea27789fda9db1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 31, 2026.
Transparency logSecurity for genui-py 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for genui_py-0.2.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 31, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.