Skip to main content

Project to build easy user interfaces, agnostic for http frameworks

Project description

routelit

Release Build status codecov Commit activity License

Routelit

routelit is a Python library for building interactive web user interfaces that are framework-agnostic and easy to use. It allows you to create dynamic web applications with a simple, declarative API similar to Streamlit, but designed to work with any HTTP framework (Flask, FastAPI, Django, etc.).

✨ Features

  • Framework Agnostic: Works with any Python web framework (Flask, FastAPI, Django, etc.)
  • Declarative UI: Build interfaces using simple Python functions
  • Interactive Components: Buttons, forms, inputs, selects, checkboxes, and more
  • State Management: Built-in session state management
  • Reactive Updates: Automatic UI updates based on user interactions
  • Fragment Support: Partial page updates for better performance
  • Flexible Layouts: Containers, columns, flex layouts, and expandable sections
  • Rich Content: Support for markdown, images, and custom styling

🚀 Installation

Install routelit using pip:

pip install routelit

📖 Quick Start

Here's a simple example of how to use routelit:

from routelit import RouteLit, RouteLitBuilder

# Create a RouteLit instance
rl = RouteLit()

def my_app(builder: RouteLitBuilder):
    builder.title("Welcome to RouteLit!")

    name = builder.text_input("Enter your name:", value="World")

    if builder.button("Say Hello"):
        builder.text(f"Hello, {name}!")

    builder.markdown("This is a **markdown** text with *emphasis*.")

Flask

pip install routelit-flask
from flask import Flask
from routelit import RouteLit, RouteLitBuilder
from routelit_flask import RouteLitFlaskAdapter

app = Flask(__name__)
rl = RouteLit()
adapter = RouteLitFlaskAdapter(rl).configure(app)

def index_view(rl: RouteLitBuilder):
    rl.text("Hello, World!")

@app.route("/", methods=["GET", "POST"])
def index():
    return adapter.response(index_view)

FastAPI

pip install routelit-fastapi
from fastapi import FastAPI, Request
from routelit import RouteLit, RouteLitBuilder
from routelit_fastapi import RouteLitFastAPIAdapter

app = FastAPI()
rl = RouteLit()
adapter = RouteLitFastAPIAdapter(rl).configure(app)

def index_view(rl: RouteLitBuilder):
    rl.text("Hello, World!")

@app.api_route("/", methods=["GET", "POST"])
async def index(request: Request):
    return await adapter.response(index_view, request)

# Or use the simplified decorator:
@adapter.route("/")
def index_view(rl: RouteLitBuilder):
    rl.text("Hello, World!")

Django

pip install routelit-django
# views.py
from routelit import RouteLit, RouteLitBuilder
from routelit_django import RouteLitDjangoAdapter, DjangoSessionStorage

rl = RouteLit(session_storage=DjangoSessionStorage())
adapter = RouteLitDjangoAdapter(rl)

def index_view(rl: RouteLitBuilder):
    rl.text("Hello, World!")

def index(request):
    return adapter.response(index_view, request)
# urls.py
from django.urls import path
from . import views

urlpatterns = [
    path('', views.index, name='index'),
]

views.adapter.configure(urlpatterns)

🏗️ Core Concepts

Builder Pattern

RouteLit uses a builder pattern where you define your UI using a RouteLitBuilder instance:

def my_view(builder: RouteLitBuilder):
    builder.header("My Application")

    with builder.container():
        builder.text("This is inside a container")

        col1, col2 = builder.columns(2)
        with col1:
            builder.text("Left column")
        with col2:
            builder.text("Right column")

State Management

RouteLit automatically manages state between requests:

def counter_app(builder: RouteLitBuilder):
    # Get current count from session state
    count = builder.session_state.get("count", 0)

    builder.text(f"Count: {count}")

    if builder.button("Increment"):
        builder.session_state["count"] = count + 1
        builder.rerun()  # Trigger a re-render

Interactive Components

Build rich forms and interactive elements:

def form_example(builder: RouteLitBuilder):
    with builder.form("my_form"):
        name = builder.text_input("Name")
        age = builder.text_input("Age", type="number")

        options = ["Option 1", "Option 2", "Option 3"]
        choice = builder.select("Choose an option", options)

        newsletter = builder.checkbox("Subscribe to newsletter")

        if builder.button("Submit", event_name="submit"):
            builder.text(f"Hello {name}, you are {age} years old!")
            if newsletter:
                builder.text("Thanks for subscribing!")

🔧 Framework Integration

RouteLit is designed to work with any Python web framework.

📚 Documentation

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

🙏 Acknowledgments

RouteLit is inspired by Streamlit but designed to be framework-agnostic and more flexible for web development use cases.


Repository initiated with fpgmaas/cookiecutter-uv.

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

routelit-0.6.2.tar.gz (130.5 kB view details)

Uploaded Source

Built Distribution

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

routelit-0.6.2-py3-none-any.whl (38.8 kB view details)

Uploaded Python 3

File details

Details for the file routelit-0.6.2.tar.gz.

File metadata

  • Download URL: routelit-0.6.2.tar.gz
  • Upload date:
  • Size: 130.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.2

File hashes

Hashes for routelit-0.6.2.tar.gz
Algorithm Hash digest
SHA256 5c7df3ed5eab7dc7044fbd37a949e48e894810da0dc5306ee799b4a7f1813220
MD5 b6e701a1f0b27fec83a7a3766168f8e4
BLAKE2b-256 1c4a250b1e9e983260c3b2287ef635e75a9bbfc152bc8dcd5d0f07eea77b4a9e

See more details on using hashes here.

File details

Details for the file routelit-0.6.2-py3-none-any.whl.

File metadata

  • Download URL: routelit-0.6.2-py3-none-any.whl
  • Upload date:
  • Size: 38.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.2

File hashes

Hashes for routelit-0.6.2-py3-none-any.whl
Algorithm Hash digest
SHA256 473d736ce9a40724a8131e8483a8e827a38cea0cb2e2e7228222035afeef8d19
MD5 1f1045c3812b858ccea3b036042be88e
BLAKE2b-256 330769f652cb57e26891510a3176bda9457b89e58e042839139a45bc42d248ab

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