Skip to main content

FastAPI Class Views and utilities

Project description

fastapi-views

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

FastAPI Class Views and utilities


Version: 0.1.0

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

Repository: https://github.com/performancemedia/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.1.0.tar.gz (18.5 kB view details)

Uploaded Source

Built Distribution

fastapi_views-0.1.0-py3-none-any.whl (23.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: fastapi_views-0.1.0.tar.gz
  • Upload date:
  • Size: 18.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.8

File hashes

Hashes for fastapi_views-0.1.0.tar.gz
Algorithm Hash digest
SHA256 64f561ce6f8c81a8eee04b271887fb3c850921c2365bbcc63df9aa68c221b697
MD5 39578c9b0f422cda5c5dbb5b3db5e6a9
BLAKE2b-256 09d525accea99995170735c11adcf9bb780fa48c45f259d1d9523fd5846dbd4c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fastapi_views-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 471c45ab3728d28835ce7b61175d50fc8e44967f505d61d47f1dfbb772078402
MD5 0fe1f31feba6bfbe08b9a1af77342c67
BLAKE2b-256 30013172926df69817289cb3e61ce0820ff1fab89a8eea7b03ef75aa1c756bb1

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