Django Easy API - Easy and Fast Django REST framework based on Django-ninja-extra
Project description
Django Easy API Framework
Easy and Fast Django REST framework based on Django-Ninja-Extra
- CRUD Async API Generation: Automatic and configurable, inspired by NextJs-Crud.
- Domain/Service/Controller Base Structure: for better code organization.
- Base Permission/Response/Exception Classes: and many handy features to help your API coding easier
- Pure class based Django-Ninja APIs: thanks to Django-Ninja-Extra
Django-Ninja features:
Easy: Designed to be easy to use and intuitive.
FAST execution: Very high performance thanks to Pydantic and async support.
Fast to code: Type hints and automatic docs lets you focus only on business logic.
Standards-based: Based on the open standards for APIs: OpenAPI (previously known as Swagger) and JSON Schema.
Django friendly: (obviously) has good integration with the Django core and ORM.
Plus Extra:
Class Based: Design your APIs in a class based fashion.
Permissions: Protect endpoint(s) at ease with defined permissions and authorizations at route level or controller level.
Dependency Injection: Controller classes supports dependency injection with python Injector or django_injector. Giving you the ability to inject API dependable services to APIController class and utilizing them where needed
Requirements
- Python >= 3.6
- Django >= 3.1
- pydantic >= 1.6
- Django-Ninja-extra >= 0.15.0
Install
pip install django-api-framework
Then add "easy" to your django INSTALLED_APPS:
[
...,
"easy",
...,
]
Usage
Get all your Django app CRUD APIs up and running
In your Django project next to urls.py create new apis.py file:
from easy.main import EasyAPI
api_admin_v1 = EasyAPI(
urls_namespace="admin_api",
version="v1.0.0",
)
# Automatic Admin API generation
api_admin_v1.auto_create_admin_controllers()
Now go to urls.py and add the following:
from django.urls import path
from .apis import api_admin_v1
urlpatterns = [
path("admin/", admin.site.urls),
path("api_admin/v1/", api_admin_v1.urls), # <---------- !
]
Now go to http://127.0.0.1:8000/api_admin/v1/docs
You will see the automatic interactive API documentation (provided by Swagger UI).
Adding CRUD APIs to a specific API Controller
By inheriting CrudAPIController class, CRUD APIs will be added to your API controller. Configuration is available via Meta class:
model_exclude
: fields to be excluded in Schemamodel_fields
: fields to be included in Schema, default to"__all__"
model_join
: prefetch and retrieve all m2m fields, default to Falsemodel_recursive
: recursively retrieve FK/OneToOne fields, default to Falsesensitive_fields
: fields to be ignored
Example:
@api_controller("even_api", permissions=[AdminSitePermission])
class EventAPIController(CrudAPIController):
def __init__(self, service: EventService):
super().__init__(service)
class Meta:
model = Event # django model
generate_crud = True # whether to create crud api, default to True
model_fields = ["field_1", "field_2",] # if not configured default to "__all__"
model_join = True
model_recursive = True
sensitive_fields = ["password", "sensitive_info"]
Please check tests/demo_app for more examples.
Boilerplate Django project
A boilerplate Django project for quickly getting started, production ready easy-apis wiht 100% test coverage ready: https://github.com/freemindcore/django-easy-api
Thanks to your help
If you find this project useful, please give your stars to support this open-source project. :) Thank you !
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
Hashes for django-api-framework-0.1.32.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 801d2fce8780be6ada700adfc65651d91a7d4244524b4e468aea4b679c938090 |
|
MD5 | c33a1d358a9097d5d98306a124595602 |
|
BLAKE2b-256 | e2327d605485aae607c0445c93c94650067125d6fe3e22832ca9722f742cd542 |
Hashes for django_api_framework-0.1.32-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3eca2c7991d91b73820e39ed76ddeb411c730c7a9d060566825c0115bef6a3e5 |
|
MD5 | 8a18cf0911877929c131305eea2ef969 |
|
BLAKE2b-256 | 416aedb7926ccb118e3b0ce8546e7331b84008dc3e0f2fb682d7c9719e52bbea |