Flask dynamic route registration
A library to help dynamically register routes in Flask applications.
pip install flask-dynamic-route-registration
How to Use
Basic Setup
You start by creating a Flask application as you usually do.
from flask import Flask
from flask_dynamic_route_registration import register_blueprint
app = Flask(__name__)
register_blueprint(app, "healthcheck", '', {})
app.run()
Inside the healthcheck/__init__.py file
from flask import make_response
from typing import TYPE_CHECKING
from flask_dynamic_route_registration import register_route
if TYPE_CHECKING:
from flask import Response
@register_route("/health")
def health() -> "Response":
response = make_response("OK", 200)
response.mimetype = "text/plain"
return response
More advanced use cases
In those use cases, we will cover both:
- how to reuse the same file multiple times but with different parameters,
- how to register a route based on a condition
api_versions = [
{
"blueprint_name": "api_v1",
"blueprint_kwargs": {"url_prefix": "/api/1"},
"params": {"version": 1},
},
{
"blueprint_name": "api_v2",
"blueprint_kwargs": {"url_prefix": "/api/2"},
"params": {"version": 2},
}
]
register_blueprint(app, 'api', api_versions, {})
Inside the api/__init__.py file
from flask import jsonify
from typing import TYPE_CHECKING
from flask_dynamic_route_registration import register_route
if TYPE_CHECKING:
from flask import Response
@register_route("/status")
def status(*, version: int = 1) -> "Response":
return jsonify({"status": "OK", "version": version})
@register_route("/foo", enabled=lambda **params: params.get("version", 1) >= 2)
def foo_a(*, version: int = 1) -> "Response":
return jsonify({"hello": "world"})
@register_route("/foo/<subject>", enabled=lambda **params: params.get("version", 1) >= 2)
def foo_b(subject: str = "world", version: int = 1) -> "Response":
return jsonify({"hello": subject})
By doing so we have registered four routes:
| URL | Return value | Function |
|---|---|---|
| /api/1/status | {"status": "OK", "version": 1} | status |
| /api/2/status | {"status": "OK", "version": 2} | status |
| /api/2/foo | {"hello": "world"} | foo_a |
/api/2/foo/<subject> |
{"hello": <subject>} |
foo_b |
Other examples
The register_route decorator also accept commons flask.route parameters like methods
@register_route("/post", methods=["POST"])
def post_endpoint () -> "Response":
return jsonify({"hello": "world"})
Registering multiple modules at once
register_blueprints (plural) registers multiple route modules under a shared parent blueprint:
from flask import Flask
from flask_dynamic_route_registration import register_blueprints
app = Flask(__name__)
register_blueprints(
app,
"myapp.api",
{
"healthcheck": "",
"users": {"blueprint_kwargs": {"url_prefix": "/users"}},
},
{},
url_prefix="/v1",
)
app.run()
This creates a parent blueprint for myapp.api, registers each sub-module (myapp.api.healthcheck, myapp.api.users) into it, then mounts the parent blueprint on app.
Limitations
As for now you can't register multiple routes at the same time for a given function.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Metadata
Release files for flask-dynamic-route-registration 0.10.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| flask_dynamic_route_registration-0.10.0.tar.gz | 14.3 kB | With provenance | Details for flask_dynamic_route_registration-0.10.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| flask_dynamic_route_registration-0.10.0-py3-none-any.whl | Python 3 | none | any | Details for flask_dynamic_route_registration-0.10.0-py3-none-any.whl |
Total release size: 21.6 kB
Release files / flask_dynamic_route_registration-0.10.0.tar.gz
| Download URL | flask_dynamic_route_registration-0.10.0.tar.gz |
|---|---|
| Size | 14.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b15a594291723e8e0412807695d1d863cae5ff0b2ec32be004397d208e797c6d
|
|
BLAKE2b-256 checksum How to use checksums |
d6045656d4144cda7f9b8c224841a22ad1d8908850b3d2e4c4a7b50969c0ee03
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 13, 2026.
Transparency logRelease files / flask_dynamic_route_registration-0.10.0-py3-none-any.whl
| Download URL | flask_dynamic_route_registration-0.10.0-py3-none-any.whl |
|---|---|
| Size | 7.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9946edf3d60c30018c352d901183bf662ce7842800f88342b877feddc2aa3298
|
|
BLAKE2b-256 checksum How to use checksums |
b66795fcaba4b6b59c1b7c0f7f1548f539332f853fa46f9359d85c7ccddc97c5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 13, 2026.
Transparency logSecurity for flask-dynamic-route-registration 0.10.0
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.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for flask_dynamic_route_registration-0.10.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 13, 2026.
Transparency logA 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.