Skip to main content

Release Notes Downloads GitHub CI Status License: MIT

Type-Safe Route URL Generator for FastAPI

Stop guessing route names. This tool analyzes your FastAPI application and generates a typed wrapper for url_path_for, giving you instant autocompletion and catching typos before they hit production.

Here's an example project which uses it (checkout just py_generate)

Installation

uv add generate-fastapi-typed-routes --dev

Usage

Point the tool at your FastAPI app and tell it where to save the generated code:

generate-fastapi-typed-routes --app-module myapp.main:app --output myapp/routes.py

Note that since this tool needs to import an app modules you cannot run it via uvx, which runs outside of your venv.

Now, instead of using the raw app.url_path_for, import your generated function:

from myapp.routes import app_url_path_for

# Complete with IDE autocompletion and type checking!
url = app_url_path_for("get_user_profile", user_id=123)

CLI Arguments

  • --app-module: The import path to your FastAPI app instance (e.g., src.main:app). You can pass this multiple times to generate helpers for multiple apps in one file.
  • --output: The file path where the generated Python code will be saved.
  • --prefix: (Optional) Custom prefix for the generated function. Defaults to the app variable name (e.g., app becomes app_url_path_for). Use this if you have multiple apps to keep things distinct.
  • --directory / -d: (Optional) The directory containing the application module (default: current directory). Use this if your app is not in the current working directory.

Duplicate Route Names

When multiple routes in the same FastAPI app share a route name, the generated helper uses their FastAPI unique IDs instead:

app_url_path_for("list_items_first_items_get")
app_url_path_for("list_items_second_items_get")

Routes whose names are already unique keep their shorter names. If FastAPI's unique IDs still cannot distinguish the conflicting routes, generation fails with an error listing the colliding routes and does not write the output file. Automatic qualification emits a warning for each affected route with its path and the unique ID used in the generated helper.

Features

  • Minimal Runtime Overhead: Unique route names delegate directly to FastAPI; only automatically qualified duplicate names require route lookup.
  • IDE Autocompletion: Never type a route name manually again. Your editor will list every available route name defined in your app.
  • Refactoring Safe: Change a route name in your app, and your type checker (mypy, pyright) will flag every place usage that needs updating.
  • Multi-App Support: Easily manage routes for projects with multiple FastAPI instances.

MIT License


This project was created from iloveitaly/python-package-template

Metadata

Release files for generate-fastapi-typed-routes 0.4.1

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

Source distribution (sdist)

Source distribution for generate-fastapi-typed-routes 0.4.1
File Size Uploaded Provenance Actions
generate_fastapi_typed_routes-0.4.1.tar.gz 6.5 kB Without provenance Details for generate_fastapi_typed_routes-0.4.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for generate-fastapi-typed-routes 0.4.1
File Interpreter ABI Platform Actions
generate_fastapi_typed_routes-0.4.1-py3-none-any.whl Python 3 none any Details for generate_fastapi_typed_routes-0.4.1-py3-none-any.whl

Total release size: 13.8 kB

Release files / generate_fastapi_typed_routes-0.4.1.tar.gz

Download URL generate_fastapi_typed_routes-0.4.1.tar.gz
Size 6.5 kB
Tags Source
SHA-256 checksum
How to use checksums
2309fbb85917158ef3f7fb91fa7778e36a0610aca0544f31ad75276d09ec2d3a
BLAKE2b-256 checksum
How to use checksums
eb72dd57d96561a6c8e6d9ca361923355fb1b4fa02c523bd932ddb02f51d4de9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.6 {"installer":{"name":"uv","version":"0.13.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / generate_fastapi_typed_routes-0.4.1-py3-none-any.whl

Download URL generate_fastapi_typed_routes-0.4.1-py3-none-any.whl
Size 7.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
273b75edefddb5ae57f41c55def30391cd1d2fce7dcc6479864f0612acfcf949
BLAKE2b-256 checksum
How to use checksums
32dc1f681f9b6e1707d88b10c64e294d3d1ca754797e72582b9e3e225e44393a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.6 {"installer":{"name":"uv","version":"0.13.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for generate-fastapi-typed-routes 0.4.1

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.

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