Skip to main content

Release Notes Downloads GitHub CI Status License: MIT

Generate Typed Python URL Helpers from React Router Routes

Generate strongly-typed Python helpers (TypedDict param objects + overloads) from a React Router v6+ route tree. This is useful when a Python backend, worker, or test suite needs to construct URLs that stay in sync with a JavaScript/TypeScript frontend using React Router.

Take a look at this project for a live usage example.

How it works

Given a React Router project, the CLI either:

  • Auto-detects your package manager (bun, pnpm, or npm) and runs <package-manager> react-router routes --json (if you pass --directory), or
  • Reads a pre-generated JSON file (if you pass --json-file)

It walks the returned route objects and produces a Python module containing:

  • RoutePaths Literal of every concrete route pattern (e.g. /users/:userId?, /files/*).
  • Per-route TypedDict classes containing snake_case parameter keys.
  • Overloaded react_router_path() to build a relative path with validation + percent-encoding.
  • Overloaded react_router_url() to prepend a base URL (explicit argument or BASE_URL env var).
  • Optional url_params argument on both functions to append query string parameters.

Installation

Using uv (recommended):

uv add react-router-routes

Local CLI development

Run just install_editable to install this checkout globally in editable mode. Source changes are reflected without reinstalling.

This requires uv, just, zsh, and jq. If mise is available, the recipe also updates every installed pipx:react-router-routes environment so mise can use the local checkout. Re-run after mise upgrades, which replace those editable installations.

Prerequisites

Your JS project must have react-router and a package manager with the react-router routes --json command available (React Router v6+ data APIs). The tool automatically detects your package manager (bun, pnpm, or npm) based on lockfiles and availability. The Python process must run inside (or have access to) that project directory so the CLI can execute the command.

CLI Usage

The script entry point is named react-router-routes (see pyproject.toml).

Two ways to supply routes:

  1. Have the tool invoke <package-manager> react-router routes --json by providing a directory (auto-detects bun, pnpm, or npm):
react-router-routes ./routes_typing.py --directory ./frontend
  1. Provide an existing JSON file (output of pnpm react-router routes --json):
react-router-routes ./routes_typing.py --json-file tests/react-router.json

Then import the generated module in Python code:

from routes_typing import react_router_path, react_router_url, RoutePaths

# Basic path generation
react_router_path("/users/:userId", {"user_id": 123})  # -> '/users/123'

# URL generation with base URL
react_router_url(
    "/files/*", {"splat": "docs/readme.md"}, base_url="https://example.com"
)
# -> 'https://example.com/files/docs/readme.md'

# Adding query parameters with url_params
react_router_path(
    "/users/:userId", {"user_id": 123}, url_params={"tab": "profile", "edit": "true"}
)
# -> '/users/123?tab=profile&edit=true'

react_router_url(
    "/home", base_url="https://example.com", url_params={"page": "1", "sort": "name"}
)
# -> 'https://example.com/home?page=1&sort=name'

Environment Variables

  • BASE_URL (optional) – If set and you omit base_url when calling react_router_url, this value is prepended. If missing the function returns the path and logs a warning.
  • LOG_LEVEL (optional) – Standard Python logging level (INFO, DEBUG, etc.).

MIT License


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

Metadata

Release files for react-router-routes 0.5.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 react-router-routes 0.5.1
File Size Uploaded Provenance Actions
react_router_routes-0.5.1.tar.gz 8.3 kB Without provenance Details for react_router_routes-0.5.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for react-router-routes 0.5.1
File Interpreter ABI Platform Actions
react_router_routes-0.5.1-py3-none-any.whl Python 3 none any Details for react_router_routes-0.5.1-py3-none-any.whl

Total release size: 17.5 kB

Release files / react_router_routes-0.5.1.tar.gz

Download URL react_router_routes-0.5.1.tar.gz
Size 8.3 kB
Tags Source
SHA-256 checksum
How to use checksums
0a7221ec198f54a69c64e39664d64c42c1afa908bd01d00e1eaf675a5c6414cd
BLAKE2b-256 checksum
How to use checksums
b12962be0ff4721259210fd50fd01509a9c6497551046cf4be867a11556fcfa5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","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 / react_router_routes-0.5.1-py3-none-any.whl

Download URL react_router_routes-0.5.1-py3-none-any.whl
Size 9.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1daf26d74eadf2805eb8d7b7b31d514d7c10b5db91c1dddf924207535afa2721
BLAKE2b-256 checksum
How to use checksums
f3358478dfa4e365334ede51a21f18d1e154fa97151e0041be753526fc6d643a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","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 react-router-routes 0.5.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