Skip to main content

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

Project description

LazyFast

LazyFast

PyPI - Version PyPI - Python Version PyPI - Downloads

LazyFast is a lightweight Python library for building modern, component-based web interfaces using FastAPI. It handles server-side logic in Python, with interactive elements like inputs and buttons triggering server-side component reloads for dynamic state updates.

Ideal for Python developers who:

  • Have basic HTML and CSS knowledge and want to build web interfaces without learning complex frontend frameworks like React, Angular, or Vue.

Suitable for projects that:

  • Have low to medium traffic and can benefit from server-side rendering to offload work from the client's machine. (Note: High traffic may increase server costs due to backend load.)
  • Require quick prototyping and demos without involving frontend developers. LazyFast offers more flexibility than tools like Streamlit, which can be limiting and produce similar-looking applications.

Key Features

  1. Component-Based Server Rendering
    • Build interfaces with lazy-loaded components that encapsulate logic, state, and presentation.
  2. Server-Side Logic
    • Manage interactions and state on the server, reducing client-side complexity.
  3. FastAPI Integration
    • Components and pages are FastAPI endpoints, supporting dependency injection and other features.
  4. Lightweight
    • Dependencies: FastAPI for Python and HTMX for JavaScript (included via CDN).
  5. State Management
    • Use a state manager to trigger component reloads for 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.

Examples

You can find examples in examples.

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.30.tar.gz (18.0 kB view details)

Uploaded Source

Built Distribution

lazyfast-0.1.30-py3-none-any.whl (19.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: lazyfast-0.1.30.tar.gz
  • Upload date:
  • Size: 18.0 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.30.tar.gz
Algorithm Hash digest
SHA256 5b56e97cffc622c8c4cb7caa4f993f129413f29a8b67dbb4cc6a7f5854b2b93b
MD5 43301e8fea0e4ebe9edf5708636b13b0
BLAKE2b-256 542c3ecf0381efb281e120d1b04e18e08b49d6d015711613602ad39c4e4debeb

See more details on using hashes here.

File details

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

File metadata

  • Download URL: lazyfast-0.1.30-py3-none-any.whl
  • Upload date:
  • Size: 19.2 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.30-py3-none-any.whl
Algorithm Hash digest
SHA256 bce8c7e5d1aa53f3a3c432b21f438106a98561792aaf6e78587f9ade5b86d2d6
MD5 8278c2231dd41f4f22c307a0396366a6
BLAKE2b-256 c0c5dc218c306d851ddd5213f06a66e305cff454c71ccfa12a6760d166ccc6e8

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