DRF Compose is a Python package for defining and quick starting Django Rest Framework projects. With DRF Compose, you use a JSON or YAML file to configure your DRF application. Then, with a single command, you get to generate your DRF project code using all the specified configuration from your compose file. To learn more about all the features of DRF Compose, see the list of features below.
DRF Compose is aimed at making the process of starting a DRF project quick and fun - giving you a development head start experience - while also preventing any frustration caused by the inability to quick start an API.
Install and update using pip:
$ pip install drf-compose
Using DRF Compose is basically a two-step process:
- Define your application in a drf-compose.json file.
- Run drf-compose and the DRF compose command generates a ready to use DRF project code.
You can also see this information by running drf-compose --help from the command line.
Usage: drf-compose [OPTIONS]
This script composes a DRF project.
Options:
-s, --source FILE Specify an alternate compose file as source [default: drf-compose.json]
--yaml Indicates that the supplied source file is a YAML file
--help Show this message and exit.
A drf-compose file looks like this:
In YAML format (.yml) | In JSON format (.json) |
name: delight_blog
app_with_model:
- app_name: post
models:
- name: Post
fields:
- name: title
type: char
options:
max_length: 200
- name: content
type: text
options:
blank: true
'null': true
str: title
- name: Category
fields:
- name: name
type: char
options:
blank: true
'null': true
max_length: 200 | {
"name": "delight_blog",
"app_with_model": [
{
"app_name": "post",
"models": [
{
"name": "Post",
"fields": [
{
"name": "title",
"type": "char",
"options": {
"max_length": 200
}
},
{
"name": "content",
"type": "text",
"options": {
"blank": true,
"null": true
}
}
],
"str": "title"
},
{
"name": "Category",
"fields": [
{
"name": "name",
"type": "char",
"options": {
"blank": true,
"null": true,
"max_length": 200
}
}
]
}
]
}
]
} |
name
(required): specifies the project name.app_with_model
(required): specifies details describing each apps in the DRF project.app_name
(required): specifies the app namemodels
: a list of models belonging to the appname
(required): specifies the model namemeta
: specifies the different model meta options as in the Django model meta documentationfields
(required): a list of fields belonging to a model.name
(required): the name of the field as in the Django model field documentationtype
(required): the field type as specified in Django model field type reference documentation. Basic syntax sugar also supported as shown below:Syntax
Field Type
char
CharField
text
TextField
url
URLField
datetime
DatetimeField
fk
ForeignKey
o2o
OneToOneField
m2m
ManyToManyField
options
: specifies field option as in the Django model field documentation.
use_uuid_as_key
(boolean): if True, a UUID is used as the model’s primary key.str
: specifies the field to be returned as representation of the model in__str__
. Must be one of the specified field names
auth_app
: specifies details of the authentication application.app_name
(required): specifies the app namemodel_name
(required): specifies the model name for the custom user modelusername_field
: A string describing the name of the field on the user model that is used as the unique identifier Django USERNAME_FIELD documentation.email_field
: A string describing the name of the email field on the User model. Django's EMAIL_FIELD documentationrequired_fields
: A list of the field names that will be prompted for when creating a user via thecreatesuperuser
management command Django's REQUIRED_FIELDS documentationmeta
: specifies the different model meta options as in the Django model meta documentationfields
: a list of fields belonging to a model.name
(required): the name of the field as in the Django model field documentationtype
(required): the field type as specified in Django model field type reference documentation. Basic syntax sugar also supported as shown below:Syntax
Field Type
char
CharField
text
TextField
url
URLField
datetime
DatetimeField
fk
ForeignKey
o2o
OneToOneField
m2m
ManyToManyField
options
: specifies field option as in the Django model field documentation.
use_uuid_as_key
(boolean): if True, a UUID is used as the model’s primary key.str
: specifies the field to be returned as representation of the model in__str__
. Must be one of the specified field names
include
: specifies the addons to be included in the application.simple_jwt
(boolean): if True, includes Simple JWT JSON Web Token authentication plugin into the application.COMING SOON!
django_filter
(boolean) if True, includes Django-filter, a reusable Django application allowing users to declaratively add dynamic QuerySet filtering from URL parameters.docker
(boolean): if True, includes docker setup option into the application.dj-database-url
(boolean): if True, includes DJ-Database-URL , a simple Django utility allows you to utilize the 12factor inspired DATABASE_URL environment variable to configure your Django application.
- Documentation: https://drf-compose.readthedocs.io
- Changes: https://drf-compose.readthedocs.io/changes/
- PyPI Releases: https://pypi.org/project/drf-compose/
- Source Code: https://github.com/IamAbbey/drf_compose
- Issue Tracker: https://github.com/IamAbbey/drf_compose/issues
This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.