Metadata-Version: 2.1
Name: fastapi-views
Version: 0.1.2
Summary: FastAPI Class Views and utilities
Author: Radzim Kowalow
Author-email: radzim.kowalow@performance-media.pl
Requires-Python: >=3.9,<4.0
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Provides-Extra: opentelemetry
Provides-Extra: prometheus
Provides-Extra: uvicorn
Provides-Extra: uvloop
Requires-Dist: fastapi (>=0.109.2,<0.110.0)
Requires-Dist: opentelemetry-instrumentation-fastapi ; extra == "opentelemetry"
Requires-Dist: orjson (>=3.9.10,<4.0.0)
Requires-Dist: pydantic (>=2.0,<3.0)
Requires-Dist: pydantic-settings (>=2.0,<3.0)
Requires-Dist: starlette-exporter (>=0.17.1,<0.18.0) ; extra == "prometheus"
Requires-Dist: uvicorn (>=0.27.1,<0.28.0) ; extra == "uvicorn"
Requires-Dist: uvloop (>=0.19.0,<0.20.0) ; extra == "uvloop"
Description-Content-Type: text/markdown

# fastapi-views

![CI](https://github.com/performancemedia/fastapi-views/workflows/CI/badge.svg)
![Build](https://github.com/performancemedia/fastapi-views/workflows/Publish/badge.svg)
![License](https://img.shields.io/github/license/performancemedia/fastapi-views)
![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)
![Mypy](https://img.shields.io/badge/mypy-checked-blue)
![Code Style](https://img.shields.io/badge/code%20style-black-000000.svg)
[![security: bandit](https://img.shields.io/badge/security-bandit-yellow.svg)](https://github.com/PyCQA/bandit)

*FastAPI Class Views and utilities*

---
Version: 0.1.2 

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

Repository: https://github.com/performancemedia/fastapi-views

---

## Installation

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

## Usage

```python
from typing import Optional
from uuid import UUID

from fastapi_views import Serializer, ViewRouter
from fastapi_views.views.viewsets import AsyncAPIViewSet


class ItemSchema(Serializer):
    id: UUID
    name: str
    price: int


items = {}


class MyViewSet(AsyncAPIViewSet):
    api_component_name = "Item"
    serializer = ItemSchema
    
    async def list(self):
        return list(items.values())

    async def create(self, item: ItemSchema) -> ItemSchema:
        items[item.id] = item
        return item

    async def retrieve(self, id: UUID) -> Optional[ItemSchema]:
        return items.get(id)

    async def update(self, item: ItemSchema):
        items[item.id] = item

    async def destroy(self, id: UUID) -> None:
        items.pop(id, None)

router = ViewRouter(prefix="/items")
router.register_view(MyViewSet)
# in app.py
# app.include_router(router)

```

## Features

- Class Based Views
  - APIViews
  - GenericViews
  - ViewSets
- Both async and sync function support
- No dependencies on ORM
- Openapi id simplification
- 'Smart' and fast serialization using orjson
- Http Problem Details implementation
- Automatic prometheus metrics exporter
- Pluggable healthcheck helper

