Citry 1.0.0: the Python web is getting safer, faster and smarter
Build interactive web apps in Python with typed components, fast pages and an editor that catches your mistakes, all from one Python codebase.
It's here. Citry 1.0.0 is out, and it's stable. 🎉
pip install citry
I've been waiting to write this post for a long time.
Two to three years ago I worked on a Django web app. When building the frontend, there were two options:
Django or Jinja templates
Simple and easy to pick up, but with no type checking and no isolation between components. Mistakes were easy to make, and you found them when someone opened the page.
Separate JavaScript frontend in Vue or React
Great tooling and developer experience. But now you had two projects to manage, the Python one and the JavaScript one.
There were projects that tried to make the Python frontend experience less frustrating - ReactPy, Reflex, FastHTML... - and they succeeded to varying degree.
But it was still a far cry from the ease of development I knew from working with Vue (and React) for many years:
- Easy to reason about components thanks to isolation and having everything in a single file.
- Smart IDE integration that understands my components, their inputs, etc.
- Linter catching errors during development.
- And much, much more...
Those ~3 years ago I started helping on out django-components (created by Emil Stenström), a Django plugin that offered a component-like experience for templates.
Fast forward, and the new library, Citry, now fills that gap I missed. You now get high-end frontend tooling, the kind Vue and React developers take for granted, in a single Python codebase.
With v1, Citry is now ready to be used in production.
There's still so much more I want to build to make the Python frontend experience the best it can be. See the roadmap.
If you want to see more of my work in the future, please support this project here, or reach out to me.
- Come say hi and ask questions on Discord.
- Report bugs and ask for features in GitHub issues.
A huge thank you to everyone who helped or support this project. You made this possible. And if you build something with Citry, please show me. I'd love to see it. ❤️
What Citry is
A Citry component is a Python class. It holds its HTML template, its browser behavior (in Vue), its CSS, its translations, and the Python methods that run when the visitor clicks or submits something. One component, one file, one codebase. No separate frontend project.
Here's a like button that runs Python when you click it:
from citry import Component
class LikeButton(Component):
class Kwargs:
product_id: int
likes: int = 0
class State(Kwargs):
pass
class Events:
def like(self, state: LikeButton.State):
save_like(state.product_id)
return LikeButton(
product_id=state.product_id,
likes=state.likes + 1,
)
def template_data(self, kwargs: Kwargs, slots):
return {"likes": kwargs.likes}
template = """
<button type="button" @c-click="like">
Like ({{ likes }})
</button>
"""
css = """
button {
border-radius: 8px;
}
"""
The click calls like() on the server, and Citry swaps in the new button. No JavaScript to write, no API endpoint to add.
It runs with FastAPI, Django, Flask, Starlette, or any ASGI or WSGI app, on Python 3.11 to 3.15.
Safe from the start
Security is a huge problem these days because of AI.
A new framework simply doesn't have the accumulated knowledge of an established one.
But while AI is speeding up the rate of cyber threats, it's also speeding up the rate at which we can protect ourselves.
To make Citry reasonably battle-tested from day one, I turned to the wider frontend ecosystem, and audited Citry against all their known vulnerabilities.
456 security advisories that other frameworks published - Django, Next.js, Nuxt, React and Vue among them - and checked Citry for every kind of bug that could apply to it. How we check advisories walks through the process.
To handle new vulnerabilities, a monthly cron job checks for new ones.
See Security for practical details and limitations.
Fast
Citry is fast. Really fast.
- Before the page request
- Server builds the page
- Other request time
- Page download
- Browser work and later requests
- Wait for the next layout
Show the numbers as a table
| Framework | Before the page request | Server builds the page | Other request time | Page download | Browser work and later requests | Wait for the next layout | Total |
|---|---|---|---|---|---|---|---|
| Citry | 0.6 | 71.4 | 1.2 | 7.4 | 159.4 | 17.3 | 257.3 |
| Django + HTMX + Alpine | 0.6 | 52.8 | 0.9 | 1.7 | 270.4 | 15.5 | 341.9 |
| Rusty + HTMX + Alpine | 0.7 | 17.0 | 0.7 | 1.2 | 267.9 | 8.6 | 296.1 |
| Jinja + HTMX + Alpine | 0.7 | 22.1 | 0.6 | 0.7 | 270.3 | 5.4 | 299.8 |
| Tetra | 0.7 | 117.3 | 0.8 | 1.0 | 199.9 | 5.8 | 325.5 |
| django-unicorn | 0.7 | 102.6 | 0.8 | 0.9 | 394.4 | 9.1 | 508.5 |
| django-components | 0.7 | 198.0 | 0.9 | 1.0 | 268.6 | 5.8 | 475.0 |
| FastHTML | 0.7 | 371.4 | 0.3 | 9.5 | 265.6 | 19.2 | 666.7 |
| ReactPy | 0.6 | 6.0 | 0.5 | 0.1 | 873.7 | 29.4 | 910.3 |
| Reflex | 0.8 | 0.5 | 0.4 | 0.5 | 385.2 | 21.6 | 409.0 |
| Next.js | 0.7 | 51.6 | 0.4 | 7.5 | 240.3 | 23.7 | 324.2 |
| Nuxt | 0.6 | 22.4 | 3.6 | 8.2 | 185.0 | 9.7 | 229.5 |
In our own test, a page with 1,400 entries was usable in 257 ms on its second load. That's ahead of Next.js (324 ms) and of the Django stack with django-components (475 ms), and just behind Nuxt (230 ms). All from one Python codebase.
I wrote the same app in Citry and in eleven other frameworks, see the Benchmarks page for full details.
Smart
This is the part I missed most from Vue and TypeScript: tools that understand your code and tell you about a mistake the moment you make it.
In Django templates, mistakes stay quiet. Misspell a variable and the page renders an empty spot. Pass a wrong input to a component and nothing complains. You find out only when someone opens the page, or when a customer tells you - and that's already too late.
In Citry, every component spells out what it takes, and Citry checks every template against it. Your editor knows your components too. It suggests their inputs as you type, shows their types when you hover, and jumps from a template straight to the Python definition. A typo gets underlined right away.
The same checks can be run in CI, to ensure you never ship a mistake. Just call citry check.
This matters even more now that AI writes a big part of our code. An AI agent makes the same small mistakes we do, just faster. When the framework catches them, the agent sees the error and fixes it itself, before you ever review the code.
To see how much this catches, I planted the same 63 mistakes in the app for each framework:
- Static/IDE error
- Static/IDE warning
- Runtime error
- Runtime warning
- Missed
Citry reported 56 of the 61 that apply to it before the app ever ran, more than any other framework I tested, Next.js with TypeScript included.
Try it
- Play with it right now in the browser, nothing to install: the playground.
- Build your first component: Getting started.
- Install with
pip install citry
Versioning and support
Citry now follows SemVer - what the docs describe keeps working throughout 1.x releases.
django-components has now entered the maintenance mode. It will receive updates to remain compatible with supported Python and Django versions.
The UI library, citry-ui, is still in development, so pin one minor release, such as "citry-ui>=0.6.0,<0.7". The exact rules are in Versioning and support.
Coming from django-components?
You don't have to move everything at once: citry-django, a community project by Joey Jurjens, lets Citry components and your existing Django templates live side by side, so you can migrate one component at a time. The migration guide shows what changes.
Upgrading from earlier versions
Citry:
- Upgrade to the newest 0.9.x and follow its upgrade notes.
- Upgrade to 1.0.0:
pip install -U citry.
Step by step: Upgrade to Citry 1.0.0.
VSCode extension:
citry-lsp, the VS Code extension and pygments-citry are at 1.0.0 too; upgrade citry-lsp and the extension together.
Citry UI:
citry-ui 0.6.0 needs Citry 1.0.0 or later.
About the author
I'm Juro Oravec. Citry grew out of my years of work on django-components, and it's everything I wished django-components could be. I built it over the past year, working with AI coding agents, and I'm going to keep pushing it forward.