Skip to main content

Build UIs quickly with Jinga2, FastAPI, Pydantic, htmx, and a little bit of magic

Project description

Overview

QuikUI is a library for contextual server-side rendering of Pydantic models into HTML components, using Jinja2 for template-based rendering, and designed to work seamlessly with FastAPI-based apps. One of the main benefits of QuikUI is that it allows you to create completely custom HTML for your models just by subclassing quikui.BaseComponent in your model's class heirarchy, allowing you to easily integrate HTML rendering into your existing FastAPI applications by just adding the quikui.render_component decorator. Further, this rendering is contextual using a heuristic on FastAPI requests, such that if a web browser makes a request to a supported endpoint in your app, the app will respond with rendered html instead of converting your model to JSON in response.

Installation

To install QuikUI, use pip or your favorite package installation tool:

$ pip install quikui

Example

We have example in this repository that you can run via:

uvicorn example:app

Usage

It is recommended that you subclass quikui.BaseComponent in a base class used by your heirarchy, so that you can configure your own template directory:

import quikui as qk


class Component(qk.BaseComponent):
    quikui_template_package_name = "your_package_name"
    # a folder called `templates/` under this package should contain your html templates


# Now you can subclass `Component` to enable rendering of your models.

Models are rendered according to their class name, so if you have a class like:

class MyModel(Component, ...):
    a_field: str = Field(...)  # Works with any Pydantic Model type
    ...

Then it is expected to have a file under your package's template directory named MyModel.html:

{# This is a Jinj2 template #}
<{{ __quikui_component_name__ }} class="{{ quikui_css_classes }}" {{ quikui_extra_attributes }}>
  {{ a_field }}
...

The template can use any named field of your model (the type is not converted, so handle accordingly), or it can the QuikUI-provided fields __quikui_component_name__ (the name of the model e.g. MyModel), quikui_css_classes (which is the set of CSS classes that should be added), and quikui_extra_attributes (which is a rendered "safe" string of html attributes in k="v" format, including the class attribute).

Additionally, there are two extra fields that are injected into your model when subclassing (which are hidden from your model export via model_dump and model_dump_json) that you should use to customize your objects: attrs=dict(...) (a mapping of html5-compatible string attribute names to string or bool values) and css=set(...) (a set of string css class names to concatenate together).

Contributing

Open an issue.

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

quikui-0.3.0.tar.gz (23.8 kB view details)

Uploaded Source

Built Distribution

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

quikui-0.3.0-py3-none-any.whl (23.6 kB view details)

Uploaded Python 3

File details

Details for the file quikui-0.3.0.tar.gz.

File metadata

  • Download URL: quikui-0.3.0.tar.gz
  • Upload date:
  • Size: 23.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for quikui-0.3.0.tar.gz
Algorithm Hash digest
SHA256 786eed18811a9ab74a62f0afa20c0dc8e04674ffaedb2486986f8d81340ddf4d
MD5 ac4292292d42320b8383264ce8ebe1f3
BLAKE2b-256 e72d6523df5a290e17c61bedf7b8a23d830346c1dc7a4119a33b7ada36acfdd3

See more details on using hashes here.

Provenance

The following attestation bundles were made for quikui-0.3.0.tar.gz:

Publisher: publish.yaml on fubuloubu/QuikUI

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file quikui-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: quikui-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 23.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for quikui-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c72965aa24191e6e7374843b2a90507278253bacc394e482bab3f401af4e9952
MD5 201ca2c18c7e710c0b158325c9840fd2
BLAKE2b-256 3c2e8961d69c42793e31857bdc3bbe979091056e671efcf3d63f0355efc98db1

See more details on using hashes here.

Provenance

The following attestation bundles were made for quikui-0.3.0-py3-none-any.whl:

Publisher: publish.yaml on fubuloubu/QuikUI

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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