Skip to main content

Route definition primitives for Python services.

Project description

RouteDef 🧭

Runtime-neutral route definitions for Python services.

routedef gives applications one route contract that can be mounted into multiple runtimes. The core package has no FastAPI, Cloudflare, ASGI, auth, database, or application dependency. Runtime-specific code lives in adapters.

What It Provides ✅

  • RouteDef: method, path template, handler, and metadata.
  • RouteRequest: canonical request object for handlers.
  • RouteResponse: canonical response object for handlers.
  • RouteTable: ordered method/path matching with {path_param} extraction.
  • build_fastapi_router: FastAPI router integration.
  • CloudflareDispatcher: direct Cloudflare Python Workers integration.

Why Use It 🎯

Use RouteDef when you need the same route definitions to work across more than one Python runtime, especially when migrating between framework-hosted APIs and Cloudflare Python Workers.

  • One handler contract instead of per-runtime handler shapes.
  • App-owned auth and authorization through metadata, auth providers, and enforcers.
  • Dependency-free core package with optional runtime adapters.
  • Testable route behavior without starting a web server.
  • Migration-friendly wrappers for legacy split-argument handlers.

Why Not 🚧

Do not use RouteDef as a full web framework, ORM, dependency injection container, auth library, or request validation system. It intentionally does not own app policy, storage, schemas, background jobs, or runtime lifecycle. If a service will only ever run in one framework and already has a stable route layer, the adapter boundary may not be worth adding.

Architecture 🏗️

routedef request flow

routedef package boundaries

See docs/architecture.md for package boundaries and docs/migration.md for migration examples covering undef-style roles, admin authorization callbacks, Taybols JWT auth, and uwarp split-argument handlers.

Basic Usage 🚀

from routedef import RouteDef, RouteRequest, RouteResponse, RouteTable


async def get_item(request: RouteRequest[None, dict[str, object]]) -> RouteResponse:
    return RouteResponse.json({"id": request.path_params["id"]})


routes = RouteTable([RouteDef("GET", "/v1/items/{id}", get_item)])

FastAPI

from fastapi import FastAPI
from routedef.adapters.fastapi import build_fastapi_router

app = FastAPI()
app.include_router(build_fastapi_router(routes))

Cloudflare Python Workers

from routedef.adapters.cloudflare import CloudflareDispatcher
from workers import WorkerEntrypoint

dispatcher = CloudflareDispatcher(routes)


class Default(WorkerEntrypoint):
    async def fetch(self, request):
        return await dispatcher.dispatch(request)

A real local Cloudflare fixture lives in examples/cloudflare-worker. Run it with:

uv run python scripts/check_cloudflare_worker.py

The integration script vendors the local src/routedef package into a temporary Python Worker project, runs pywrangler sync, starts wrangler@latest dev, and probes routes over HTTP.

Quality Gates 🧪

uv run pre-commit run --all-files
uv run pytest -q --cov=src/routedef --cov-branch --cov-report=term-missing --cov-fail-under=100
uv run pre-commit run mutation-sweep --hook-stage manual
uv run pre-commit run cloudflare-worker-integration --hook-stage manual

The project requires 100% branch coverage, strict typing, security/dead-code/complexity checks, REUSE compliance, max-LOC checks, mutation testing, and a Cloudflare Worker runtime integration gate.

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

routedef-0.1.0.tar.gz (53.7 kB view details)

Uploaded Source

Built Distribution

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

routedef-0.1.0-py3-none-any.whl (17.2 kB view details)

Uploaded Python 3

File details

Details for the file routedef-0.1.0.tar.gz.

File metadata

  • Download URL: routedef-0.1.0.tar.gz
  • Upload date:
  • Size: 53.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.21 {"installer":{"name":"uv","version":"0.11.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"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 routedef-0.1.0.tar.gz
Algorithm Hash digest
SHA256 7975371a8153d444670ac8b69f14225079fcc0c1dc1ac79d2efd4d3ad9c665ca
MD5 4a8fdc03512222be78ffdfd1b5be1314
BLAKE2b-256 d2464e5a669a7a76493e263cec7ac05df61724ec0b5b5ff2dd7dfea2c7d86d41

See more details on using hashes here.

File details

Details for the file routedef-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: routedef-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 17.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.21 {"installer":{"name":"uv","version":"0.11.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"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 routedef-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b29397b50d3cab4ab0f89992d4ed62e472bc813564f96bae05ea89accc9c6e9d
MD5 e2bb63146047c0d3cea64b9627dc19bf
BLAKE2b-256 c0f3016ace988229a91a19168ad6b71a6f6b80172a9d40f24cf9897de0db1508

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