Metadata-Version: 2.3
Name: fastapi-views
Version: 1.0.3rc0
Summary: FastAPI Class Views and utilities
Project-URL: Documentation, https://github.com/asynq-io/fastapi-views#readme
Project-URL: Issues, https://github.com/asynq-io/fastapi-views/issues
Project-URL: Source, https://github.com/asynq-io/fastapi-views
Author-email: RaRhAeu <rarha_eu@protonmail.com>
License: Apache-2.0
Keywords: asyncio,fastapi,views
Classifier: Development Status :: 4 - Beta
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: Implementation :: CPython
Classifier: Programming Language :: Python :: Implementation :: PyPy
Requires-Python: >=3.9
Requires-Dist: fastapi
Requires-Dist: pydantic<3,>2.0
Provides-Extra: all
Requires-Dist: opentelemetry-instrumentation-fastapi; extra == 'all'
Requires-Dist: starlette-exporter; extra == 'all'
Requires-Dist: typer; extra == 'all'
Requires-Dist: uvicorn; extra == 'all'
Requires-Dist: uvloop; extra == 'all'
Provides-Extra: cli
Requires-Dist: typer; extra == 'cli'
Provides-Extra: opentelemetry
Requires-Dist: opentelemetry-instrumentation-fastapi; extra == 'opentelemetry'
Provides-Extra: prometheus
Requires-Dist: starlette-exporter; extra == 'prometheus'
Provides-Extra: uvicorn
Requires-Dist: uvicorn; extra == 'uvicorn'
Provides-Extra: uvloop
Requires-Dist: uvloop; extra == 'uvloop'
Description-Content-Type: text/markdown

# fastapi-views

![Tests](https://github.com/asynq-io/fastapi-views/workflows/Tests/badge.svg)
![Build](https://github.com/asynq-io/fastapi-views/workflows/Publish/badge.svg)
![License](https://img.shields.io/github/license/asynq-io/fastapi-views)
![Mypy](https://img.shields.io/badge/mypy-checked-blue)
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/charliermarsh/ruff/main/assets/badge/v1.json)](https://github.com/charliermarsh/ruff)
[![Pydantic v2](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/pydantic/pydantic/main/docs/badge/v2.json)](https://docs.pydantic.dev/latest/contributing/#badges)
[![security: bandit](https://img.shields.io/badge/security-bandit-yellow.svg)](https://github.com/PyCQA/bandit)
![Python](https://img.shields.io/pypi/pyversions/fastapi-views)
![Format](https://img.shields.io/pypi/format/fastapi-views)
![PyPi](https://img.shields.io/pypi/v/fastapi-views)

*FastAPI Class Views and utilities*

---
Documentation: https://asynq-io.github.io/fastapi-views/

Repository: https://github.com/asynq-io/fastapi-views

---

## Installation

```shell
pip install fastapi-views
```

## Usage

```python
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
