Skip to main content

Wrap a Python function and get an instant web UI.

Project description

InstantUI

Wrap a Python function with a decorator and get an instant web UI. Zero runtime dependencies.

import instantui

@instantui.app
def greet(name: str = "world", times: int = 1, shout: bool = False) -> str:
    """Greet someone a few times."""
    msg = " ".join([f"Hello {name}!"] * times)
    return msg.upper() if shout else msg

if __name__ == "__main__":
    instantui.run(title="Hello")

Run it, open http://127.0.0.1:8000, and you get a form per function — typed inputs, captured stdout, and a return value rendered as text, JSON, markdown, an image, or a table depending on what you return.

Install

pip install instantui

Two flavors of card

Form cards — @instantui.app

A parameterized function turns into a form. Submit it and you see the return value.

@instantui.app
def add(a: int, b: int = 1) -> int:
    return a + b

Chat cards — @instantui.chat

A function with a message parameter (and optionally history) turns into a chat panel — message log, input box, typing indicator. History is held in the browser and re-sent on each turn, so the server stays stateless.

@instantui.chat
def my_bot(message: str, history: list[dict]) -> str:
    # history items look like {"role": "user" | "assistant", "content": str}
    return f"echo: {message}"

history matches the OpenAI/Anthropic message shape, so you can pass it straight to an LLM SDK — see examples/chat.py for a sketch.

Form and chat cards can live on the same page.

Inputs

Annotation Rendered as
str text input
int number input
float number input, step=any
bool checkbox
datetime.date native date picker
datetime.datetime datetime-local picker
Literal["a", "b"] dropdown
Enum subclass dropdown
Annotated[str, instantui.Multiline] textarea

Unannotated parameters fall back to str. Defaults are pre-filled in the form.

Outputs

Whatever you return is auto-rendered. Wrappers let you opt into richer rendering.

Return value Rendered as
str, int, float, bool, None plain text
dict, list pretty-printed JSON
list[dict] HTML table
pandas.DataFrame HTML table (auto-detected, no hard dep)
instantui.Markdown("…") rendered markdown
instantui.HTML("…") raw HTML (escape-free, opt-in)
instantui.Image(bytes | path | PIL.Image) inline image
pathlib.Path download link (or inline if an image)
an exception red error block with traceback

Anything written to stdout during the call is shown in a separate block above the return value.

Customizing the page

instantui.run(host="127.0.0.1", port=8000, title="My App", open_browser=True)

title is shown as the page heading. The small "InstantUI" brand mark stays in the top-left nav regardless.

CLI

instantui PATH [--host HOST] [--port PORT] [--title TITLE] [--no-browser]

The script is loaded with runpy.run_path, so any top-level @instantui.app / @instantui.chat decorator runs at import time.

instantui examples/calculator.py --port 8080 --title "Calc"

Documentation

Full docs live under docs/:

Examples

Project layout

src/instantui/
├── core/         registry · introspection · casting
├── server/       BaseHTTPRequestHandler · runner
├── rendering/    HTML renderer · templates/ · static/
├── output.py     return-value → typed block
├── types.py      Markdown · HTML · Image · Multiline
├── cli.py        `instantui script.py`
└── exceptions.py

Each subpackage is independently testable. The HTTP server uses only http.server from the standard library; Pillow and pandas are auto-detected at runtime if installed but never required.

Development

pip install -e ".[dev]"
pytest
ruff check .
mypy

53 tests on Python 3.9 – 3.12, Linux / macOS / Windows in CI.

Status

Alpha. The @instantui.app / @instantui.chat / run() contract is stable; internals may still move.

License

MIT

Project details


Download files

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

Source Distribution

instantui-0.1.0.tar.gz (26.1 kB view details)

Uploaded Source

Built Distribution

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

instantui-0.1.0-py3-none-any.whl (25.1 kB view details)

Uploaded Python 3

File details

Details for the file instantui-0.1.0.tar.gz.

File metadata

  • Download URL: instantui-0.1.0.tar.gz
  • Upload date:
  • Size: 26.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.5

File hashes

Hashes for instantui-0.1.0.tar.gz
Algorithm Hash digest
SHA256 84e27200d48e39ac713f33aab94dfcf0b445b0dbdb4f2c9b7c9ee861c3e0d1c9
MD5 bf7af2d82b498313adcbfca1bcb916c2
BLAKE2b-256 1e5e8c0487d00f82833cdc6fbc16d25bd8e896b6884f06909cff68c35fb6fbd9

See more details on using hashes here.

File details

Details for the file instantui-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: instantui-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 25.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.5

File hashes

Hashes for instantui-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 96c87838366afd8e9c61a06a5a361ae5e14952e04bd198f56512516c9bc09812
MD5 784af480c94687488e29135032dec123
BLAKE2b-256 248732eb1e46b865d1dc5239e9ac869f2c8741a9984e9563119847b3e3db2208

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 Pingdom Monitoring Sentry Error logging StatusPage Status page