|
1 | | - |
2 | | -[](https://badge.fury.io/py/django-ninja-extra) |
3 | | -[](https://pypi.python.org/pypi/django-ninja-extra) |
4 | | -[](https://pypi.python.org/pypi/django-ninja-extra) |
5 | | -[](https://pypi.python.org/pypi/django-ninja-extra) |
6 | | -[](https://codecov.io/gh/eadwinCode/django-ninja-extra) |
7 | | -[](https://pepy.tech/project/django-ninja-extra) |
8 | | - |
9 | | -# Django Ninja Extra |
10 | | - |
11 | | -**Django Ninja Extra** is a complete class-based fashion of building and setting up APIs at incredible speed with incredible performance. |
12 | | -It utilizes [**Django Ninja**](https://django-ninja.rest-framework.com) core features without compromising speed. |
13 | | - |
14 | | -**Key features:** |
15 | | - |
16 | | -All **Django-Ninja** features : |
17 | | - |
18 | | -- **Easy**: Designed to be easy to use and intuitive. |
19 | | -- **FAST execution**: Very high performance thanks to **<a href="https://pydantic-docs.helpmanual.io" target="_blank">Pydantic</a>** and **<a href="/async-support/">async support</a>**. |
20 | | -- **Fast to code**: Type hints and automatic docs lets you focus only on business logic. |
21 | | -- **Standards-based**: Based on the open standards for APIs: **OpenAPI** (previously known as Swagger) and **JSON Schema**. |
22 | | -- **Django friendly**: (obviously) has good integration with the Django core and ORM. |
23 | | - |
24 | | -Plus **Extra**: |
25 | | - |
26 | | -- **Class Based**: Design your APIs in a class based fashion. |
27 | | -- **Permissions**: Protect endpoint(s) at ease with defined permissions and authorizations at route level or controller level. |
28 | | -- **Dependency Injection**: Controller classes supports dependency injection with python [**Injector** ](https://injector.readthedocs.io/en/latest/) or [**django_injector**](https://github.com/blubber/django_injector). Giving you the ability to inject API dependable services to APIController class and utilizing them where needed |
29 | | - |
30 | | ---- |
31 | | - |
32 | | -### Requirements |
33 | | -- Python >= 3.6 |
34 | | -- django >= 2.1 |
35 | | -- pydantic >= 1.6 |
36 | | -- Django-Ninja >= 0.16.1 |
37 | | - |
38 | | -## Django-Ninja Benchmark |
39 | | -**Django-Ninja-Extra** uses **Django-Ninja** under the hood, it can be assumed that Django-Ninja-Extra has the same benchmark with Django-Ninja |
40 | | - |
41 | | - |
42 | | -Full documentation, [visit](https://eadwincode.github.io/django-ninja-extra/). |
43 | | - |
44 | | -## Sample Project |
45 | | -Django-Ninja-Tutorial Project, [visit](https://github.com/eadwinCode/bookstoreapi) |
46 | | - |
47 | | -## Installation |
48 | | - |
49 | | -``` |
50 | | -pip install django-ninja-extra |
51 | | -``` |
52 | | -After installation, add `ninja_extra` to your `INSTALLED_APPS` |
53 | | - |
54 | | -```Python |
55 | | -INSTALLED_APPS = [ |
56 | | - ..., |
57 | | - 'ninja_extra', |
58 | | -] |
59 | | -``` |
60 | | - |
61 | | -## Usage |
62 | | - |
63 | | -In your django project next to urls.py create new `api.py` file: |
64 | | - |
65 | | -```Python |
66 | | -from ninja_extra import NinjaExtraAPI, api_controller, http_get |
67 | | - |
68 | | -api = NinjaExtraAPI() |
69 | | - |
70 | | -# function based definition |
71 | | -@api.get("/add", tags=['Math']) |
72 | | -def add(request, a: int, b: int): |
73 | | - return {"result": a + b} |
74 | | - |
75 | | -#class based definition |
76 | | -@api_controller('/', tags=['Math'], permissions=[]) |
77 | | -class MathAPI: |
78 | | - |
79 | | - @http_get('/subtract',) |
80 | | - def subtract(self, a: int, b: int): |
81 | | - """Subtracts a from b""" |
82 | | - return {"result": a - b} |
83 | | - |
84 | | - @http_get('/divide',) |
85 | | - def divide(self, a: int, b: int): |
86 | | - """Divides a by b""" |
87 | | - return {"result": a / b} |
88 | | - |
89 | | - @http_get('/multiple',) |
90 | | - def multiple(self, a: int, b: int): |
91 | | - """Multiples a with b""" |
92 | | - return {"result": a * b} |
93 | | - |
94 | | -api.register_controllers( |
95 | | - MathAPI |
96 | | -) |
97 | | -``` |
98 | | - |
99 | | -Now go to `urls.py` and add the following: |
100 | | - |
101 | | -```Python |
102 | | -... |
103 | | -from django.urls import path |
104 | | -from .api import api |
105 | | - |
106 | | -urlpatterns = [ |
107 | | - path("admin/", admin.site.urls), |
108 | | - path("api/", api.urls), # <---------- ! |
109 | | -] |
110 | | -``` |
111 | | - |
112 | | -### Interactive API docs |
113 | | - |
114 | | -Now go to <a href="http://127.0.0.1:8000/api/docs" target="_blank">http://127.0.0.1:8000/api/docs</a> |
115 | | - |
116 | | -You will see the automatic interactive API documentation (provided by <a href="https://github.com/swagger-api/swagger-ui" target="_blank">Swagger UI</a>): |
117 | | - |
118 | | - |
119 | | -## What next? |
120 | | -- To support this project, please give star it on Github |
121 | | -- API Throttling |
| 1 | + |
| 2 | +[](https://badge.fury.io/py/django-ninja-extra) |
| 3 | +[](https://pypi.python.org/pypi/django-ninja-extra) |
| 4 | +[](https://pypi.python.org/pypi/django-ninja-extra) |
| 5 | +[](https://pypi.python.org/pypi/django-ninja-extra) |
| 6 | +[](https://codecov.io/gh/eadwinCode/django-ninja-extra) |
| 7 | +[](https://pepy.tech/project/django-ninja-extra) |
| 8 | + |
| 9 | +# Django Ninja Extra |
| 10 | + |
| 11 | +**Django Ninja Extra** is a complete class-based fashion of building and setting up APIs at incredible speed with incredible performance. |
| 12 | +It utilizes [**Django Ninja**](https://django-ninja.rest-framework.com) core features without compromising speed. |
| 13 | + |
| 14 | +**Key features:** |
| 15 | + |
| 16 | +All **Django-Ninja** features : |
| 17 | + |
| 18 | +- **Easy**: Designed to be easy to use and intuitive. |
| 19 | +- **FAST execution**: Very high performance thanks to **<a href="https://pydantic-docs.helpmanual.io" target="_blank">Pydantic</a>** and **<a href="/async-support/">async support</a>**. |
| 20 | +- **Fast to code**: Type hints and automatic docs lets you focus only on business logic. |
| 21 | +- **Standards-based**: Based on the open standards for APIs: **OpenAPI** (previously known as Swagger) and **JSON Schema**. |
| 22 | +- **Django friendly**: (obviously) has good integration with the Django core and ORM. |
| 23 | + |
| 24 | +Plus **Extra**: |
| 25 | + |
| 26 | +- **Class Based**: Design your APIs in a class based fashion. |
| 27 | +- **Permissions**: Protect endpoint(s) at ease with defined permissions and authorizations at route level or controller level. |
| 28 | +- **Dependency Injection**: Controller classes supports dependency injection with python [**Injector** ](https://injector.readthedocs.io/en/latest/) or [**django_injector**](https://github.com/blubber/django_injector). Giving you the ability to inject API dependable services to APIController class and utilizing them where needed |
| 29 | + |
| 30 | +--- |
| 31 | + |
| 32 | +### Requirements |
| 33 | +- Python >= 3.6 |
| 34 | +- django >= 2.1 |
| 35 | +- pydantic >= 1.6 |
| 36 | +- Django-Ninja >= 0.16.1 |
| 37 | + |
| 38 | +## Django-Ninja Benchmark |
| 39 | +**Django-Ninja-Extra** uses **Django-Ninja** under the hood, it can be assumed that Django-Ninja-Extra has the same benchmark with Django-Ninja |
| 40 | + |
| 41 | + |
| 42 | +Full documentation, [visit](https://eadwincode.github.io/django-ninja-extra/). |
| 43 | + |
| 44 | +## Sample Project |
| 45 | +Django-Ninja-Tutorial Project, [visit](https://github.com/eadwinCode/bookstoreapi) |
| 46 | + |
| 47 | +## Installation |
| 48 | + |
| 49 | +``` |
| 50 | +pip install django-ninja-extra |
| 51 | +``` |
| 52 | +After installation, add `ninja_extra` to your `INSTALLED_APPS` |
| 53 | + |
| 54 | +```Python |
| 55 | +INSTALLED_APPS = [ |
| 56 | + ..., |
| 57 | + 'ninja_extra', |
| 58 | +] |
| 59 | +``` |
| 60 | + |
| 61 | +## Usage |
| 62 | + |
| 63 | +In your django project next to urls.py create new `api.py` file: |
| 64 | + |
| 65 | +```Python |
| 66 | +from ninja_extra import NinjaExtraAPI, api_controller, http_get |
| 67 | + |
| 68 | +api = NinjaExtraAPI() |
| 69 | + |
| 70 | +# function based definition |
| 71 | +@api.get("/add", tags=['Math']) |
| 72 | +def add(request, a: int, b: int): |
| 73 | + return {"result": a + b} |
| 74 | + |
| 75 | +#class based definition |
| 76 | +@api_controller('/', tags=['Math'], permissions=[]) |
| 77 | +class MathAPI: |
| 78 | + |
| 79 | + @http_get('/subtract',) |
| 80 | + def subtract(self, a: int, b: int): |
| 81 | + """Subtracts a from b""" |
| 82 | + return {"result": a - b} |
| 83 | + |
| 84 | + @http_get('/divide',) |
| 85 | + def divide(self, a: int, b: int): |
| 86 | + """Divides a by b""" |
| 87 | + return {"result": a / b} |
| 88 | + |
| 89 | + @http_get('/multiple',) |
| 90 | + def multiple(self, a: int, b: int): |
| 91 | + """Multiples a with b""" |
| 92 | + return {"result": a * b} |
| 93 | + |
| 94 | +api.register_controllers( |
| 95 | + MathAPI |
| 96 | +) |
| 97 | +``` |
| 98 | + |
| 99 | +Now go to `urls.py` and add the following: |
| 100 | + |
| 101 | +```Python |
| 102 | +... |
| 103 | +from django.urls import path |
| 104 | +from .api import api |
| 105 | + |
| 106 | +urlpatterns = [ |
| 107 | + path("admin/", admin.site.urls), |
| 108 | + path("api/", api.urls), # <---------- ! |
| 109 | +] |
| 110 | +``` |
| 111 | + |
| 112 | +### Interactive API docs |
| 113 | + |
| 114 | +Now go to <a href="http://127.0.0.1:8000/api/docs" target="_blank">http://127.0.0.1:8000/api/docs</a> |
| 115 | + |
| 116 | +You will see the automatic interactive API documentation (provided by <a href="https://github.com/swagger-api/swagger-ui" target="_blank">Swagger UI</a>): |
| 117 | + |
| 118 | + |
| 119 | +## What next? |
| 120 | +- To support this project, please give star it on Github |
| 121 | +- API Throttling |
0 commit comments