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
Quick Start
- Install the library inside your virtualenv by using pip
pip install fast-drf - 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,
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": "", # (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
fast-drf-2.1.3.tar.gz
(15.0 kB
view details)
File details
Details for the file fast-drf-2.1.3.tar.gz.
File metadata
- Download URL: fast-drf-2.1.3.tar.gz
- Upload date:
- Size: 15.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
53f638a21c5ebcbd522c8edb398e556a918b73c74fda9c27d5715eb16ba6e74c
|
|
| MD5 |
e622f13633cd3f7f13f4b4e4b89499fa
|
|
| BLAKE2b-256 |
42e7ddfff3ee434c750e364eab4484393b0c53f264bafbbedf3f779de8c31fbf
|