Skip to main content

Lightweight framework for building HTML pages in pure Python.

Project description

Ludic

test codecov Python 3.12 Checked with mypy Documentation Status

Documentation: https://ludic.readthedocs.io/

Ludic is a lightweight framework for building HTML pages with component approach similar to React. It is built to be used together with htmx.org so that developers don't need to write almost any JavaScript to create dynamic web services. It's potential can be leveraged together with its web framework which is a wrapper around powerful Starlette framework. It is built with the latest Python 3.12 features heavily incorporating typing.

Features

  • Seamless </> htmx integration for rapid web development in pure Python
  • React-like component approach with standard Python type hints
  • Uses the power of Starlette and Async for high-performance web development
  • Build HTML with the ease and power of Python f-strings

Requirements

Python 3.12+

Installation

pip install ludic[full]

Similar to Starlette, you'll also want to install an ASGI server:

pip install uvicorn

Example

components.py:

from typing import override

from ludic.html import a
from ludic.types import Attrs, Component

class LinkAttrs(Attrs):
    to: str

class Link(Component[str, LinkAttrs]):
    @override
    def render(self) -> a:
        return a(
            *self.children,
            href=self.attrs["to"],
            style={"color": "#abc"},
        )

Now you can use it like this:

link = Link("Hello, World!", to="/home")

web.py:

from ludic.web import LudicApp
from ludic.html import b, p

from .components import Link

app = LudicApp()

@app.get("/")
async def homepage() -> p:
    return p(f"Hello {b("Stranger")}! Click {Link("here", to="https://example.com")}!")

To run the application:

uvicorn web:app

More Examples

For more complex usage incorporating all capabilities of the framework, please visit the folder with examples on GitHub.

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

ludic-0.1.3.tar.gz (50.1 kB view hashes)

Uploaded Source

Built Distribution

ludic-0.1.3-py3-none-any.whl (37.7 kB view hashes)

Uploaded Python 3

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