Skip to content

Commit a35716c

Browse files
authored
Merge pull request #1 from py-universe/docs
Docs
2 parents cb90d50 + 6aa323a commit a35716c

37 files changed

+391
-113
lines changed

.github/workflows/Test.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Test
2+
3+
on:
4+
push:
5+
branches: [ main, development ]
6+
pull_request:
7+
branches: [ main, development ]
8+
schedule:
9+
- cron: '30 8,20 * * *'
10+
jobs:
11+
lint-and-test:
12+
runs-on: ubuntu-latest
13+
14+
strategy:
15+
max-parallel: 4
16+
matrix:
17+
python-version: [3.7, 3.8, 3.9]
18+
steps:
19+
- uses: actions/checkout@v2
20+
- name: Set up Python ${{ matrix.python-version }}
21+
uses: actions/setup-python@v2
22+
with:
23+
python-version: ${{ matrix.python-version }}
24+
- name: Install Dependencies
25+
run: |
26+
python -m pip install --upgrade pip
27+
pip install -r requirements.txt
28+
- name: Lint
29+
run: |
30+
black .
31+
isort .
32+
flake8 .
33+
- name: Run Tests
34+
run: |
35+
python -m pytest tests

MANIFEST.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
recursive-include django_rest_cli/engine/templates *

README.md

Lines changed: 112 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,130 @@
1-
<h1>
2-
Django Rest CLI
1+
<h1 align="center">
2+
Django Rest CLI
33
</h1>
44

5-
<p>
6-
Scaffold your DRF projects faster with auto-generated docs, pre-commit hooks, auto-generated CRUD endpoints for your models and more 🚀
5+
<p align="center">
6+
<img src="https://github.com/py-universe/django-rest-cli/blob/docs/assets/logo.png" width="120" height="120">
77
</p>
88

9-
# Demo
9+
<p align="center">
10+
Scaffold your DRF project with common python packages configured, auto-generated docs, auto-generated CRUD endpoints, code linting with pre-commit hook, and more⚡🚀
11+
</p>
12+
13+
<p align="center">
14+
<a href="https://github.com/pre-commit/pre-commit">
15+
<img src="https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white" alt="pre-commit">
16+
</a>
17+
18+
<a href="https://badge.fury.io/py/dr-cli" target="_blank">
19+
<img src="https://badge.fury.io/py/dr-cli.svg" alt="PyPI version">
20+
</a>
21+
22+
<a href="https://github.com/py-universe/django-rest-cli/actions?query=workflow%3ATest" target="_blank">
23+
<img src="https://github.com/py-universe/django-rest-cli/workflows/Test/badge.svg" alt="Test">
24+
</a>
25+
</p>
26+
27+
28+
## What is Django Rest CLI ?
29+
A CLI tool for _rapid_ Rest APIs development. It abstracts the repeated aspects of building a REST API with the Django Framework by:
30+
31+
- Allowing you start your project from one of three templates. Each template comes with features you'd most likely be setting up yourself already configured for you.
32+
33+
- Allowing you define your models and have this tool generate CRUD endpoints for each model defined.
34+
For example, if you define a model, **Product** in your `models.py` file, this tool could generate a _GET /products POST /products PUT /products/<product_id>_ etc. endpoints for that model.
35+
36+
- Allowing you create all the apps in your project at once, if you know them before hand.
37+
38+
39+
## Demo
1040
working on it
1141

12-
# Motivation
13-
in the works too
42+
## Usage: How to Work with this Tool
1443

15-
# Usage
16-
I never run am yet
1744
### Installation
45+
```pip install dr-cli```
1846

19-
### CLI Commands
47+
I highly recommend that you install this in a virtual environment.
2048

21-
###### `startproject project_name`
49+
### Create a New Project
50+
- Run ```dr-cli startproject project_name``` to start a new DRF project.
2251

23-
###### `startapps app1_name app2_name app3_name`
52+
- You'd be prompted to start your project from one of three templates: **Baisc, Medior, and Advanced** templates. Learn more about what each template comes bundled with [here](https://github.com/py-universe/django-rest-cli/blob/docs/templatesInfo.md).
2453

25-
###### `addcrud app1_name app2_name app3_name`
54+
- On selecting one of the templates your project will then be created. Git will be initialized in your project, and all project dependencies installed as shown in the image below:
2655

27-
# Contributing Guide
56+
<img src="https://github.com/py-universe/django-rest-cli/blob/docs/assets/startproject.PNG">
2857

29-
# Acknowledgements
58+
The generated project comes with a nice Readme containing the steps for running the project
3059

31-
# Thank you Nyior :)
3260

33-
## Licence
34-
MIT
61+
### Create New Apps in your Project
62+
- Run ```dr-cli startapps todo me-nu user``` to create multiple Django apps in your project. Where `todo me-nu user` are your app names.
63+
64+
- Running the above command will create all your apps. Name validations would also be performed as shown in the image below:
65+
66+
<img src="https://github.com/py-universe/django-rest-cli/blob/docs/assets/createapps.PNG">
67+
68+
**Note** Make sure to add your created apps to the list of INSTALLED APPS
69+
70+
71+
### Generate CRUD Endpoints for your Apps
72+
- Run ```dr-cli addcrud memo user``` to create CRUD endpoints for the models defined in the specified apps.
73+
74+
- Running the above command would return a nice looking feedback as shown in the image below:
75+
76+
<img src="https://github.com/py-universe/django-rest-cli/blob/docs/assets/addcrud.PNG">
77+
78+
**Note** Make sure to register the `URLs` for each app in the top level `urls.py` file.
3579

