Skip to main content

A Python web framework for the modern web platform — HTML fragments, streaming, SSE, free-threading ready

Project description

⌁⌁ Chirp

PyPI version Python 3.14+ License: MIT Status: Alpha

A Python web framework for the modern web platform.

from chirp import App

app = App()

@app.route("/")
def index():
    return "Hello, World!"

app.run()

What is Chirp?

Chirp is a Python web framework built for the modern web platform: browser-native UI, HTML over the wire, streaming responses, and Server-Sent Events. Return values drive content negotiation — no make_response(), no jsonify(). The type is the intent.

What's good about it:

  • Browser-native UI<dialog>, popover, View Transitions, container queries. Most of what required a JS framework is now native HTML and CSS.
  • HTML over the wire — Serve full pages, template fragments, streaming HTML, and SSE. Built for htmx and the modern browser.
  • Streaming HTML — Send the page shell immediately and fill in content as data becomes available. No loading spinners, no skeleton screens.
  • Server-Sent Events — Push real-time updates over plain HTTP. No WebSocket protocol upgrade, no special infrastructure.

Installation

# pip
pip install bengal-chirp

# uv
uv add bengal-chirp

Requires Python 3.14+


Quick Start

chirp new myapp && cd myapp && python app.py
Function Description
chirp new <name> Scaffold a new project
chirp run <app> Start the dev server from an import string
chirp check <app> Validate hypermedia contracts
App() Create an application
@app.route(path) Register a route handler
Template(name, **ctx) Render a full template
Template.inline(src, **ctx) Render from string (prototyping)
Page(name, block, **ctx) Auto Fragment or Template based on request
Fragment(name, block, **ctx) Render a named template block
Stream(name, **ctx) Stream HTML progressively
Suspense(name, **ctx) Shell first, OOB swaps for deferred data
EventStream(gen) Server-Sent Events stream
app.run() Start the development server

Features

Feature Description Docs
Routing Pattern matching, path params, method dispatch Routing →
Filesystem routing Route discovery from pages/ with layouts Filesystem →
Templates Kida integration, rendering, filters Templates →
Fragments Render named template blocks independently Fragments →
Forms form_or_errors, form macros, validation Forms →
Streaming Progressive HTML rendering via Kida Streaming →
SSE Server-Sent Events for real-time updates SSE →
Middleware CORS, sessions, static files, security headers, custom Middleware →
Contracts Compile-time validation of hypermedia surface Reference →
Testing Test client, assertions, isolation utilities Testing →
Data Database integration and form validation Data →

📚 Full documentation: lbliii.github.io/chirp


Production Deployment

Chirp apps run on pounce, a production-grade ASGI server with enterprise features built-in:

Automatic Features (Zero Configuration)

  • WebSocket compression — 60% bandwidth reduction
  • HTTP/2 support — Multiplexed streams, server push
  • Graceful shutdown — Finishes active requests on SIGTERM
  • Zero-downtime reloadkill -SIGUSR1 for hot code updates
  • Built-in health endpoint/health for Kubernetes probes

Production Features (Configurable)

  • 📊 Prometheus metrics/metrics endpoint for monitoring
  • 🛡️ Per-IP rate limiting — Token bucket algorithm, configurable burst
  • 📦 Request queueing — Load shedding during traffic spikes
  • 🐛 Sentry integration — Automatic error tracking and reporting
  • 🔄 Multi-worker mode — CPU-based auto-scaling

Quick Start: Production Mode

from chirp import App, AppConfig

# Production configuration
config = AppConfig(
    debug=False,  # ← Enables production mode
    workers=4,
    metrics_enabled=True,
    rate_limit_enabled=True,
    sentry_dsn="https://...",
)

app = App(config=config)

@app.route("/")
def index():
    return "Hello, Production!"

app.run()  # ← Automatically uses production server

CLI Production Mode

# Development (single worker, auto-reload)
chirp run myapp:app

# Production (multi-worker, all features)
chirp run myapp:app --production --workers 4 --metrics --rate-limit

Docker Deployment

FROM python:3.14-slim
WORKDIR /app
COPY . .
RUN pip install bengal-chirp
CMD ["chirp", "run", "myapp:app", "--production", "--workers", "4"]

📦 Full deployment guide: docs/deployment/production.md


Usage

Return Values — Type-driven content negotiation

Route functions return values. The framework handles content negotiation based on the type:

return "Hello"                                  # -> 200, text/html
return {"users": [...]}                         # -> 200, application/json
return Template("page.html", title="Home")      # -> 200, rendered via Kida
return Page("search.html", "results", items=x)  # -> Fragment or Template (auto)
return Fragment("page.html", "results", items=x) # -> 200, rendered block
return Stream("dashboard.html", **async_ctx)    # -> 200, streamed HTML
return Suspense("dashboard.html", stats=...)    # -> shell + OOB swaps
return EventStream(generator())                 # -> SSE stream
return Response(body=b"...", status=201)         # -> explicit control
return Redirect("/login")                       # -> 302

No make_response(). No jsonify(). The type is the intent.

Fragments and htmx — Render template blocks independently

Kida can render a named block from a template independently, without rendering the whole page:

