Skip to main content

A factory for createing Django Rest Framework APIs

Project description

=============================
Rest Framework Factory (DRFF)
=============================


.. image:: https://img.shields.io/pypi/v/rest_framework_factory.svg
:target: https://pypi.python.org/pypi/rest_framework_factory

.. image:: https://img.shields.io/travis/MiddleFork/rest_framework_factory.svg
:target: https://travis-ci.org/MiddleFork/rest_framework_factory

.. image:: https://readthedocs.org/projects/rest-framework-factory/badge/?version=latest
:target: https://rest-framework-factory.readthedocs.io/en/latest/?badge=latest
:alt: Documentation Status


.. image:: https://pyup.io/repos/github/MiddleFork/rest_framework_factory/shield.svg
:target: https://pyup.io/repos/github/MiddleFork/rest_framework_factory/
:alt: Updates



A factory for creating Django Rest Framework APIs



* Documentation: https://rest-framework-factory.readthedocs.io.


Features
--------

* Create a DRF API painlessly, without needing to repeat boilerplate code

Installation
------------

* ``pip install rest_framework_factory``

Requirements
------------

* A Django project with at least one app' from which you wish to build an DRF API included in INSTALLED_APPS, and with at least one model defined in models.py


How it Works
------------

* The Factory works because a model itself contains all the information required in order to generate an API for it, including a Serializer, a Viewset, URL(s) and other optional (e.g. Forms, Filters) content

* Template files contain variable placeholders referencing the name and attributes of a model

TODOs
-----

* WEB UI interface to generate factory apis interactively

* Configuration files (YML?) to allow fine-grained control of the factory API, e.g. by including/excluding individual models and/or fields, setting allowed methods, etc.

* Swagger

* Sphinx

Usage
-----

Basic Usage - Manual Creation
+++++++++++++++++++++++++++++

* It is not necessary to add rest_framework_factory to INSTALLED_APPS

* One common use case is to build a factory using all the models defined in an app::

from rest_framework_factory import factory
drff = factory.Factory()
drff.build_from_app('my_app')
content = drff.apis['app']['my_app']
with open('/tmp/drff_api.py')), 'w') as f:
f.write(data)

* Once the factory file is built, it should be placed into the apps' folder, added to INSTALLED_APPS, and have its urls wired into the project::

mkdir my_app/drff; touch my_app/drff/__init__.py; cp /tmp/drff_api.py ./my_app/drff/api.py


* settings.py::

INSTALLED_APPS += 'my_app.drff'

* urls.py::

from my_app.drff.api import urlpatterns as drff_urls
urlpatterns += drff_urls



Using the Factory UI
++++++++++++++++++++

* TODO

* Scan all the apps, the models therein, and their fields

* Build forms for each model/app

* Toggle desired models/fields on-off

* Select serializer type (ie ModelSerializer vs ReadOnlyModelSerializer

* Select allowed API endpoint methos (ie GET, POST)

Configuring the factory via YML
+++++++++++++++++++++++++++++++

* TODO

* Initiallize: Scan all apps, the models therein, and their fields; write structure to file
* Manually edit file, comment out undesired fields and models, change permissions, etc

* Implement: Read yml file, generate factory

Credits
-------

Django_



Package created with Cookiecutter_.

.. _Django: https://github.com/django/django
.. _Cookiecutter: https://github.com/audreyr/cookiecutter



=======
History
=======

0.1.0 (2019-01-22)
------------------

* First release on PyPI.

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

rest_framework_factory-0.1.41.tar.gz (16.4 kB view details)

Uploaded Source

File details

Details for the file rest_framework_factory-0.1.41.tar.gz.

File metadata

  • Download URL: rest_framework_factory-0.1.41.tar.gz
  • Upload date:
  • Size: 16.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.29.1 CPython/3.6.6

File hashes

Hashes for rest_framework_factory-0.1.41.tar.gz
Algorithm Hash digest
SHA256 20b7f5bbe57ba8a307c77e1e98e0be817fa2ff8ec964daba15374d73892e7500
MD5 ce2b20b41b4ae5d781cadc150fad74ea
BLAKE2b-256 5915e2a6561b94d1e861e74c2fd22e069ae777bb4e6f0462b6e38372fc53fd01

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page