ランキングに戻る

pydantic/FastUI

Pythonfastui-demo.onrender.com

Build better UIs faster.

fastapipydanticpythonreact
スター成長
スター
9k
フォーク
340
週間成長
Issue
120
4k6k8k
2023年12月2024年10月2025年9月2026年7月
成果物PyPIpip install fastui
README

NOTE: this project is inactive, see #368

FastUI

Find the documentation here. Join the discussion in the #fastui slack channel here

CI pypi versions license

Please note: FastUI is still an active work in progress, do not expect it to be complete.

The Principle (short version)

You can see a simple demo of an application built with FastUI here.

FastUI is a new way to build web application user interfaces defined by declarative Python code.

This means:

  • If you're a Python developer — you can build responsive web applications using React without writing a single line of JavaScript, or touching npm.
  • If you're a frontend developer — you can concentrate on building magical components that are truly reusable, no copy-pasting components for each view.
  • For everyone — a true separation of concerns, the backend defines the entire application; while the frontend is free to implement just the user interface

At its heart, FastUI is a set of matching Pydantic models and TypeScript interfaces that allow you to define a user interface. This interface is validated at build time by TypeScript and pyright/mypy and at runtime by Pydantic.

The Practice — Usage

FastUI is made up of 4 things:

Here's a simple but complete FastAPI application that uses FastUI to show some user profiles:

from datetime import date

from fastapi import FastAPI, HTTPException
from fastapi.responses import HTMLResponse
from fastui import FastUI, AnyComponent, prebuilt_html, components as c
from fastui.components.display import DisplayMode, DisplayLookup
from fastui.events import GoToEvent, BackEvent
from pydantic import BaseModel, Field

app = FastAPI()


class User(BaseModel):
    id: int
    name: str
    dob: date = Field(title='Date of Birth')


# define some users
users = [
    User(id=1, name='John', dob=date(1990, 1, 1)),
    User(id=2, name='Jack', dob=date(1991, 1, 1)),
    User(id=3, name='Jill', dob=date(1992, 1, 1)),
    User(id=4, name='Jane', dob=date(1993, 1, 1)),
]


@app.get("/api/", response_model=FastUI, response_model_exclude_none=True)
def users_table() -> list[AnyComponent]:
    """
    Show a table of four users, `/api` is the endpoint the frontend will connect to
    when a user visits `/` to fetch components to render.
    """
    return [
        c.Page(  # Page provides a basic container for components
            components=[
                c.Heading(text='Users', level=2),  # renders `<h2>Users</h2>`
                c.Table(
                    data=users,
                    # define two columns for the table
                    columns=[
                        # the first is the users, name rendered as a link to their profile
                        DisplayLookup(field='name', on_click=GoToEvent(url='/user/{id}/')),
                        # the second is the date of birth, rendered as a date
                        DisplayLookup(field='dob', mode=DisplayMode.date),
                    ],
                ),
            ]
        ),
    ]


@app.get("/api/user/{user_id}/", response_model=FastUI, response_model_exclude_none=True)
def user_profile(user_id: int) -> list[AnyComponent]:
    """
    User profile page, the frontend will fetch this when the user visits `/user/{id}/`.
    """
    try:
        user = next(u for u in users if u.id == user_id)
    except StopIteration:
        raise HTTPException(status_code=404, detail="User not found")
    return [
        c.Page(
            components=[
                c.Heading(text=user.name, level=2),
                c.Link(components=[c.Text(text='Back')], on_click=BackEvent()),
                c.Details(data=user),
            ]
        ),
    ]


@app.get('/{path:path}')
async def html_landing() -> HTMLResponse:
    """Simple HTML page which serves the React app, comes last as it matches all paths."""
    return HTMLResponse(prebuilt_html(title='FastUI Demo'))

Which renders like this:

screenshot

Of course, that's a very simple application, the full demo is more complete.

Components

FastUI already defines a rich set of components.

All components are listed in the demo app.

The Principle (long version)

FastUI is an implementation of the RESTful principle; but not as it's usually understood, instead I mean the principle defined in the original PhD dissertation by Roy Fielding, and excellently summarised in this essay on htmx.org (HTMX people, I'm sorry to use your article to promote React which I know you despise 🙏).

The RESTful principle as described in the HTMX article is that the frontend doesn't need to (and shouldn't) know anything about the application you're building. Instead, it should just provide all the components you need to construct the interface, the backend can then tell the frontend what to do.

Think of your frontend as a puppet, and the backend as the hand within it — the puppet doesn't need to know what to say, that's kind of the point.

