Package: dr-cli
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 forrapidRest 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,Productin yourmodels.pyfile, this tool could generate aGET /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.Demoworking on itUsage: How to Work with this ToolInstallationpip install dr-cliI highly recommend that you install this in a virtual environment.Create a New ProjectRundr-cli startproject project_nameto start a new DRF project.You'd be prompted to start your project from one of three templates:Baisc, Medior, and Advancedtemplates. Learn more about what each template comes bundled withhere.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 projectCreate New Apps in your ProjectRundr-cli startapps todo me-nu userto create multiple Django apps in your project. Wheretodo me-nu userare your app names.Running the above command will create all your apps. Name validations would also be performed as shown in the image below:NoteMake sure to add your created apps to the list of INSTALLED APPSGenerate CRUD Endpoints for your AppsRundr-cli addcrud memo userto 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:NoteMake sure to register theURLsfor each app in the top levelurls.pyfile.On Windows, Emojis are only supported inWindows Terminal PreviewAccessing the docs pageRunpython manage.py runserverto fire up your local development server, and point your browser tohttp://localhost:8000/api/v1/docsto view the auto-generated docs page shown in the image below:MotivationIn 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 addressthe three concernsthat 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 ausersappAuthentication endpoints.python-decouple: for managing environment varibalesdrf-spactacular: for auto-generating API docsdj-database-url: for connecting to various databasespre-commit, black, isort, flake8: for code linting with pre-commit hookspytest-django: for writing unit tests with pytestDocker: for containerization.So I wished there was a tool that could start my project with the integrations, and features I need configured. I foundcookie-cutter-django-restto 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 Advancedtemplates. 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.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,Productin yourmodels.pyfile, this tool could generate aGET /products POST /products PUT /products/<product_id>etc. endpoints for that model.PROBLEM-3:I had always wish there was a way to create multiples apps at once in my Django projectSOLUTION:This tool allows you create multiple apps at once in this project.Contributing GuideComing soon...AcknowledgementsIn building this I re-used a few parts of these repositories in this project:django-classy-startdr-scaffoldI 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 xDLicenceMIT