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          ", list_users)
route("GET     /api/users/{user_id}", get_user)
route("POST    /api/users          ", create_user)
route("PATCH   /api/users/{user_id}", update_user)
route("DELETE  /api/users/{user_id}", delete_user)

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.1.2.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

fastapi_magic_router-0.1.2-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: fastapi_magic_router-0.1.2.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.1.2.tar.gz
Algorithm Hash digest
SHA256 2dc28bc7ea0b8fc3b51102a9f8791248b172d1677102fa53118a72be6039d287
MD5 62a3ce6dde088b698a7af810f823c2d9
BLAKE2b-256 4a909579830c5ca2d4743eb41b696b8f78f30332133c5c931147a7d510c98283

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fastapi_magic_router-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 7fb0f04f79e8c737d628e55fa32f058f77ac5f47fd77b5cc46c31d6141862ba7
MD5 e26bb3591cf00630280ac3b3cbb24b41
BLAKE2b-256 3ab962e52b8c4d08f9704fa95435c9e140124955d59ce17d7d8bc4a78622812e

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