Scaffold your DRF projects faster⚡🚀
Project description
Django Rest CLI ✨
Scaffold your DRF project with common python packages configured, auto-generated docs, auto-generated CRUD endpoints, code linting with pre-commit hook, and more⚡🚀
What is Django Rest CLI ?
A CLI tool for rapid Rest APIs development. It abstracts the repeated aspects of building a REST API with the Django Framework by:
-
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.
-
Allowing you 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. -
Allowing you create all the apps in your project at once, if you know them before hand.
Demo
working on it
Usage: How to Work with this Tool
Installation
pip install dr-cli
I highly recommend that you install this in a virtual environment.
Create a New Project
-
Run
dr-cli startproject project_name
to start a new DRF project. -
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.
-
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:
The generated project comes with a nice Readme containing the steps for running the project
Create New Apps in your Project
-
Run
dr-cli startapps todo me-nu user
to create multiple Django apps in your project. Wheretodo me-nu user
are your app names. -
Running the above command will create all your apps. Name validations would also be performed as shown in the image below:
Note Make sure to add your created apps to the list of INSTALLED APPS
Generate CRUD Endpoints for your Apps
-
Run
dr-cli addcrud memo user
to create CRUD endpoints for the models defined in the specified apps. -
Running the above command would return a nice looking feedback as shown in the image below:
Note Make sure to register the URLs
for each app in the top level urls.py
file.
On Windows, Emojis are only supported in Windows Terminal Preview
Accessing the docs page
- Run
python manage.py runserver
to fire up your local development server, and point your browser tohttp://localhost:8000/api/v1/docs
to view the auto-generated docs page shown in the image below:
Motivation
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.
-
PROBLEM-1: I noticed I was repeating at least one of the following integrations, and features in every project:
- A custom user model defined in a
users
app - Authentication endpoints.
- python-decouple: for managing environment varibales
- drf-spactacular: for auto-generating API docs
- dj-database-url: for connecting to various databases
- pre-commit, black, isort, flake8: for code linting with pre-commit hooks
- pytest-django: for writing unit tests with pytest
- Docker: for containerization.
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 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.
- 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.
- A custom user model defined in a
-
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.
- 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.
- 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
-
PROBLEM-3: I had always wish there was a way to create multiples apps at once in my Django project
- SOLUTION: This tool allows you create multiple apps at once in this project.
Contributing Guide
Coming soon...
Acknowledgements
In building this I re-used a few parts of these repositories in this project:
I Love this, how can I thank you Nyior?
Please let your developer friends know about this repo :) If you star this repo too I won't complain xD
Licence
MIT
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
File details
Details for the file dr-cli-1.0.2.tar.gz
.
File metadata
- Download URL: dr-cli-1.0.2.tar.gz
- Upload date:
- Size: 32.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c1f3155542ef85be323fb99c9903193b0fd76c7c0b1c2807b05e12aab82ce75d |
|
MD5 | 137994c2c982ee2f007c0146a5fba1fd |
|
BLAKE2b-256 | a2e4f6305c8b5a739a1eaba0492ef8b65f8749e50190e9b81d8de4f368e9c975 |
File details
Details for the file dr_cli-1.0.2-py3-none-any.whl
.
File metadata
- Download URL: dr_cli-1.0.2-py3-none-any.whl
- Upload date:
- Size: 52.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f6d50df42ec5bb1653e1fc2c93bb6bf2b21bb04a4c0952f8dccdf205b0b2c0a1 |
|
MD5 | cf176403b5f96ec6aece8fbefb57ee19 |
|
BLAKE2b-256 | 63602fa29d6c4c0cad5aabc704d607302276b21479b258221cdbe4b53da43cc0 |