{# templates/search.html #}
{% extends "base.html" %}

{% block content %}
  <input type="search" hx-get="/search" hx-target="#results" name="q">
  {% block results_list %}
    <div id="results">
      {% for item in results %}
        <div class="result">{{ item.title }}</div>
      {% end %}
    </div>
  {% endblock %}
{% endblock %}
@app.route("/search")
async def search(request: Request):
    results = await db.search(request.query.get("q", ""))
    if request.is_fragment:
        return Fragment("search.html", "results_list", results=results)
    return Template("search.html", results=results)

Full page request renders everything. htmx request renders just the results_list block. Same template, same data, different scope. No separate "partials" directory.

Streaming HTML — Progressive rendering

Kida renders template sections as they complete. The browser receives the shell immediately and content fills in progressively:

@app.route("/dashboard")
async def dashboard(request: Request):
    return Stream("dashboard.html",
        header=site_header(),
        stats=await load_stats(),
        activity=await load_activity(),
    )
Server-Sent Events — Real-time HTML updates

Push Kida-rendered HTML fragments to the browser in real-time:

@app.route("/notifications")
async def notifications(request: Request):
    async def stream():
        async for event in notification_bus.subscribe(request.user):
            yield Fragment("components/notification.html", event=event)
    return EventStream(stream())

Combined with htmx's SSE support, this enables real-time UI updates with zero client-side JavaScript. The server renders HTML, the browser swaps it in.

Middleware — Composable request/response pipeline

No base class. No inheritance. A middleware is anything that matches the protocol:

async def timing(request: Request, next: Next) -> Response:
    start = time.monotonic()
    response = await next(request)
    elapsed = time.monotonic() - start
    return response.with_header("X-Time", f"{elapsed:.3f}")

app.add_middleware(timing)

Built-in middleware: CORS, StaticFiles, HTMLInject, Sessions, SecurityHeaders.

Typed Contracts — Compile-time hypermedia validation

Chirp validates the server-client boundary at startup:

issues = app.check()
for issue in issues:
    print(f"{issue.severity}: {issue.message}")

Every hx-get, hx-post, and action attribute in your templates is checked against the registered route table. Every Fragment and SSE return type is checked against available template blocks. Broken references become compile-time errors, not runtime 404s.


Key Ideas

  • HTML over the wire. Serve full pages, template fragments, streaming HTML, and Server-Sent Events. Built for htmx and the modern browser.
  • Kida built in. Same author, no seam. Fragment rendering, streaming templates, and filter registration are first-class features, not afterthoughts.
  • Typed end-to-end. Frozen config, frozen request, chainable response. Zero type: ignore comments.
  • Free-threading native. Designed for Python 3.14t from the first line. Immutable data structures, ContextVar isolation.
  • Contracts, not conventions. app.check() validates the full hypermedia surface at startup.
  • Minimal dependencies. kida-templates + anyio + bengal-pounce. Everything else is optional.

Documentation

📚 lbliii.github.io/chirp

Section Description
Get Started Installation and quickstart
Core Concepts App lifecycle, return values, configuration
Routing Routes, filesystem routing, requests
Templates Rendering, fragments, filters
Streaming HTML streaming and Server-Sent Events
Middleware Built-in and custom middleware
Data Database integration and forms
Testing Test client and assertions
Deployment Production deployment with Pounce
Tutorials Flask migration, htmx patterns
Examples RAG demo, production stack, API
Reference API documentation

Development

git clone https://github.com/lbliii/chirp.git
cd chirp
uv sync --group dev
pytest

The Bengal Ecosystem

A structured reactive stack — every layer written in pure Python for 3.14t free-threading.

ᓚᘏᗢ Bengal Static site generator Docs
∿∿ Purr Content runtime
⌁⌁ Chirp Web framework ← You are here Docs
=^..^= Pounce ASGI server Docs
)彡 Kida Template engine Docs
ฅᨐฅ Patitas Markdown parser Docs
⌾⌾⌾ Rosettes Syntax highlighter Docs

Python-native. Free-threading ready. No npm required.


License

MIT

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

bengal_chirp-0.1.1.tar.gz (253.1 kB view details)

Uploaded Source

Built Distribution

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

bengal_chirp-0.1.1-py3-none-any.whl (195.7 kB view details)

Uploaded Python 3

File details

Details for the file bengal_chirp-0.1.1.tar.gz.

File metadata

  • Download URL: bengal_chirp-0.1.1.tar.gz
  • Upload date:
  • Size: 253.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for bengal_chirp-0.1.1.tar.gz
Algorithm Hash digest
SHA256 bd718293c856a2d960671a8418977271addd004b3e92ae73b6bd374c37aea101
MD5 48c042530dfa15d907cd737a7c0c0674
BLAKE2b-256 2b10bdd3226854044903ae8e69a5308eaa39f1f59849ac1830f8eb730ada1d78

See more details on using hashes here.

Provenance

The following attestation bundles were made for bengal_chirp-0.1.1.tar.gz:

Publisher: python-publish.yml on lbliii/chirp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file bengal_chirp-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: bengal_chirp-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 195.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for bengal_chirp-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6c7a03e3b22063aea9d3eb04b02c37ce3f34a41f53df0569a6a60a777fe3a44f
MD5 330b3dd884509015134a1297924eccb0
BLAKE2b-256 f433935bfe46d7478a8ff9b280906da25369a4d681ca036372f269bb17889142

See more details on using hashes here.

Provenance

The following attestation bundles were made for bengal_chirp-0.1.1-py3-none-any.whl:

Publisher: python-publish.yml on lbliii/chirp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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