Skip to main content

Generate DRF Serializers, Views, and urls for your API aplication.

Project description

Writing APIs can be boring and repetitive work. Don’t write another CRUDdy view in Django Rest Framework. With DRF Generators, one simple command will create all of your API Views, Serializers, and even Urls for your Django Rest Framework application!

This is not intended to give you a production quality API. It was intended to jumpstart your development and save you from writing the same code over and over for each model.

Compatible with Django >= 1.7 and Django Rest Framework 3.1.0

Supported Python versions Latest Version


Install with pip:

$ pip install drf-generators

Clone the repo and install manually:

$ git clone
$ cd drf-generators
$ python install

To use DRF Generator, add it your INSTALLED_APPS.


Note: In order to use the APIListView classes, you must have the rest framework DEFAULT_PAGINATION_CLASS and PAGE_SIZE set.

    'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',
    'PAGE_SIZE': 15


To use the generator run one of the following commands, where app is the application to generate an API for.

$ python generate {options} {app}




Generate only Serializers for your app.


Generate only Views for your app.


Generate only urls for your app.


Use APIView classes instead of ViewSet classes, and urls instead of Router


The generator will create for your application. DRF Generator currently supports basic serializers with the fields defined in In the future, foreign key fields for nested serialization will be supported.

class UserSerializer(ModelSerializer):

    class Meta:
        model = User
        fields = ('id', 'name', 'city', 'state', 'address', 'zip_code')


DRF Generator also takes care of all of your basic CRUD API views using your models and the generated serializers.

By default, DRF Generator will create ViewSet View lcasses like the following for your models.

class CategoryViewSet(ViewSet):

    def list(self, request):
    def create(self, request):
    def retrieve(self, request, pk=None):
    def update(self, request, pk=None):
    def destroy(self, request, pk=None):

When running the generator with the --apiview option, you will get the following API Views.

class UserAPIView(APIView):

    def get(self, request, id, format=None):
    def put(self, request, id, format=None):
    def delete(self, request, id, format=None):

class UserAPIListView(APIView):

    def get(self, request, format=None):
    def post(self, request, format=None):


Finally, DRF Generator will create you a default in the following format.

By default, DRF Generator will create rouserce route based urls like the following.

router = SimpleRouter()

router.register(r'model', views.ModelViewSet, 'Model')

urlpatterns = router.urls

If you run the generatro with the --apiview option, you will get urls like the following.

url(r'^user/([0-9]+)$', views.UserAPIView.as_view()),
url(r'^user', views.UserAPIListView.as_view()),


A full application built with drf-generators can be found in the tests directory. Instructions on running them can be found in the test project’s README.


MIT License. See LICENSE.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

drf-generators-0.1.5.tar.gz (5.5 kB view hashes)

Uploaded source

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page