FastAPI plugin for Spakky framework
Project description
Spakky FastAPI
FastAPI integration plugin for Spakky Framework.
Installation
pip install spakky-fastapi
Or install via Spakky extras:
pip install spakky[fastapi]
Features
- Automatic route registration: Routes are registered from
@ApiControllerclasses - All HTTP methods: GET, POST, PUT, DELETE, PATCH, HEAD, OPTIONS, WebSocket
- OpenAPI integration: Tags and documentation automatically configured
- Error handling middleware: Built-in exception handling with debug mode
- Context management: Request-scoped dependency injection support
Usage
Basic Controller
from spakky.plugins.fastapi.stereotypes.api_controller import ApiController
from spakky.plugins.fastapi.routes import get, post
@ApiController("/users", tags=["users"])
class UserController:
def __init__(self, user_service: UserService) -> None:
self.user_service = user_service
@get("/{user_id}")
async def get_user(self, user_id: int) -> User:
return await self.user_service.get(user_id)
@post("")
async def create_user(self, request: CreateUserRequest) -> User:
return await self.user_service.create(request)
Available Route Decorators
from spakky.plugins.fastapi.routes import (
get,
post,
put,
delete,
patch,
head,
options,
websocket,
)
@ApiController("/api")
class MyController:
@get("/items")
async def list_items(self) -> list[Item]:
...
@post("/items")
async def create_item(self, item: CreateItemRequest) -> Item:
...
@put("/items/{item_id}")
async def update_item(self, item_id: int, item: UpdateItemRequest) -> Item:
...
@delete("/items/{item_id}")
async def delete_item(self, item_id: int) -> None:
...
@websocket("/ws")
async def websocket_endpoint(self, websocket: WebSocket) -> None:
await websocket.accept()
while True:
data = await websocket.receive_text()
await websocket.send_text(f"Echo: {data}")
Accessing FastAPI Instance
from fastapi import FastAPI
from spakky.core.application.application import SpakkyApplication
# After application.start()
fast_api = application.container.get(FastAPI)
Testing with TestClient
from fastapi.testclient import TestClient
def test_get_user(application: SpakkyApplication) -> None:
fast_api = application.container.get(FastAPI)
client = TestClient(fast_api)
response = client.get("/users/1")
assert response.status_code == 200
Components
| Component | Description |
|---|---|
ApiController |
Stereotype for REST API controllers with prefix and tags |
get, post, put, etc. |
Route decorators for HTTP methods |
websocket |
WebSocket endpoint decorator |
ErrorHandlingMiddleware |
Built-in exception handling middleware |
RegisterRoutesPostProcessor |
Automatic route registration post-processor |
Configuration
The plugin automatically registers a FastAPI instance as a Pod. You can customize it by registering your own FastAPI instance before loading the plugin:
from fastapi import FastAPI
@Pod()
def custom_fastapi() -> FastAPI:
return FastAPI(
title="My API",
description="Custom API configuration",
version="1.0.0",
)
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file spakky_fastapi-6.1.3.tar.gz.
File metadata
- Download URL: spakky_fastapi-6.1.3.tar.gz
- Upload date:
- Size: 10.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
23bb44eeebf6b4f53e8c75fe11397b2dbe4e9d26c92e57c37085839f145cac00
|
|
| MD5 |
18a852f0126a1d727025268b5cb0b2c4
|
|
| BLAKE2b-256 |
4440fccebca8e7c50d5c16d19b8c011d035b4ee2efcef1f02e4695a37d99c0ca
|
Provenance
The following attestation bundles were made for spakky_fastapi-6.1.3.tar.gz:
Publisher:
release.yml on E5presso/spakky-framework
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
spakky_fastapi-6.1.3.tar.gz -
Subject digest:
23bb44eeebf6b4f53e8c75fe11397b2dbe4e9d26c92e57c37085839f145cac00 - Sigstore transparency entry: 1110386774
- Sigstore integration time:
-
Permalink:
E5presso/spakky-framework@e597ac5d16b5f9a964808fc66f1f6cc0a7d5df59 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/E5presso
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@e597ac5d16b5f9a964808fc66f1f6cc0a7d5df59 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file spakky_fastapi-6.1.3-py3-none-any.whl.
File metadata
- Download URL: spakky_fastapi-6.1.3-py3-none-any.whl
- Upload date:
- Size: 25.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
06d267ccafdc1ffd20ccffa6e8490527ef8462c0595ed58538e57edf9742dc7d
|
|
| MD5 |
8c86ec4dc55a6682ea88c7202a591b88
|
|
| BLAKE2b-256 |
1008dcec4428c185dfc9d623cdf0da296add749ee9859ef333105e6063bd6d67
|
Provenance
The following attestation bundles were made for spakky_fastapi-6.1.3-py3-none-any.whl:
Publisher:
release.yml on E5presso/spakky-framework
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
spakky_fastapi-6.1.3-py3-none-any.whl -
Subject digest:
06d267ccafdc1ffd20ccffa6e8490527ef8462c0595ed58538e57edf9742dc7d - Sigstore transparency entry: 1110387012
- Sigstore integration time:
-
Permalink:
E5presso/spakky-framework@e597ac5d16b5f9a964808fc66f1f6cc0a7d5df59 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/E5presso
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@e597ac5d16b5f9a964808fc66f1f6cc0a7d5df59 -
Trigger Event:
workflow_dispatch
-
Statement type: