You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
**Django Shinobi** is a web framework for building APIs with **Django** and Python 3.6+ **type hints**.
29
20
30
21
It's a fork of the fantastic **[Django Ninja](https://github.com/vitalik/django-ninja)** library focused on
31
-
community-desired features and fixes. Read the [announcement](https://github.com/pmdevita/django-shinobi/discussions/5)
32
-
for more info and check out the [roadmap](https://github.com/pmdevita/django-shinobi/discussions/6)!
22
+
community-desired features and fixes. Check out the list of [differences](https://pmdevita.github.io/django-shinobi/differences/)
23
+
if you're coming from Ninja, as well as the [roadmap](https://github.com/pmdevita/django-shinobi/discussions/6)!
33
24
34
25
35
26
**Key features:**
@@ -51,16 +42,23 @@ for more info and check out the [roadmap](https://github.com/pmdevita/django-shi
51
42
52
43
## Installation
53
44
45
+
In your Django project, add Django Shinobi.
46
+
54
47
```
55
48
pip install django-shinobi
56
49
```
57
50
51
+
or start a new project.
58
52
53
+
```shell
54
+
pip install django django-shinobi
55
+
django-admin startproject apidemo
56
+
```
59
57
60
58
## Usage
61
59
62
60
63
-
In your django project next to urls.py create new `api.py` file:
61
+
In your Django project, next to urls.py, create a new file called `api.py`.
64
62
65
63
```Python
66
64
from ninja import NinjaAPI
@@ -98,6 +96,12 @@ Now you've just created an API that:
98
96
99
97
### Interactive API docs
100
98
99
+
Run your Django project
100
+
101
+
```shell
102
+
python manage.py runsever
103
+
```
104
+
101
105
Now go to <ahref="http://127.0.0.1:8000/api/docs"target="_blank">http://127.0.0.1:8000/api/docs</a>
102
106
103
107
You will see the automatic interactive API documentation (provided by <ahref="https://github.com/swagger-api/swagger-ui"target="_blank">Swagger UI</a> or <ahref="https://github.com/Redocly/redoc"target="_blank">Redoc</a>):
RUSSIA INVADED UKRAINE - <ahref="https://github.com/vitalik/django-ninja/issues/383">Please read (from Shinobi's original author)</a>
5
-
</div>
6
-
7
-
8
3

9
4
10
5
Django Shinobi is a web framework for building APIs with Django and Python 3.6+ type hints.
11
6
7
+
It's a fork of the fantastic **[Django Ninja](https://github.com/vitalik/django-ninja)** library focused on
8
+
community-desired features and fixes. Check out the list of [differences](https://pmdevita.github.io/django-shinobi/differences/)
9
+
if you're coming from Ninja, as well as the [roadmap](https://github.com/pmdevita/django-shinobi/discussions/6)!
10
+
11
+
12
12
Key features:
13
13
14
14
-**Easy**: Designed to be easy to use and intuitive.
@@ -24,57 +24,71 @@ Key features:
24
24
25
25
## Installation
26
26
27
+
In your Django project, add Django Shinobi.
28
+
27
29
```
28
30
pip install django-shinobi
29
31
```
30
32
31
-
## Quick Example
33
+
or start a new project.
32
34
33
-
Start a new Django project (or use an existing one)
34
-
```
35
+
```shell
36
+
pip install django django-shinobi
35
37
django-admin startproject apidemo
36
38
```
37
39
38
-
in `urls.py`
40
+
## Usage
41
+
42
+
43
+
In your Django project, next to urls.py, create a new file called `api.py`.
44
+
39
45
40
46
```python hl_lines="3 5 8 9 10 15"
41
47
{!./src/index001.py!}
42
48
```
43
49
44
-
Now, run it as usual:
45
-
```
46
-
./manage.py runserver
47
-
```
48
50
49
-
Note: You don't have to add Django Shinobi to your installed apps for it to work.
51
+
Now go to `urls.py` and add the following:
50
52
51
-
## Check it
52
53
53
-
Open your browser at <ahref="http://127.0.0.1:8000/api/add?a=1&b=2"target="_blank">http://127.0.0.1:8000/api/add?a=1&b=2</a>
54
+
```Python hl_lines="3 7"
55
+
...
56
+
from .api import api
54
57
55
-
You will see the JSON response as:
56
-
```JSON
57
-
{"result": 3}
58
+
urlpatterns = [
59
+
path("admin/", admin.site.urls),
60
+
path("api/", api.urls), # <---------- !
61
+
]
58
62
```
63
+
64
+
**That's it !**
65
+
59
66
Now you've just created an API that:
60
67
61
68
- receives an HTTP GET request at `/api/add`
62
69
- takes, validates and type-casts GET parameters `a` and `b`
63
70
- decodes the result to JSON
64
71
- generates an OpenAPI schema for defined operation
65
72
66
-
## Interactive API docs
73
+
### Interactive API docs
74
+
75
+
Run your Django project
76
+
77
+
```shell
78
+
python manage.py runsever
79
+
```
67
80
68
81
Now go to <ahref="http://127.0.0.1:8000/api/docs"target="_blank">http://127.0.0.1:8000/api/docs</a>
69
82
70
-
You will see the automatic, interactive API documentation (provided by the <ahref="https://github.com/swagger-api/swagger-ui"target="_blank">OpenAPI / Swagger UI</a> or <ahref="https://github.com/Redocly/redoc"target="_blank">Redoc</a>):
83
+
You will see the automatic interactive API documentation (provided by <ahref="https://github.com/swagger-api/swagger-ui"target="_blank">Swagger UI</a> or <ahref="https://github.com/Redocly/redoc"target="_blank">Redoc</a>):
84
+
71
85
72
-

86
+

73
87
74
88
75
89
## Recap
76
90
77
-
In summary, you declare the types of parameters, body, etc. **once only**, as function parameters.
91
+
In summary, you declare the types of parameters, body, etc. **once only**, as function parameters.
78
92
79
93
You do that with standard modern Python types.
80
94
@@ -117,5 +131,9 @@ def operation(a: Item):
117
131
* Files
118
132
* Automatic, interactive API documentation
119
133
120
-
This project was heavily inspired by <ahref="https://fastapi.tiangolo.com/"target="_blank">FastAPI</a> (developed by <ahref="https://github.com/tiangolo"target="_blank">Sebastián Ramírez</a>)
134
+
## What next?
121
135
136
+
- Read the full documentation here - https://pmdevita.github.io/django-shinobi
137
+
- To support this project, please give star it on Github. 
138
+
- Share it [via Twitter](https://twitter.com/intent/tweet?text=Check%20out%20Django%20Shinobi%20-%20Fast%20Django%20REST%20Framework%20-%20https%3A%2F%2Fpmdevita.github.io/django-shinobi)
139
+
- Share your feedback and discuss development on Discord https://discord.gg/ntFTXu7NNv
0 commit comments