Skip to main content

A Django Next generator

Project description

Django API Generator

Simple tool that Generates Secure APIs on top of DRF with minimum effort - actively supported by App-Generator.



For a complete set of features and long-term support, check out Dynamic Django, a powerful starter that incorporates:

  • Dynamic DataTables: using a single line of configuration, the data saved in any table is automatically managed
  • Dynamic API: any model can become a secure API Endpoint using DRF
  • Dynamic Charts: extract relevant charts without coding all major types are supported
  • CSV Loader: translate CSV files into Django Models and (optional) load the information
  • Powerful CLI Tools for the GIT interface, configuration editing, updating the configuration and database (create models, migrate DB)

Features

  • API engine provided by DRF
  • Secured by JWT Tokens (mutating requests)
  • Minimal Configuration (single line in config for each model)
  • Handles any model defined across the project
  • CRUD access logic:
    • READ is public (all items, get item by ID)
    • Mutating requests are protected by JWT Tokens

Django API Generator - DRF Interface (open-source tool).


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 model in core/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 DB and create the tables used by DRF

$ 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 Token is provided by http://localhost:8000/login/jwt/ route (the user should exist).


Django API Generator - POSTMAN Interface (open-source tool).


Links & resources



Django API Generator - Open-source library provided by App-Generator

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

django_next_gen-0.1.0.tar.gz (38.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_next_gen-0.1.0-py3-none-any.whl (59.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: django_next_gen-0.1.0.tar.gz
  • Upload date:
  • Size: 38.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for django_next_gen-0.1.0.tar.gz
Algorithm Hash digest
SHA256 4a7fe704e081eac31f07ac949617621f29a1f98ee42035cdf89288ba5775e276
MD5 1ab24ba5577b6ad104593bbcb0b5bdf2
BLAKE2b-256 be3a5eba3c0f0b2f690f35569ad6e53b5bc7f3b15fdb72394b3ea90055fe2fb3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for django_next_gen-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 dcd78c1181fa8905286fcd107b4134a965330dacffa8597d4dfa551279403336
MD5 06e7d828203219b40fdd908e01df36d9
BLAKE2b-256 258f79f40a56c85f63e593db690980399c6c4646dbc8815153862afa8d374b0f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page