django-api-generator
django-api-generator copied to clipboard
API Generator for Django - Open-Source Library | AppSeed
Django API Generator
Simple tool that Generates Secure APIs on top of DRF with minimum effort - actively supported by AppSeed.
- Django Dynamic Services -
sample project that uses the library - Django - Build Services without Coding -
video presentation
Features
API engineprovided byDRF- Secured by
JWT Tokens(mutating requests) Minimal Configuration(single line in config for each model)Handles any modeldefined across the projectCRUDaccess logic:READis public (all items, get item by ID)Mutating requestsare protected byJWT Tokens

How to use it
Step #1 -
Install the package
$ pip install django-api-generator
// OR
$ pip install git+https://github.com/app-generator/django-api-generator.git
Step #2 -
Update Configuration, include the new APPs
INSTALLED_APPS = [
'django_api_gen', # Django API GENERATOR # <-- NEW
'rest_framework', # Include DRF # <-- NEW
'rest_framework.authtoken', # Include DRF Auth # <-- NEW
]
Step #3 -
Register the modelincore/settings.py(API_GENERATOR section)
This sample code assumes that app1 exists and model Book is defined and migrated.
API_GENERATOR = {
# pattern:
# API_SLUG -> Import_PATH
'books' : "app1.models.Book",
}
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': [
'rest_framework.authentication.SessionAuthentication',
'rest_framework.authentication.TokenAuthentication',
],
}
Step #4 -
Migrate DBand create the tables used byDRF
$ python manage.py makemigrations
$ python manage.py migrate
Step #5 -
Generate API
$ python manage.py generate-api
// OR
$ python manage.py generate-api -f # supress confirmation (forcing mode)
The code is generated under the api folder in the ROOT of the project. At each iteration the API code is overwritten.
Step #6 -
Update routing, include APIs
from django.contrib import admin
from django.urls import path, include # <-- UPD: 'include` directive
from rest_framework.authtoken.views import obtain_auth_token # <-- NEW
urlpatterns = [
path("admin/", admin.site.urls),
path("api/", include("api.urls")), # <-- NEW
path('login/jwt/', view=obtain_auth_token), # <-- NEW
]
Step #7 -
Use API
If the managed model is Books, the API interface is /api/books/ and all CRUD methods are available.
Note: for mutating requests, the
JWT Tokenis provided byhttp://localhost:8000/login/jwt/route (the user should exist).

Links & resources
- DRF - HOMEpage
- More Developer Tools provided by
AppSeed - Ask for Support via
Email&Discord
Django API Generator - Open-source library provided by AppSeed