Skip to main content

FastAPI Class Views and utilities

Project description

fastapi-views

Tests Build License Python Format PyPi Mypy Code Style security: bandit

FastAPI Class Views and utilities


Version: 0.3.2

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

Project details


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-0.3.2.tar.gz (19.8 kB view details)

Uploaded Source

Built Distribution

fastapi_views-0.3.2-py3-none-any.whl (25.7 kB view details)

Uploaded Python 3

File details

Details for the file fastapi_views-0.3.2.tar.gz.

File metadata

  • Download URL: fastapi_views-0.3.2.tar.gz
  • Upload date:
  • Size: 19.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.5

File hashes

Hashes for fastapi_views-0.3.2.tar.gz
Algorithm Hash digest
SHA256 04f2c261fd91da23cc20788f7b6c9f74ee596eea4bb673df43dcde44183c5c3b
MD5 ed6158d3cce9dfe90476fe149a509f7e
BLAKE2b-256 751920a5d2190f4c719cab53ec8c241d0197919c8f3a33d1079683d23bf87a2f

See more details on using hashes here.

File details

Details for the file fastapi_views-0.3.2-py3-none-any.whl.

File metadata

File hashes

Hashes for fastapi_views-0.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 4687ef51e162c67586a16bb486da249e07b90f16506f05630fca60152e839470
MD5 560b6d13d9acfcbec9a7260e76321dce
BLAKE2b-256 fe1b654ede8b105681a32ee41838f53f485b0d5a282afbd41978f5c298d24e6f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page