Skip to main content

LazyFast = FastAPI + HTMX + Component-based approach + State management

Project description

LazyFast

LazyFast is a lightweight Python library designed for building modern web interfaces using a component-based approach. It enables writing page logic on the server side in Python, integrating seamlessly with FastAPI. With LazyFast, interactive elements like inputs, buttons, and selects trigger component reloads that occur on the server, updating the component's state dynamically.

Key Features

  1. Component-Based Server Rendering: Build web interfaces using lazy loaded components that encapsulate logic, state, and presentation.
  2. Server-Side Logic: Handle interactions and state management on the server, reducing client-side complexity.
  3. FastAPI Integration: Each component or page is a FastAPI endpoint, allowing for dependency injection and other FastAPI features.
  4. Lightweight: The only dependencies are FastAPI for Python and HTMX for JavaScript, which can be included via CDN.
  5. State Management: Utilize a state manager that can trigger component reloads, ensuring a reactive user experience.

Installation

To install LazyFast, use pip:

pip install lazyfast

or

poetry add lazyfast

Quick Start

Here's an example application to demonstrate how LazyFast works:

from fastapi import FastAPI, Request
from lazyfast import LazyFastRouter, Component, tags


# LazyFastRouter inherits from FastAPI's APIRouter
router = LazyFastRouter()

# Define a lazy-loaded HTML component powered by HTMX
@router.component()
class MyComponent(Component):
    title: str

    async def view(self, request: Request) -> None:
        tags.h1(self.title, class_="my-class")

        with tags.div(style="border: 1px solid black"):
            tags.span(request.headers)

# Initialize the page dependencies for component rendering
# The page endpoint is also a FastAPI endpoint
@router.page("/{name}")
def root(name: str):
    with tags.div(class_="container mt-6"):
        MyComponent(title=f"Hello, World from {name}")

# Embed the router in a FastAPI app
app = FastAPI()
app.include_router(router)

If you use uvicorn instead as a server and want to reload on changes, use the following command:

uvicorn app:app --reload --timeout-graceful-shutdown 1

Documentation

Documentation can be found here.

License

LazyFast is licensed under the MIT License.

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

lazyfast-0.1.27.tar.gz (17.1 kB view details)

Uploaded Source

Built Distribution

lazyfast-0.1.27-py3-none-any.whl (18.9 kB view details)

Uploaded Python 3

File details

Details for the file lazyfast-0.1.27.tar.gz.

File metadata

  • Download URL: lazyfast-0.1.27.tar.gz
  • Upload date:
  • Size: 17.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.2 CPython/3.10.6 Linux/5.15.153.1-microsoft-standard-WSL2

File hashes

Hashes for lazyfast-0.1.27.tar.gz
Algorithm Hash digest
SHA256 ad31550670359fd9e80eced9ba2f2275ca0857a970bac9e9a538330529b6e937
MD5 d6d0466a78021b8492be28e9a29e4266
BLAKE2b-256 e20ebd6ab21e5420ff18bd87694adae10ac15fcd64bc8d426f15689776730f9f

See more details on using hashes here.

File details

Details for the file lazyfast-0.1.27-py3-none-any.whl.

File metadata

  • Download URL: lazyfast-0.1.27-py3-none-any.whl
  • Upload date:
  • Size: 18.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.2 CPython/3.10.6 Linux/5.15.153.1-microsoft-standard-WSL2

File hashes

Hashes for lazyfast-0.1.27-py3-none-any.whl
Algorithm Hash digest
SHA256 0416ba03fc25ae8c8bd02ae636e1b11ec04270ecf226f60a564049ecb49f862c
MD5 59ebfbc45d4b2ec9d3fffb68a2a91fa6
BLAKE2b-256 e8bcb2fa135c71f9109852595a33cf4b28bc016025e3aafba5c18f4b58935359

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