Skip to main content

Protorig is a small web framework supporting both ASGI and RSGI

Project description

protorig

A small Python web framework with a Rust core, supporting both ASGI and RSGI. It takes inspiration from most of the established web frameworks including sanic and FastAPI

Features

  • async only
  • ASGI and RSGI compatible — run it under uvicorn, granian, or any compliant server
  • radix-tree router in rust based on go's httprouter
  • Function-based routing with decorators
  • Dependency injection via Depends
  • Helpers for text, JSON, file, and redirect responses
  • Customisable exception handlers
  • Composable route groups with prefixes and mounting

Requirements

  • Python 3.13+
  • orjson
  • anyio
  • msgspec
  • A Rust toolchain (only needed to build from source)

Installation

Pre-built wheels are published on PyPI, install with your preferred package manager:

pip install protorig

Building from source

protorig is built with maturin. To build and install from a checkout:

uv sync
uv run maturin develop

This compiles the Rust core (protorig.core) and installs the package into your environment.

Quick start

import uvicorn

from typing import Annotated

from protorig import responses
from protorig.application import Application
from protorig.depends import Depends
from protorig.routes import Routes

routes = Routes()


def get_db():
    return "clearly a database"


@routes.get("/user/:id")
async def get_user(id: int, db: Annotated[str, Depends(get_db)]):
    return responses.text(f"user({db}) -- {id}", 200)


app = Application(routes)

if __name__ == "__main__":
    uvicorn.run(app, host="0.0.0.0", port=8000)

Routing

Create a Routes group and register handlers with the per-method decorators (get, post, put, delete, patch, options, head) or the generic route decorator:

routes = Routes()

@routes.get("/health")
async def health():
    return responses.text("ok")

@routes.route(["GET", "POST"], "/echo")
async def echo(request: Request):
    return responses.json(await request.json())

Path parameters

Path segments prefixed with : are captured and passed to the handler by name. Annotate the parameter to have its value coerced to that type:

@routes.get("/post/:slug/comment/:id")
async def comment(slug: str, id: int):
    ...

Prefixes and mounting

A Routes group can be given a prefix, and groups can be composed by mounting one into another — either directly or by import path:

api = Routes(prefix="/api")

root = Routes()
root.mount(api)
root.mount("myapp.users:routes", prefix="/v1")

Dependency injection

Declare dependencies with Depends. They are resolved per request, and the resolved value is injected into your handler:

from typing import Annotated
from protorig.depends import Depends

def get_db():
    return "db"

@routes.get("/items")
async def list_items(db: Annotated[str, Depends(get_db)]):
    ...

The current Request can be injected by annotating a parameter with the Request type.

Responses

The protorig.responses module provides helpers that return an HTTPResponse:

Helper Purpose
responses.text(body, status=200, ...) Plain-text response
responses.json(body, status=200, ...) JSON response (serialised with orjson)
responses.file(path, ...) File response with caching / conditional headers
responses.redirect(url, status=302, ...) Redirect response

Exception handling

Register handlers for specific exception types with Application.exception_handler. HTTPException is handled by default and returns its detail and status_code:

from protorig.exceptions import HTTPException

@app.exception_handler(HTTPException)
async def handle_http(request, exception: HTTPException):
    return responses.text(exception.detail, exception.status_code)

Unhandled exceptions are logged and produce a 500 Internal Server Error.

License

BSD-3-Clause

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

protorig-0.2.1.tar.gz (36.7 kB view details)

Uploaded Source

Built Distributions

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

protorig-0.2.1-cp314-cp314-win_amd64.whl (265.6 kB view details)

Uploaded CPython 3.14Windows x86-64

protorig-0.2.1-cp314-cp314-musllinux_1_2_x86_64.whl (493.0 kB view details)

Uploaded CPython 3.14musllinux: musl 1.2+ x86-64

protorig-0.2.1-cp314-cp314-manylinux_2_34_x86_64.whl (417.1 kB view details)

Uploaded CPython 3.14manylinux: glibc 2.34+ x86-64

protorig-0.2.1-cp313-cp313-win_amd64.whl (265.3 kB view details)

Uploaded CPython 3.13Windows x86-64

protorig-0.2.1-cp313-cp313-musllinux_1_2_x86_64.whl (492.8 kB view details)

Uploaded CPython 3.13musllinux: musl 1.2+ x86-64

