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

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

generate_fastapi_typed_routes-0.4.0.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

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

generate_fastapi_typed_routes-0.4.0-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

Details for the file generate_fastapi_typed_routes-0.4.0.tar.gz.

File metadata

  • Download URL: generate_fastapi_typed_routes-0.4.0.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.32 {"installer":{"name":"uv","version":"0.11.32","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}

File hashes

Hashes for generate_fastapi_typed_routes-0.4.0.tar.gz
Algorithm Hash digest
SHA256 611a91774003f2514d4e9a3c462b1878142625b534fe57a8cb03dd1d200b0865
MD5 1e264c453b1e798ebe92f33bc0bbc87d
BLAKE2b-256 115492dbd8bbb9cdf89b523645927477173c5ecf94c20b44630eafa34f56926a

See more details on using hashes here.

File details

Details for the file generate_fastapi_typed_routes-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: generate_fastapi_typed_routes-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 7.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.32 {"installer":{"name":"uv","version":"0.11.32","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}

File hashes

Hashes for generate_fastapi_typed_routes-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c79cb9ef612e0f62ac6b447135c1a2d2cada527a764e556fc1e7050b3a587384
MD5 71a4da24beede6a4f9446142820a7a62
BLAKE2b-256 cd9fc511ed983bb6defb2f3010ae8394f7a7c493512b6cb9e8b68d096a005611

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.4.0 This release

2 files

0.3.4

2 files

0.3.2

2 files

0.3.1

2 files

0.3.0

2 files

0.2.0

2 files

0.1.1

2 files

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