Skip to main content

FastApi Gino ViewSets

Project description

Inspired by Django Rest Framework

Python 3.7+
Install: pip install fastapi-gino-viewsets

Github: https://github.com/basalex/fastapi_gino_viewsets

Examples of usage:

Create your model and migrate database

class User(db.Model):
    __tablename__ = 'users'
    id = db.Column(db.Integer(), primary_key=True)
    username = db.Column(db.String(255), nullable=False, unique=True)
    email = db.Column(db.EmailType, nullable=False, unique=True)
    age = db.Column(db.Integer(), nullable=True)

Then, you would want to use MainRouter class

from fastapi_gino_viewsets import MainRouter
from fastapi_gino_viewsets import Viewset

router = MainRouter()

@router.add_view('/user)
class UserViewSet(ViewSet):
    model = User
That’s it! Now all methods -> get[+list+filters], post, patch, put, deletes are available and ready for use

Available Mixin and ViewSet classes

  • AggregationMixin - Requires output_schema -> retrieve_aggregated_data
    • get_query[sync, async] - required to be manually implemented

    • filter_query - override to change filters behaviour

  • ListMixin - Used when you want to get a list of objects, main method -> retrieve_list methods
    • base_list_schema -> override base class for output schema

    • retrieve_list - it’s not recommended to be overridden, probably you just don’t need to use the mixin

    • get_query[sync, async] - override to change default behaviour

    • filter_query - override to change filters behaviour

    • sort_query - override to change sort behaviour

    • total - override to change total count calculation

    • paginate - override to change paginate behaviour

    • prepare_data_hook - override for manipulating data after query execution

  • RetrieveModelMixin - Get single object by id -> retrieve method

  • UpdateModelMixin - Update using PUT http -> update method

  • UpdateModelMixin - Update using PATCH http -> update_partial method

  • DeleteModelMixin - Delete object by id -> delete method

  • ReadOnlyViewset - Provides retrieve and retrieve_list methods

  • Viewset - Prodiveds all methods from all mixins, but AggregationMixin

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-gino-viewsets-0.1.0b6.tar.gz (14.1 kB view hashes)

Uploaded Source

Built Distribution

fastapi_gino_viewsets-0.1.0b6-py3-none-any.whl (20.4 kB view hashes)

Uploaded Python 3

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