protorig-0.2.1-cp313-cp313-manylinux_2_34_x86_64.whl (417.0 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ x86-64

File details

Details for the file protorig-0.2.1.tar.gz.

File metadata

  • Download URL: protorig-0.2.1.tar.gz
  • Upload date:
  • Size: 36.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.15 {"installer":{"name":"uv","version":"0.11.15","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for protorig-0.2.1.tar.gz
Algorithm Hash digest
SHA256 7514c01cef4fbf315b6aa3d75b082505cf7ff878ca601bf7ef86274e0115075d
MD5 e584cee022222ef720f126b2de1b65a0
BLAKE2b-256 22ccc2c11d1a900aa02336745881c49c7fcd5969e860bd9434b6dc6fe19032a6

See more details on using hashes here.

File details

Details for the file protorig-0.2.1-cp314-cp314-win_amd64.whl.

File metadata

  • Download URL: protorig-0.2.1-cp314-cp314-win_amd64.whl
  • Upload date:
  • Size: 265.6 kB
  • Tags: CPython 3.14, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.15 {"installer":{"name":"uv","version":"0.11.15","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for protorig-0.2.1-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 01168912fbc8f407507d76e53dde44eb536c54f7404fb038101bc98cc6ff1a3e
MD5 6aa3aab447834824bb1e6162a04e57a4
BLAKE2b-256 c74d7da9583ff9886b7f6ae01a68403e8141294fdb17cb534e94d9c8db614805

See more details on using hashes here.

File details

Details for the file protorig-0.2.1-cp314-cp314-musllinux_1_2_x86_64.whl.

File metadata

  • Download URL: protorig-0.2.1-cp314-cp314-musllinux_1_2_x86_64.whl
  • Upload date:
  • Size: 493.0 kB
  • Tags: CPython 3.14, musllinux: musl 1.2+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.15 {"installer":{"name":"uv","version":"0.11.15","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Alpine Linux","version":"3.24.0_alpha20260127","id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for protorig-0.2.1-cp314-cp314-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 65048db84afecf024e3753b9182c56f14ebadbf3b08953fad7a0e6b2a027baac
MD5 3568f6e41b2385049e829fc21f6eb00c
BLAKE2b-256 2ec4fafe7d6b937e940701b948b2974d2f6d2680e0058dbd3e9e2d38d9ff282e

See more details on using hashes here.

File details

Details for the file protorig-0.2.1-cp314-cp314-manylinux_2_34_x86_64.whl.

File metadata

  • Download URL: protorig-0.2.1-cp314-cp314-manylinux_2_34_x86_64.whl
  • Upload date:
  • Size: 417.1 kB
  • Tags: CPython 3.14, manylinux: glibc 2.34+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.15 {"installer":{"name":"uv","version":"0.11.15","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for protorig-0.2.1-cp314-cp314-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 dd6d601d8f5df734b05b4e9437899c4cf72ee5b7659b63c5c0b25ba8971ceaaa
MD5 bc476f8e0c2a34b3be3eae60aff30bba
BLAKE2b-256 3795b23acf8b6e14d31637b48155e4ede631ab19b78e83118f5ec8eb7fe49ded

See more details on using hashes here.

File details

Details for the file protorig-0.2.1-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: protorig-0.2.1-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 265.3 kB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.15 {"installer":{"name":"uv","version":"0.11.15","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for protorig-0.2.1-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 6455feb18fd82671f69b907621e3367d9d9552330739ade43cb4cb5979369bc2
MD5 b175fe8709e6a417025dbae20f4c8287
BLAKE2b-256 cc5cd3f1b5892e96e5f4921112d9e01c37c587d11094c830993a892c4940f178

See more details on using hashes here.

File details

Details for the file protorig-0.2.1-cp313-cp313-musllinux_1_2_x86_64.whl.

File metadata

  • Download URL: protorig-0.2.1-cp313-cp313-musllinux_1_2_x86_64.whl
  • Upload date:
  • Size: 492.8 kB
  • Tags: CPython 3.13, musllinux: musl 1.2+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.15 {"installer":{"name":"uv","version":"0.11.15","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Alpine Linux","version":"3.24.0_alpha20260127","id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for protorig-0.2.1-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 a0ed63a8d350e018a09072fe48cd85204c522da4f99b3f39eeb7a609a5e97219
MD5 3b167144f3b446b18c6706a08c7aab7d
BLAKE2b-256 690a92f5a23f64434b4f6829edabb8035574c2f0547cf856f6968b88088d57a2

See more details on using hashes here.

File details

Details for the file protorig-0.2.1-cp313-cp313-manylinux_2_34_x86_64.whl.

File metadata

  • Download URL: protorig-0.2.1-cp313-cp313-manylinux_2_34_x86_64.whl
  • Upload date:
  • Size: 417.0 kB
  • Tags: CPython 3.13, manylinux: glibc 2.34+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.15 {"installer":{"name":"uv","version":"0.11.15","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for protorig-0.2.1-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 c72883ca803bbaff183e9e6f3380a7c45dafc889d75da8078e7dc6453d66bcb1
MD5 f51b01c706e28c45775ce66bd35b3ab0
BLAKE2b-256 2cbb2992830fafb3316b63075ce2d862ffa7764ae15205c6ef56972e4e91e899

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