Autogenerated Api
Get Autogenerated Serializers and API EndPoints
Requirements
- django
- djangorestframework
Tested with all Django versions from `1.8.x to 2.x.x`
Released with latest version of Django.
Note
For Django==1.8.x
- djangorestframework==3.4.2
Installing autogenerated-api
autogenerated-api built for django.
pip install autogenerated_api
Customizable Files in Apps
django_app architecture looks like
- app_name
- __init__.py
- admin.py
- models.py
- serializers.py
- tests.py
- views.py
serilizers.py
from .models import ModelName
from autogenerated_api.serializers import DeadlySerializerFactory
ModelNameDeadlySerializer = DeadlySerializerFactory(modelName)
- DeadlySerializerFactory `Optional Paramaters`
- nest = ["field_1","field_2"]
- nested_fields = {"field_name_in_releation" : ["related_model_field_1","related_model_field_2"]}
- if you want to get all fields of model while is in relation
- nested_fields = {"field_name_in_reletion" : ["*"]}
- exclude = ["field_1","field_2"] : fields that you want to exclude
ModelNameDeadlySerializer = DeadlySerializerFactory(modelName,nest,nested_fields,exclude)
views.py
import app_name.models
import app_name.serializers
from autogenerated_api.autogeneration import make_all_viewsets
make_all_viewsets(__name__)
Create a new file api_urls.py in main project folder.
Main project folder Architecture
- main_proj_name
- __init__.py
- settings.py
- urls.py
- wsgi.py
- api_urls.py
Add below codes in api_urls.py file.
import app_name.views
from django.urls import path, re_path , include
from autogenerated_api import autogenerated_urls
urlpatterns = autogenerated_urls.urlpatterns
urlpatterns += []
Adding to URLs
Add the Below urls.py
import django
dj_version = django.get_version()
from django.contrib import admin
try:
from django.urls import path, include , re_path
except ImportError:
from django.conf.urls import include, url
try:
from django.core.urlresolvers import reverse
except ImportError:
from django.urls import reverse
import re
if re.search('^2[\d.]+',str(dj_version)):
urlpatterns = [
re_path(r'^api/', include(('main_proj_name.api_urls', 'main_proj_name') , namespace="api")),
]
else:
urlpatterns = [
url(r'^admin/', include(admin.site.urls)),
url(r'^api/', include('main_proj_name.api_urls' , namespace="api")),
]
Customizable Fields in Settings.
AUTOGENERATE_APPS = ["app_name"]
Finally, you will get autogenerated seraializers and end points.
- Autogenerated End Points
- `/api/model_name_in_lower/` : list out all the model_instance
- `/api/model_name_in_lower/<instance_id>` : you will get detail of instance of given id
Why use autogenerated_api?
Through autogenerated_api module , you can directly create serializers coresponding to each model and can also access the all fields value of model which are in relation (m2m or foreignkey relationship).
To get the list of model instance , You have to write an api end points , like ListAPiView and for getting the detail of model instance, have to implement DetailAPIView or RetrieveApiView end points.
Now , You don't have to create these APi-end points and get worry about the serailizers . This module will take care. Just , follow the steps that i mentioned above.
Coming
- Module with more functionality and more autogenerated end points.
I will really appreciate if you support the project by clicking the star button on Github repository
Metadata
Release files for autogenerated-api 1.2.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| autogenerated_api-1.2.6.tar.gz | 11.4 kB | Without provenance | Details for autogenerated_api-1.2.6.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| autogenerated_api-1.2.6-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details for autogenerated_api-1.2.6-py2.py3-none-any.whl |
Total release size: 33.5 kB
Release files / autogenerated_api-1.2.6.tar.gz
| Download URL | autogenerated_api-1.2.6.tar.gz |
|---|---|
| Size | 11.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1588a9be5ff3b6e725fe107a3c8e67a28ccb98eb771f966870972a255233f739
|
|
BLAKE2b-256 checksum How to use checksums |
1272ba8eace3022f14996dbf7e61c91a876e91ad599c3e9acd22d4e1d7af1065
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.12.1 pkginfo/1.5.0.1 requests/2.19.1 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.25.0 CPython/3.7.1
|
Release files / autogenerated_api-1.2.6-py2.py3-none-any.whl
| Download URL | autogenerated_api-1.2.6-py2.py3-none-any.whl |
|---|---|
| Size | 22.1 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
d90bc6fd164e43c0f4accf26eab481a488e41f0a50f4ec5deba8c775937247b4
|
|
BLAKE2b-256 checksum How to use checksums |
56985f6f877ea762931e8cdbeef23498f70f14c9b06652050e6e3fe225647adb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.12.1 pkginfo/1.5.0.1 requests/2.19.1 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.25.0 CPython/3.7.1
|
Security for autogenerated-api 1.2.6
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.