Building an application this way has a number of significant advantages:

  • You only need to write code in one place to build a new feature — add a new view, change the behavior of an existing view or alter the URL structure
  • Deploying the front and backend can be completely decoupled, provided the frontend knows how to render all the components the backend is going to ask it to use, you're good to go
  • You should be able to reuse a rich set of opensource components, they should end up being better tested and more reliable than anything you could build yourself, this is possible because the components need no context about how they're going to be used (note: since FastUI is brand new, this isn't true yet, hopefully we get there)
  • We can use Pydantic, TypeScript and JSON Schema to provide guarantees that the two sides are communicating with an agreed schema

In the abstract, FastUI is like the opposite of GraphQL but with the same goal — GraphQL lets frontend developers extend an application without any new backend development; FastUI lets backend developers extend an application without any new frontend development.

Beyond Python and React

Of course, this principle shouldn't be limited to Python and React applications — provided we use the same set of agreed schemas and encoding to communicate, we should be able to use any frontend and backend that implements the schema. Interchangeably.

This could mean:

  • Implementing a web frontend using another JS framework like Vue — lots of work, limited value IMHO
  • Implementing a web frontend using an edge server, so the browser just sees HTML — lots of work but very valuable
  • Implementing frontends for other platforms like mobile or IOT — lots of work, no idea if it's actually a good idea?
  • Implementing the component models in another language like Rust or Go — since there's actually not that much code in the backend, so this would be a relatively small and mechanical task
関連リポジトリ
fastapi/fastapi

FastAPI framework, high performance, easy to learn, fast to code, ready for production

PythonPyPIMIT Licensepythonjson
fastapi.tiangolo.com
100.8k9.7k
headroomlabs-ai/headroom

Compress tool outputs, logs, files, and RAG chunks before they reach the LLM. 20% fewer tokens for coding agents, 60-95% fewer tokens for JSON, same answers. Library, proxy, MCP server.

PythonPyPIApache License 2.0agentai
headroom-docs.vercel.app/docs
61k4.6k
fastapi/full-stack-fastapi-template

Full stack, modern web application template. Using FastAPI, React, SQLModel, PostgreSQL, Docker, GitHub Actions, automatic HTTPS and more.

TypeScriptnpmMIT Licensepythonjson
44.4k8.8k
mouredev/Hello-Python

Curso para aprender el lenguaje de programación Python desde cero y para principiantes. 100 clases, 44 horas en vídeo, código, proyectos y grupo de chat. Fundamentos, frontend, backend, testing, IA...

PythonPyPIApache License 2.0fastapimongodb
mouredev.link/python
36.5k2.3k
jina-ai/serve

☁️ Build multimodal AI applications with cloud-native stack

PythonPyPIApache License 2.0neural-searchcloud-native
jina.ai/serve
21.9k2.2k
Zeyi-Lin/HivisionIDPhotos

⚡️HivisionIDPhotos: a lightweight and efficient AI ID photos tools. 一个轻量级的AI证件照制作算法。

PythonPyPIApache License 2.0demogradio
modelscope.cn/studios/SwanLab/HivisionIDPhotos
21.3k2.4k
Evil0ctal/Douyin_TikTok_Download_API

🚀「Douyin_TikTok_Download_API」是一个开箱即用的高性能异步抖音、快手、TikTok、Bilibili数据爬取工具,支持API调用,在线批量解析及下载。

PythonPyPIApache License 2.0pythonpywebio
douyin.wtf
18.9k2.7k
fastapi/sqlmodel

SQL databases in Python, designed for simplicity, compatibility, and robustness.

PythonPyPIMIT Licensepythonsql
sqlmodel.tiangolo.com
18.2k873
zhanymkanov/fastapi-best-practices

FastAPI Best Practices and Conventions we used at our startup

fastapibest-practices
17.7k1.3k
MODSetter/SurfSense

Open-source NotebookLM alternative. Research the open web with live data, through one platform, API or MCP server. Join our Discord: https://discord.gg/ejRNvftDp9

PythonPyPIOtheraifastapi
surfsense.com
15.3k1.5k
DataTalksClub/machine-learning-zoomcamp

Learn ML engineering for free in 4 months! Register here 👇🏼

Jupyter Notebookcoursedeployment
airtable.com/shryxwLd0COOEaqXo
13.7k3.1k
JoeanAmier/XHS-Downloader

小红书(XiaoHongShu、RedNote)链接提取/作品采集工具:提取账号发布、收藏、点赞、专辑作品链接;提取搜索结果作品、用户链接;采集小红书作品信息;提取小红书作品下载地址;下载小红书作品文件

PythonPyPIGNU General Public License v3.0pythonjson
discord.com/invite/ZYtmgKud9Y
12k1.8k