80+
On Windows, Emojis are only supported in [Windows Terminal Preview](https://www.microsoft.com/en-us/p/windows-terminal-preview/9n8g5rfz9xk3?activetab=pivot:overviewtab)
3681

37-
**Note** On Windows, Emojis are only supported in [Windows Terminal Preview](https://www.microsoft.com/en-us/p/windows-terminal-preview/9n8g5rfz9xk3?activetab=pivot:overviewtab)
82+
### Accessing the docs page
83+
- Run `python manage.py runserver` to fire up your local development server, and point your browser to `http://localhost:8000/api/v1/docs` to view the auto-generated docs page shown in the image below:
84+
85+
<img src="./assets/docs.PNG">
86+
87+
88+
## Motivation
89+
In creating REST APIs with the Django framework, I noticed there were things I kept repeating for every project. And there were things I just wished there was a better way of doing them. I created this CLI tool to address _the three concerns_ that mattered to me the most. Hopefully, it resonates with you too.
90+
91+
- **PROBLEM-1:** I noticed I was repeating at least one of the following integrations, and features in every project:
92+
- A custom user model defined in a `users` app
93+
- Authentication endpoints.
94+
- [python-decouple](https://pypi.org/project/python-decouple/): for managing environment varibales
95+
- [drf-spactacular](https://drf-spectacular.readthedocs.io/en/latest/readme.html): for auto-generating API docs
96+
- [dj-database-url](https://github.com/jazzband/dj-database-url): for connecting to various databases
97+
- [pre-commit, black, isort, flake8](https://ljvmiranda921.github.io/notebook/2018/06/21/precommits-using-black-and-flake8/): for code linting with pre-commit hooks
98+
- [pytest-django](https://pytest-django.readthedocs.io/en/latest/): for writing unit tests with pytest
99+
- [Docker](https://learndjango.com/tutorials/django-docker-and-postgresql-tutorial): for containerization.
100+
101+
So I wished there was a tool that could start my project with the integrations, and features I need configured. I found [cookie-cutter-django-rest](https://github.com/agconti/cookiecutter-django-rest) to be useful, but sometimes it's just too heavy for my use-case. I needed something more flexible, something that could start my project with few integrations or all the features and integrations above.
102+
103+
- **SOLUTION:** This CLI tool allows you start your project from one of three templates we provide: **Basic, Medior, and Advanced** templates. Depending on what template you select, you could scaffold your project with just python_decouple for managing env vars. Or you could go with something as complex as adding pytest for unit tests, drf_spectacular for auto-generating docs, authentication endpoints, pre-commit hook for code linting setup in your project, and docker support. Regardless of the template you select, we initialize git, install all project dependencies if internet connection is detected, and add a readme to your project.
104+
105+
106+
- **PROBLEM-2:** I noticed most times I needed CRUD endpoints for the models I define. CRUD endpoints are so unchanging that I wish there was a tool that could just generate all the CRUD endpoints for the models I define.
107+
108+
- **SOLUTION:** You can define your models and have this tool generate CRUD endpoints for each model defined. For example, if you define a model, **Product** in your `models.py` file, this tool could generate a _GET /products POST /products PUT /products/<product_id>_ etc. endpoints for that model.
109+
110+
111+
- **PROBLEM-3:** I had always wish there was a way to create multiples apps at once in my Django project
112+
- **SOLUTION:** This tool allows you create multiple apps at once in this project.
113+
114+
115+
## Contributing Guide
116+
Coming soon...
117+
118+
119+
## Acknowledgements
120+
In building this I re-used a few parts of these repositories in this project:
121+
- [django-classy-start](https://github.com/mfonism/django-classy-start)
122+
- [dr-scaffold](https://github.com/Abdenasser/dr_scaffold)
123+
124+
125+
## I Love this, how can I thank you Nyior?
126+
Please let your developer friends know about this repo :) If you star this repo too I won't complain xD
127+
128+
129+
## Licence
130+
MIT

assets/addcrud.PNG

27.8 KB
Loading

assets/createapps.PNG

20.2 KB
Loading

assets/docs.PNG

47.2 KB
Loading

assets/logo.png

11.6 KB
Loading

assets/startproject.PNG

61.1 KB
Loading

django_rest_cli/engine/cli/cli_commands.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
from django_rest_cli.engine.utils import print_exception
21
from django_rest_cli.engine.commands import AddCrud, StartApp, StartProject
2+
from django_rest_cli.engine.utils import print_exception
33

44
from .input_validators import is_django_project_directory, validate_name
55
from .mixins import ProjectConfigMixin

django_rest_cli/engine/cli/mixins.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ def template_type() -> str:
99
{
1010
"type": "list",
1111
"name": "user_option",
12-
"message": "What template do you want to start this project with? Refer to docs for details on what each template comes with",
12+
"message": (
13+
"What template do you want to start this"
14+
"project with? Refer to docs for details"
15+
"on what each template comes with"
16+
),
1317
"choices": ["Basic", "Medior", "Advanced"],
1418
}
1519
]

0 commit comments

Comments
 (0)