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
Distributed Tracing
spakky-tracing은 필수 의존성으로 자동 설치됩니다. TracingMiddleware가 자동으로 등록되어 모든 HTTP 요청에 대해 TraceContext를 전파합니다.
- 수신 요청의
traceparent헤더에서TraceContext를 추출하여 자식 스팬을 생성합니다 - 헤더가 없으면 새로운 루트 트레이스를 시작합니다
- 요청 완료 후
TraceContext를 자동으로 정리합니다
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 |
TracingMiddleware |
Trace context propagation middleware (spakky-tracing 필수 의존) |
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.3.1.tar.gz.
File metadata
- Download URL: spakky_fastapi-6.3.1.tar.gz
- Upload date:
- Size: 11.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
33729bac255f66311176f54e809e46962136e852ce6ad98d85f3ba7865bd93fc
|
|
| MD5 |
695385bee4a114ce19eb309188d8fc52
|
|
| BLAKE2b-256 |
ed51b9b34fe7dbfc1ae1fa8627d1b88c0d58611a43ca96dad847d27b4ff3e7b1
|
Provenance
The following attestation bundles were made for spakky_fastapi-6.3.1.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.3.1.tar.gz -
Subject digest:
33729bac255f66311176f54e809e46962136e852ce6ad98d85f3ba7865bd93fc - Sigstore transparency entry: 1236504251
- Sigstore integration time:
-
Permalink:
E5presso/spakky-framework@6d8469ad090c00a829421ab05aafc6d10178d93f -
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@6d8469ad090c00a829421ab05aafc6d10178d93f -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file spakky_fastapi-6.3.1-py3-none-any.whl.
File metadata
- Download URL: spakky_fastapi-6.3.1-py3-none-any.whl
- Upload date:
- Size: 27.3 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 |
7e81438b0c88ed1cde792a13f6d149b2a9df5e781a079a77cbc6442fe2b1f320
|
|
| MD5 |
90236c7e6e229f922eb48e883558b216
|
|
| BLAKE2b-256 |
48c137f35cc5ae9ac93d220005d582912954945b4f4c7ac1405fdb9b85815e07
|
Provenance
The following attestation bundles were made for spakky_fastapi-6.3.1-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.3.1-py3-none-any.whl -
Subject digest:
7e81438b0c88ed1cde792a13f6d149b2a9df5e781a079a77cbc6442fe2b1f320 - Sigstore transparency entry: 1236504256
- Sigstore integration time:
-
Permalink:
E5presso/spakky-framework@6d8469ad090c00a829421ab05aafc6d10178d93f -
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@6d8469ad090c00a829421ab05aafc6d10178d93f -
Trigger Event:
workflow_dispatch
-
Statement type: