Skip to main content

🪄 FastAPI router with magical powers ✨

Project description

🪄 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)

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

Project details


Download files

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

Source Distribution

fastapi_magic_router-0.2.0.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

fastapi_magic_router-0.2.0-py3-none-any.whl (4.4 kB view details)

Uploaded Python 3

File details

Details for the file fastapi_magic_router-0.2.0.tar.gz.

File metadata

  • Download URL: fastapi_magic_router-0.2.0.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.13

File hashes

Hashes for fastapi_magic_router-0.2.0.tar.gz
Algorithm Hash digest
SHA256 a7e0a56c4a485be30a3572e7105b33e2ca0d534643929ffaca339a2032ef85ae
MD5 b63d45bddd0c77a4328072fdebe0fd7e
BLAKE2b-256 e8f7765ac263100abe07cdb8088b3edb7d476bc70ed9b0bcb84c5b76e88361bb

See more details on using hashes here.

File details

Details for the file fastapi_magic_router-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for fastapi_magic_router-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d84d1fa31f186d01473a034192bf31e3b2d13656602122091e84d593e55e44a3
MD5 d79047a29b800af67a2be37d327970c3
BLAKE2b-256 5505909ebe1cbde88d694c26a0e1dc6df547c0e80300002be90ffd1a25c268e8

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page