A simple model based API configarator written in Python and based of Django and Django REST Framework
Project description
Fast DRF

Fast DRF is a small library for making API faster with Django and Django REST Framework. It's easy and configurable.
Full Documentation here
Change Log is here
Features
- Runtime API creation without writing View, Serializer, Url, etc
- API versioning by default.
- Control fields on each versions
- An enhanced filtering support align with Django query filter.
- Customizable API URL and API Prefix.
- Options for Overriding Viewset, Serializer, Queryset
- Query optimization enabled for API with Django's
prefetch_relatedandselect_related - Full control over project during making automated API. i.e: you can select an Django app to enable for making API.
Quick Start
- Install the library inside your virtualenv by using pip
pip install fast-drf - Add 'rest_framework' to
INSTALLED_APPS - Add fast_drf.router.BasicRouter.get_urls() to the
urlpatternsinurls.py, e.g.
from django.contrib import admin
from django.urls import path
from fast_drf.router import BasicRouter
urlpatterns = [
path('admin/', admin.site.urls),
] + BasicRouter.get_urls()
- Add config for Fast DRF like following,
FAST_DRF_CONFIG = {
'DEFAULT_APPLIED_APPS': (
'example_app', 'another_app'
)
}
- Update your every model or if you use base abstract model then it's good and less time you need. Update model like following,
Overriding the
expose_apiclassmethod is not necessary anymore. If you just inherit theExposeApiModelMixinmixin class then your app will be detect a api url accordingly.
from fast_drf.mixins.expose_api_model_mixin import ExposeApiModelMixin
from django.db import models
class MyModel(ExposeApiModelMixin, models.Model):
#... All yor fields
pass
# The following methods are available from model mixin
@classmethod
def exposed_api(cls, *args, **kwargs):
"""
This method holds a bunch of API configs and return like following...
{
"api_url": "", # (NOT REQUIRED)
# You must use from HTTPVerbsEnum. Like HTTPVerbsEnum.GET.value, HTTPVerbsEnum.POST.value
"allowed_methods": ['get', 'post', 'put', 'patch', 'delete'], # (NOT REQUIRED)
# slug_field is application 'put', 'patch', 'delete' these methods
"slug_field": "pk", # (NOT REQUIRED) DEFAULT [PK] (Must be model field, unique or primary key)
"queryset": "", # (NOT REQUIRED) default all
"viewset_class": "", # (NOT REQUIRED) BaseViewset class
"serializer_class": "", # (NOT REQUIRED) default BaseEntitySerializer
"permission_classes": "", # (NOT REQUIRED) default set from settings
}
:param args:
:param kwargs:
:return: An empty Dictionary/False OR Full config dictionary.
"""
api_configs = {
"api_url": 'my-model-api',
}
return api_configs
Enable multiple API version
To achieve this awesomeness rewrite the following method in your model
@classmethod
def api_version_fields(cls, **kwargs):
"""
*** DEFAULT VERSION `v1` ***
This method will return a dictionary object with version number and fields name. Fields are similar like
serializer fields. Or you can say exactly as same as serializer fields.
:param kwargs: Currently nothing to receive on kwargs
:return: a dictionary object with version number
"""
versions = {
'v1': ['id', 'name', 'custom_1', 'custom_2'],
'v2': ['id', 'name', 'something_else']
}
return versions
Append a slash at the end of of API
Set APPEND_SLASH = True at your settings.py
API Prefix Change
Set you API prefix as your own like following.
FAST_DRF_CONFIG = {
# ...
'DEFAULT_API_PREFIX': 'rest-api' # Default 'api'
# ...
}
Your API will look like, /rest-api/v1/users/
That's it. You can also override serializer class and viewset class
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fast_drf-2.2.12.tar.gz.
File metadata
- Download URL: fast_drf-2.2.12.tar.gz
- Upload date:
- Size: 14.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.6.1 CPython/3.11.5 Darwin/23.1.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c934c670988cb9f9754eabb981028b2994f6e7841607e4b5ef4953e314c5b1a5
|
|
| MD5 |
7f60de7acb51f7111bc407161f01e0ce
|
|
| BLAKE2b-256 |
62d94ef177d60852455fecf545e7eb94d00754605c25cc6b2034319921a0bc07
|
File details
Details for the file fast_drf-2.2.12-py3-none-any.whl.
File metadata
- Download URL: fast_drf-2.2.12-py3-none-any.whl
- Upload date:
- Size: 21.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.6.1 CPython/3.11.5 Darwin/23.1.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1f52b27c6b26d27236a0224ab3710f655d1f112a3cc61e95c5f04bd2ac296ae8
|
|
| MD5 |
bf608197f5f05205811bf4103a8c23e8
|
|
| BLAKE2b-256 |
3d8cf09fd19b35f277ae96307847132bb09056b6c5be8fad64c7dd6ef6289bd7
|