Skip to main content

YHTTP

PyPI Build Coverage Documentation Python

YHTTP is a small, extensible WSGI framework for building HTTP services in Python. It provides regex routing, request guards, form parsing, settings, lifecycle hooks, static file serving, and a built-in development CLI while leaving features such as templates, authentication, localization, and database access to focused extensions.

Installation

YHTTP requires Python 3.10 or newer.

python -m pip install yhttp

Quick start

Create hello.py:

import sys

from yhttp.core import Application, text


app = Application('0.1.0', 'hello')


@app.route('/')
@text
def get(req):
    return 'Hello, world!'


if __name__ == '__main__':
    sys.exit(app.climain())


app.ready()

Start the built-in development server and make a request:

python hello.py serve --bind 8080
curl http://localhost:8080/

The application is WSGI-compatible, so it can also be served by a WSGI server such as Gunicorn:

python -m pip install gunicorn
gunicorn hello:app

The handler name selects the HTTP verb when verb is not passed explicitly to app.route(). Routes are regular expressions, and captured groups are passed to the handler after req.

Features

  • Regex routes with captured path parameters and explicit verb overrides
  • Strict query-string and request-body validation through guards
  • URL-encoded, multipart, and JSON form parsing
  • Layered settings and application lifecycle hooks
  • Static files, WSGI rewriting, middleware, and status handlers
  • An extensible command-line interface with a development server
  • A small core that can be composed with YHTTP extensions

SSR development

YHTTP keeps server-side rendering outside the core. Use an extension such as yhttp-mako to render Mako templates, then compose localization, authentication, assets, and persistence through the extensions already used by your application.

Install the Mako extension:

python -m pip install yhttp-mako
mkdir -p templates makomodules

A minimal rendered page consists of an application module and a template:

# app.py
from yhttp.core import Application
from yhttp.ext import mako


app = Application('0.1.0', 'pages')
mako.install(app)

app.settings.mako.lookup = 'templates'
app.settings.mako.modules = 'makomodules'


@app.route('/')
@app.template('index.mako')
def get(req):
    return {'title': 'Hello from YHTTP'}


app.ready()
<!-- templates/index.mako -->
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>${title | h}</title>
  </head>
  <body>
    <h1>${title | h}</h1>
  </body>
</html>

Run it with gunicorn app:app. The makomodules directory stores compiled templates and must be writable by the application process.

For a maintainable SSR application, keep the rendering path explicit:

  1. Create the Application, install extensions, and merge settings before readiness. Import model modules before route modules, and call app.ready() only after registration is complete; an unimported model or route module is inactive.
  2. Keep handlers responsible for request guards, authorization, database access, and status responses. A page handler should return a context dictionary to @app.template(...), not build HTML itself.
  3. Put shared document structure in inherited Mako layouts. Keep templates presentational, reuse template-provided helpers, and escape user-controlled values. Render stored HTML unescaped only when the application explicitly treats it as trusted.
  4. Localize visible text with the installed translation helpers, preserve locale-prefixed links, and test both LTR and RTL output when the application supports both directions.
  5. Keep pages useful without JavaScript where practical. Add focused browser behavior through the project's existing asset pipeline, and keep endpoint calls in browser-side service modules rather than templates.
  6. Extend the nearest bddrest page test. Assert meaningful rendered behavior, including routes, localized text, direction-sensitive markup, resolved assets, authentication states, and persisted effects relevant to the page.

A typical project keeps its composition root, route registration, page handlers, templates, browser assets, and page tests separate:

app.py
models/
routes.py
pages.py
templates/
www/
tests/test_pages.py

Treat this as a responsibility map rather than a required package layout; follow the nearest complete feature in an existing application.

Contributing

This repository uses python-makelib. Install it first, then create and populate the development environment:

make venv
source ./activate.sh
make env

Run the test suite:

make test

Run a focused test or coverage target with F:

make test F=tests/test_form.py::test_getform_force
make cover F=tests/test_static.py

Run all coverage checks or generate the HTML coverage report:

make cover
make cover-html

Lint the project:

make lint

Delete the virtual environment with make venv-delete.

Documentation

Build and test the Sphinx documentation from the repository root:

source ./activate.sh
make doc
make doctest
make doclive

The equivalent commands from sphinx/ are make html, make doctest, and make livehtml.

Distribution

Build the source and wheel distributions in dist/:

make clean
make sdist
make wheel

Publishing is reserved for project maintainers. Maintainers can upload both artifacts with make pypi.

License

YHTTP is released under the MIT License.

Metadata

Release files for yhttp 9.6.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for yhttp 9.6.0
File Size Uploaded Provenance Actions
yhttp-9.6.0.tar.gz 62.6 kB Without provenance Details for yhttp-9.6.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for yhttp 9.6.0
File Interpreter ABI Platform Actions
yhttp-9.6.0-py3-none-any.whl Python 3 none any Details for yhttp-9.6.0-py3-none-any.whl

Total release size: 100.0 kB

Release files / yhttp-9.6.0.tar.gz

Download URL yhttp-9.6.0.tar.gz
Size 62.6 kB
Tags Source
SHA-256 checksum
How to use checksums
5853270b4b02aa02a49efb53ca3f14f719abf76c0bc0334e9763fd0ea2b2c16f
BLAKE2b-256 checksum
How to use checksums
668bfce0ca6647545d0764f1e6425237751a9cd82088c566beb2ac5ef0156fc8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / yhttp-9.6.0-py3-none-any.whl

Download URL yhttp-9.6.0-py3-none-any.whl
Size 37.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e128e0746f841e2c82c069fc46e17d6b338d16b0305269a09ccfc021506a5b9c
BLAKE2b-256 checksum
How to use checksums
d8808af047d5a7f511b04ab2d8408dd9fd99b8a2a2b6f0a59e6954f54034e4fe
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Security for yhttp 9.6.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

9.6.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page