FastAPI Class Views and utilities
Project description
fastapi-views
FastAPI Class Views and utilities
Documentation: https://asynq-io.github.io/fastapi-views/
Repository: https://github.com/asynq-io/fastapi-views
Installation
pip install fastapi-views
Usage
from typing import ClassVar, Optional
from uuid import UUID
from fastapi import FastAPI
from pydantic import BaseModel
from fastapi_views import ViewRouter, configure_app
from fastapi_views.views.viewsets import AsyncAPIViewSet
class UpdateItemSchema(BaseModel):
name: str
price: int
class ItemSchema(BaseModel):
id: UUID
name: str
price: int
class MyViewSet(AsyncAPIViewSet):
api_component_name = "Item"
response_schema = ItemSchema
items: ClassVar[dict[UUID, ItemSchema]] = {}
async def list(self) -> list[ItemSchema]:
return list(self.items.values())
async def create(self, item: ItemSchema) -> ItemSchema:
self.items[item.id] = item
return item
async def retrieve(self, id: UUID) -> Optional[ItemSchema]:
return self.items.get(id)
async def update(self, id: UUID, item: UpdateItemSchema) -> ItemSchema:
self.items[id] = ItemSchema(id=id, name=item.name, price=item.price)
return self.items[id]
async def destroy(self, id: UUID) -> None:
self.items.pop(id, None)
router = ViewRouter(prefix="/items")
router.register_view(MyViewSet)
app = FastAPI(title="My API")
app.include_router(router)
configure_app(app)
Features
- Class Based Views
- APIViews
- ViewSets
- Both async and sync function support
- No dependencies on ORM
- OpenAPI operation id simplification
- 'Smart' and fast serialization using Pydantic v2
- Http Problem Details implementation (both models & exception classes)
- Automatic prometheus metrics exporter
- Optional Opentelemetry instrumentation with
correlation_id
in error responses - CLI for generating OpenAPI documentation file
- Pagination types & schemas
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
fastapi_views-1.2.2.tar.gz
(25.6 kB
view details)
Built Distribution
File details
Details for the file fastapi_views-1.2.2.tar.gz
.
File metadata
- Download URL: fastapi_views-1.2.2.tar.gz
- Upload date:
- Size: 25.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
3de29993fb2897de6e571f9ea7794025582a48c44ed15c803a7776b7ac28e40b
|
|
MD5 |
c6e8a366b9358d2ff862f9d854a78142
|
|
BLAKE2b-256 |
8ff3c6b9e49a9acb43c4a5551612cf48cf60115ab3ed63a036787d6f53f5ad92
|
File details
Details for the file fastapi_views-1.2.2-py3-none-any.whl
.
File metadata
- Download URL: fastapi_views-1.2.2-py3-none-any.whl
- Upload date:
- Size: 28.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
e40ccbbac4487c627b933d56e166533e12b150e06cb7366f583a81b71d8f13e6
|
|
MD5 |
a647840b34255edb2a02a560475fb163
|
|
BLAKE2b-256 |
0660a7f49a4d0274fca15ba363bd4030541f294011dda981feb8726894f527bd
|