Skip to main content

🪄 FastAPI Magic Router ✨

Have you come here seeking a magical way to define FastAPI routes?

app = FastAPI()
route = magic_router(app)

route("GET     /api/users          ", user.list_)
route("GET     /api/users/{user_id}", user.get)
route("POST    /api/users          ", user.create)
route("PATCH   /api/users/{user_id}", user.update)
route("DELETE  /api/users/{user_id}", user.delete_)

Come, I shall grant you your wish!

Default Router vs Magic Router

from fastapi import FastAPI
from pydantic import BaseModel
from magic_router import magic_router, magic


class Response(BaseModel):
    path: str


# Default Router -----------------------------------------------------------------------

app = FastAPI()
not_so_magical_path = "/api/not-so-magical"

async def not_so_magical_endpoint():
    return Response(path=not_so_magical_path)

app.get(
    not_so_magical_path,
    response_model=Response,
    tags=["main"],
    operation_id="not_so_magical_endpoint",
    name="not_so_magical_endpoint",
)(not_so_magical_endpoint)

# Magic Router -------------------------------------------------------------------------

route = magic_router(app)

async def magical_endpoint() -> Response:
    return Response(path=magic(magical_endpoint).path)

route("GET /api/magical", magical_endpoint)

# --------------------------------------------------------------------------------------

Release files for fastapi-magic-router 0.2.0

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

Source distribution (sdist)

Source distribution for fastapi-magic-router 0.2.0
File Size Uploaded
fastapi_magic_router-0.2.0.tar.gz 4.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for fastapi-magic-router 0.2.0
File Interpreter ABI Platform
fastapi_magic_router-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 9.0 kB

Release files / fastapi_magic_router-0.2.0.tar.gz

Download URL fastapi_magic_router-0.2.0.tar.gz
Size 4.6 kB
Tags Source
SHA-256 checksum
How to use checksums
a7e0a56c4a485be30a3572e7105b33e2ca0d534643929ffaca339a2032ef85ae
BLAKE2b-256 checksum
How to use checksums
e8f7765ac263100abe07cdb8088b3edb7d476bc70ed9b0bcb84c5b76e88361bb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.13

Release files / fastapi_magic_router-0.2.0-py3-none-any.whl

Download URL fastapi_magic_router-0.2.0-py3-none-any.whl
Size 4.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d84d1fa31f186d01473a034192bf31e3b2d13656602122091e84d593e55e44a3
BLAKE2b-256 checksum
How to use checksums
5505909ebe1cbde88d694c26a0e1dc6df547c0e80300002be90ffd1a25c268e8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.13

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release 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