Skip to main content

A FastHTML wrapper for Daisy-UI

Project description

fhdaisy

fhdaisy is a Python wrapper for DaisyUI that brings its component classes to FastHTML applications. Instead of manually writing HTML elements with DaisyUI classes like <button class="btn btn-primary">, you use Python components like Btn('Click me', cls='-primary'). The library follows a consistent pattern: every DaisyUI CSS class becomes a title-case Python component (e.g., cardCard, alertAlert), and modifiers can be shortened by dropping the redundant prefix (e.g., btn-primary-primary). Beyond the standard components, fhdaisy.xtras provides helper functions for common patterns like accordions and forms, reducing repetitive code while maintaining the flexibility to create custom helpers for your specific needs.

Usage

Installation

Install latest from pypi

$ pip install fhdaisy

Docs

To learn to use this library and see examples, please refer to the documentation.

A brief overview of the project is available in this readme, but it is not a replacement for the docs.

Brief overview

DaisyUI

DaisyUI is a component library built on top of Tailwind CSS that provides semantic class names for common UI patterns. While Tailwind offers utility classes like bg-blue-500 or p-4, DaisyUI adds higher-level component classes like btn, card, and modal that encapsulate the many utility classes typically needed for these elements. This means you can create a styled button with class="btn btn-primary" instead of combining dozens of Tailwind utilities.

For FastHTML developers, DaisyUI is particularly useful because it provides a complete design system out of the box without requiring JavaScript frameworks. The components are purely CSS-based and work perfectly with FastHTML’s server-side rendering approach. You get professional-looking components with built-in themes, responsive design, and accessibility features, while maintaining the simplicity of working with HTML elements.

Daisy basics

from fasthtml.common import *
from fasthtml.jupyter import *
from fhdaisy import *

Let’s look at a specific example of a DaisyUI component - the btn.

DaisyUI creates buttons by using a btn class, along with other special classes prefixed by btn-, eg:

c = Button('Hey there', cls='btn btn-primary')
print(c)

fhdaisy basics

Now let’s see how fhdaisy makes this simpler and more Pythonic. Instead of using generic HTML elements with DaisyUI classes, fhdaisy provides Python components that correspond directly to DaisyUI’s component classes. The key insight is that DaisyUI’s CSS class names already tell us what kind of component we’re creating - so why not use them as Python component names?

Here’s how it works: fhdaisy takes each DaisyUI base class (like btn, card, alert) and turns it into a Python component with a title-case name (Btn, Card, Alert). When you use Btn() in your code, fhdaisy automatically creates a button element with the btn class already applied.

While the component names in fhdaisy come from DaisyUI’s CSS classes, the underlying HTML elements are automatically chosen to match what DaisyUI requires. Each component knows its correct HTML tag - Btn creates a <button>, Alert creates a <div>, Input creates an <input>, and so on. This mapping follows DaisyUI’s own documentation and ensures your components work correctly with all of DaisyUI’s styling and behavior.

Additional convenience comes with modifiers. In DaisyUI, you style a button by adding classes like btn-primary, btn-outline, or btn-sm. Notice how they all repeat the btn- prefix? With fhdaisy, you can use a shorthand notation in the cls parameter: just write -primary, -outline, or -sm. The component knows it’s a Btn, so it automatically adds the btn- prefix back when generating the HTML. This means less typing, less repetition, and cleaner code that’s easier to read and maintain.

Let’s see this in action with the same btn as before:

c = Btn('Hey there', cls='-primary')
print(c)
<button class="btn btn-primary ">Hey there</button>

This renders identically to the previous manual version.

With fhdaisy, the pattern is consistent: use the title-case version of the DaisyUI class name as your component. So input becomes Input; fhdaisy automatically adds the base input class when you use the Input component. Any modifiers like input-bordered can be shortened to just -bordered in the cls parameter.

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

fhdaisy-0.0.1.tar.gz (12.1 kB view details)

Uploaded Source

Built Distribution

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

fhdaisy-0.0.1-py3-none-any.whl (11.3 kB view details)

Uploaded Python 3

File details

Details for the file fhdaisy-0.0.1.tar.gz.

File metadata

  • Download URL: fhdaisy-0.0.1.tar.gz
  • Upload date:
  • Size: 12.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for fhdaisy-0.0.1.tar.gz
Algorithm Hash digest
SHA256 cd5dc4567a1f4125a784264a4d26c86131d4ce134a25544c0f58c8331e1221c4
MD5 e202fd77e172693873389c63edee09bd
BLAKE2b-256 c5be41c9b0c1c68a230713125ac8f7875684a2c19de5f015003245031451240a

See more details on using hashes here.

File details

Details for the file fhdaisy-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: fhdaisy-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 11.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for fhdaisy-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a971bc7029d92ee26d833518d9531aa806f3abb57b78cd65310fdb63bdd4b2ae
MD5 026190565b0c573df3913e9ec43dd647
BLAKE2b-256 acc85d0c411c9abd9fff122f787acf5f59cb29a6cb326686e4476f8e4295610a

See more details on using hashes here.

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