# Ludic
> Ludic lets you write HTML as typed Python components. The type checker validates the markup, so wrong nesting, unknown attributes and missing arguments are caught before a page renders. Ludic only renders HTML, so it fits into Starlette, FastAPI, Django or any other framework, and it pairs with htmx.
Rules for writing Ludic code:
- Ludic 1.x needs Python 3.14+ and mixes text with elements in t-strings: `p(t"Hello {b('World')}!")`. Use f-strings only in projects on Ludic 0.5.x (Python 3.12 and 3.13), which renders elements inside f-strings.
- Set `plugins = ["ludic.mypy_plugin"]` for mypy and run mypy after changes. Only mypy with the plugin checks the attributes passed to components.
- Text children are escaped. Wrap only trusted HTML in `Safe`, never user input.
- The HTTP methods of an `Endpoint` (`get`, `post`, `put`, ...) are classmethods that usually return `Self`; `render()` builds the HTML.
- Read form data with a handler parameter typed `Parser[SomeAttrs]` and call `.validate()`, which returns the TypedDict or raises a 400 `ValidationError`.
- Use `request.url_path_for(...)` or the `.path` of `url_for(...)` in links and `hx_*` attributes, so a forged Host header cannot change them.
- Prefer the catalog (`ludic.catalog.pages`, `layouts`, `forms`, `tables`) to building pages from raw `div` elements.
## Documentation
- [Introduction](https://getludic.dev/docs/index.md): What Ludic is, its features, a comparison with htpy, FastHTML, tdom and Jinja2, requirements and installation.
- [Getting Started](https://getludic.dev/docs/getting-started.md): Install Ludic, create a first app with LudicApp and run it.
- [Components](https://getludic.dev/docs/components.md): HTML elements, Component and ComponentStrict, typed attributes, t-strings and the available helper types.
- [Styles and Themes](https://getludic.dev/docs/styles.md): Component styles, the style element and attribute, loading and caching CSS, and themes.
- [HTMX Support](https://getludic.dev/docs/htmx.md): Typed htmx attributes, loading htmx in a page, swap operations, response headers and inline JavaScript.
- [Web Framework](https://getludic.dev/docs/web-framework.md): Routing, function and class-based endpoints, form parsers, error handlers, exceptions, WebSockets and testing.
- [Other Integrations](https://getludic.dev/docs/integrations.md): Return Ludic elements from FastAPI and Django views.
## Catalog
- [Basics](https://getludic.dev/catalog/index.md): How the catalog works, how its CSS is loaded and how to create the base page component.
- [Layouts](https://getludic.dev/catalog/layouts.md): Stack, Box, Center, Cluster, Sidebar, Switcher, Cover, Grid and Frame layouts based on the Every Layout book.
- [Typography](https://getludic.dev/catalog/typography.md): Links, paragraphs, inline code, code blocks, key-value pairs, lists and headers with anchors.
- [Buttons](https://getludic.dev/catalog/buttons.md): Button variants, button links and sizes.
- [Messages](https://getludic.dev/catalog/messages.md): Info, success, warning and danger message boxes.
- [Forms](https://getludic.dev/catalog/forms.md): Input, select, text area and choice fields, forms, and fields generated from an Attrs TypedDict.
- [Tables](https://getludic.dev/catalog/tables.md): Typed tables, and table rows generated from data.
- [Loaders](https://getludic.dev/catalog/loaders.md): A loading indicator and LazyLoader, which loads content after the page renders.
## Examples
- [Components](https://getludic.dev/examples/index.md): Custom components with styles: a link, a navigation and a search bar.
- [Complex Layout](https://getludic.dev/examples/complex-layout.md): A page layout composed from the catalog layouts.
- [Bulk Update](https://getludic.dev/examples/bulk-update.md): Activate or deactivate several table rows with one form.
- [Click to Edit](https://getludic.dev/examples/click-to-edit.md): Switch a record to an edit form and save it with PUT.
- [Click to Load](https://getludic.dev/examples/click-to-load.md): Load the next page of table rows with a button.
- [Delete Row](https://getludic.dev/examples/delete-row.md): Delete a table row after a confirmation.
- [Edit Row](https://getludic.dev/examples/edit-row.md): Edit a single table row inline.
- [Infinite Scroll](https://getludic.dev/examples/infinite-scroll.md): Load more rows when the last one scrolls into view.
- [Lazy Loading](https://getludic.dev/examples/lazy-loading.md): Load slow content after the page renders.
- [FastAPI Example](https://getludic.dev/examples/cascading-selects.md): Cascading select fields in a FastAPI app.
## Optional
- [All pages in one file](https://getludic.dev/llms-full.txt): The documentation, catalog and examples above as one Markdown file.
- [README](https://github.com/getludic/ludic/blob/main/README.md): Overview, type checking errors, framework integrations and a comparison with other libraries.
- [Agent skill: ludic-components](https://github.com/getludic/ludic/blob/main/skills/ludic-components/SKILL.md): How to write components, use the catalog and check the code with mypy.
- [Agent skill: ludic-web](https://github.com/getludic/ludic/blob/main/skills/ludic-web/SKILL.md): How to write endpoints, parse forms, return htmx responses and build safe URLs.
- [Examples on GitHub](https://github.com/getludic/ludic/tree/main/examples): Runnable htmx patterns written with Ludic.