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):
    html_template_package = "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 #}
{{ __component_name__ }} {{ __extra_attrs__ }}
  {{ 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 __component_name__ (the name of the model e.g. MyModel) and __extra_attrs__ (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.1.0b0.tar.gz (19.1 kB view details)

Uploaded Source

Built Distribution

QuikUI-0.1.0b0-py3-none-any.whl (18.9 kB view details)

Uploaded Python 3

File details

Details for the file QuikUI-0.1.0b0.tar.gz.

File metadata

  • Download URL: QuikUI-0.1.0b0.tar.gz
  • Upload date:
  • Size: 19.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for QuikUI-0.1.0b0.tar.gz
Algorithm Hash digest
SHA256 f1f7549acf7f12dffd2b0dedd590f0dc4e62fde3763dfaabdef54f176afd8b65
MD5 272ab721db114aeb8457584915a6bfdc
BLAKE2b-256 c6801d08eba7a92367eb11e4d07096ed57d5f0c84a0a052db1aadd1f1eff795b

See more details on using hashes here.

File details

Details for the file QuikUI-0.1.0b0-py3-none-any.whl.

File metadata

  • Download URL: QuikUI-0.1.0b0-py3-none-any.whl
  • Upload date:
  • Size: 18.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for QuikUI-0.1.0b0-py3-none-any.whl
Algorithm Hash digest
SHA256 c57c119abbccaa974582d87ad06c414733b210972baaa66629fb4a5d18834251
MD5 b79c5a75aeb804cbe0cd3596cbc71ea9
BLAKE2b-256 e33c291713b4a6668a15fb886478cb854cc9d95eae2b03ad0f2588a8bf7de6ce

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page