djangorestframework


Namedjangorestframework JSON
Version 3.8.2 PyPI version JSON
download
home_pagehttp://www.django-rest-framework.org
SummaryWeb APIs for Django, made easy.
upload_time2018-04-06 13:42:12
maintainer
docs_urlNone
authorTom Christie
requires_python>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*
licenseBSD
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            `Django REST framework <http://www.django-rest-framework.org/>`__
=================================================================

|build-status-image| |coverage-status-image| |pypi-version|

**Awesome web-browsable Web APIs.**

Full documentation for the project is available at
`http://www.django-rest-framework.org <http://www.django-rest-framework.org/>`__.

--------------

Funding
=======

REST framework is a *collaboratively funded project*. If you use REST
framework commercially we strongly encourage you to invest in its
continued development by `signing up for a paid
plan <https://fund.django-rest-framework.org/topics/funding/>`__.

The initial aim is to provide a single full-time position on REST
framework. *Every single sign-up makes a significant impact towards
making that possible.*

|image3| |image4| |image5| |image6| |image7|

Many thanks to all our `wonderful
sponsors <https://fund.django-rest-framework.org/topics/funding/#our-sponsors>`__,
and in particular to our premium backers,
`Rover <http://jobs.rover.com/>`__,
`Sentry <https://getsentry.com/welcome/>`__,
`Stream <https://getstream.io/try-the-api/?utm_source=drf&utm_medium=banner&utm_campaign=drf>`__,
`Machinalis <https://hello.machinalis.co.uk/>`__, and
`Rollbar <https://rollbar.com/>`__.

--------------

Overview
========

Django REST framework is a powerful and flexible toolkit for building
Web APIs.

Some reasons you might want to use REST framework:

-  The `Web browsable API <https://restframework.herokuapp.com/>`__ is a
   huge usability win for your developers.
-  `Authentication
   policies <http://www.django-rest-framework.org/api-guide/authentication/>`__
   including optional packages for
   `OAuth1a <http://www.django-rest-framework.org/api-guide/authentication/#django-rest-framework-oauth>`__
   and
   `OAuth2 <http://www.django-rest-framework.org/api-guide/authentication/#django-oauth-toolkit>`__.
-  `Serialization <http://www.django-rest-framework.org/api-guide/serializers/>`__
   that supports both
   `ORM <http://www.django-rest-framework.org/api-guide/serializers/#modelserializer>`__
   and
   `non-ORM <http://www.django-rest-framework.org/api-guide/serializers/#serializers>`__
   data sources.
-  Customizable all the way down - just use `regular function-based
   views <http://www.django-rest-framework.org/api-guide/views/#function-based-views>`__
   if you don't need the
   `more <http://www.django-rest-framework.org/api-guide/generic-views/>`__
   `powerful <http://www.django-rest-framework.org/api-guide/viewsets/>`__
   `features <http://www.django-rest-framework.org/api-guide/routers/>`__.
-  `Extensive documentation <http://www.django-rest-framework.org/>`__,
   and `great community
   support <https://groups.google.com/forum/?fromgroups#!forum/django-rest-framework>`__.

There is a live example API for testing purposes, `available
here <https://restframework.herokuapp.com/>`__.

**Below**: *Screenshot from the browsable API*

.. figure:: http://www.django-rest-framework.org/img/quickstart.png
   :alt: Screenshot

   Screenshot

--------------

Requirements
============

-  Python (2.7, 3.4, 3.5, 3.6)
-  Django (1.10, 1.11, 2.0)

Installation
============

Install using ``pip``...

::

    pip install djangorestframework

Add ``'rest_framework'`` to your ``INSTALLED_APPS`` setting.

::

    INSTALLED_APPS = (
        ...
        'rest_framework',
    )

Example
=======

Let's take a look at a quick example of using REST framework to build a
simple model-backed API for accessing users and groups.

Startup up a new project like so...

::

    pip install django
    pip install djangorestframework
    django-admin.py startproject example .
    ./manage.py migrate
    ./manage.py createsuperuser

Now edit the ``example/urls.py`` module in your project:

.. code:: python

    from django.conf.urls import url, include
    from django.contrib.auth.models import User
    from rest_framework import serializers, viewsets, routers

    # Serializers define the API representation.
    class UserSerializer(serializers.HyperlinkedModelSerializer):
        class Meta:
            model = User
            fields = ('url', 'username', 'email', 'is_staff')


    # ViewSets define the view behavior.
    class UserViewSet(viewsets.ModelViewSet):
        queryset = User.objects.all()
        serializer_class = UserSerializer


    # Routers provide a way of automatically determining the URL conf.
    router = routers.DefaultRouter()
    router.register(r'users', UserViewSet)


    # Wire up our API using automatic URL routing.
    # Additionally, we include login URLs for the browsable API.
    urlpatterns = [
        url(r'^', include(router.urls)),
        url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework'))
    ]

We'd also like to configure a couple of settings for our API.

Add the following to your ``settings.py`` module:

.. code:: python

    INSTALLED_APPS = (
        ...  # Make sure to include the default installed apps here.
        'rest_framework',
    )

    REST_FRAMEWORK = {
        # Use Django's standard `django.contrib.auth` permissions,
        # or allow read-only access for unauthenticated users.
        'DEFAULT_PERMISSION_CLASSES': [
            'rest_framework.permissions.DjangoModelPermissionsOrAnonReadOnly'
        ]
    }

That's it, we're done!

::

    ./manage.py runserver

You can now open the API in your browser at ``http://127.0.0.1:8000/``,
and view your new 'users' API. If you use the ``Login`` control in the
top right corner you'll also be able to add, create and delete users
from the system.

You can also interact with the API using command line tools such as
```curl`` <https://curl.haxx.se/>`__. For example, to list the users
endpoint:

::

    $ curl -H 'Accept: application/json; indent=4' -u admin:password http://127.0.0.1:8000/users/
    [
        {
            "url": "http://127.0.0.1:8000/users/1/",
            "username": "admin",
            "email": "admin@example.com",
            "is_staff": true,
        }
    ]

Or to create a new user:

::

    $ curl -X POST -d username=new -d email=new@example.com -d is_staff=false -H 'Accept: application/json; indent=4' -u admin:password http://127.0.0.1:8000/users/
    {
        "url": "http://127.0.0.1:8000/users/2/",
        "username": "new",
        "email": "new@example.com",
        "is_staff": false,
    }

Documentation & Support
=======================

Full documentation for the project is available at
`http://www.django-rest-framework.org <http://www.django-rest-framework.org/>`__.

For questions and support, use the `REST framework discussion
group <https://groups.google.com/forum/?fromgroups#!forum/django-rest-framework>`__,
or ``#restframework`` on freenode IRC.

You may also want to `follow the author on
Twitter <https://twitter.com/_tomchristie>`__.

Security
========

If you believe you've found something in Django REST framework which has
security implications, please **do not raise the issue in a public
forum**.

Send a description of the issue via email to
rest-framework-security@googlegroups.com. The project maintainers will
then work with you to resolve any issues where required, prior to any
public disclosure.

.. |build-status-image| image:: https://secure.travis-ci.org/encode/django-rest-framework.svg?branch=master
   :target: https://travis-ci.org/encode/django-rest-framework?branch=master
.. |coverage-status-image| image:: https://img.shields.io/codecov/c/github/encode/django-rest-framework/master.svg
   :target: https://codecov.io/github/encode/django-rest-framework?branch=master
.. |pypi-version| image:: https://img.shields.io/pypi/v/djangorestframework.svg
   :target: https://pypi.python.org/pypi/djangorestframework
.. |image3| image:: https://raw.githubusercontent.com/encode/django-rest-framework/master/docs/img/premium/rover-readme.png
   :target: http://jobs.rover.com/
.. |image4| image:: https://raw.githubusercontent.com/encode/django-rest-framework/master/docs/img/premium/sentry-readme.png
   :target: https://getsentry.com/welcome/
.. |image5| image:: https://raw.githubusercontent.com/encode/django-rest-framework/master/docs/img/premium/stream-readme.png
   :target: https://getstream.io/try-the-api/?utm_source=drf&utm_medium=banner&utm_campaign=drf
.. |image6| image:: https://raw.githubusercontent.com/encode/django-rest-framework/master/docs/img/premium/machinalis-readme.png
   :target: https://hello.machinalis.co.uk/
.. |image7| image:: https://raw.githubusercontent.com/encode/django-rest-framework/master/docs/img/premium/rollbar-readme.png
   :target: https://rollbar.com/



            

Raw data

            {
    "maintainer": "", 
    "docs_url": null, 
    "requires_python": ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*", 
    "maintainer_email": "", 
    "cheesecake_code_kwalitee_id": null, 
    "keywords": "", 
    "upload_time": "2018-04-06 13:42:12", 
    "author": "Tom Christie", 
    "home_page": "http://www.django-rest-framework.org", 
    "download_url": "https://pypi.python.org/packages/c4/c0/a0d5a5872fb97c9210fb932116b2bf11f7b159239b00d514f5357b9cf11f/djangorestframework-3.8.2.tar.gz", 
    "platform": "", 
    "version": "3.8.2", 
    "cheesecake_documentation_id": null, 
    "description": "`Django REST framework <http://www.django-rest-framework.org/>`__\n=================================================================\n\n|build-status-image| |coverage-status-image| |pypi-version|\n\n**Awesome web-browsable Web APIs.**\n\nFull documentation for the project is available at\n`http://www.django-rest-framework.org <http://www.django-rest-framework.org/>`__.\n\n--------------\n\nFunding\n=======\n\nREST framework is a *collaboratively funded project*. If you use REST\nframework commercially we strongly encourage you to invest in its\ncontinued development by `signing up for a paid\nplan <https://fund.django-rest-framework.org/topics/funding/>`__.\n\nThe initial aim is to provide a single full-time position on REST\nframework. *Every single sign-up makes a significant impact towards\nmaking that possible.*\n\n|image3| |image4| |image5| |image6| |image7|\n\nMany thanks to all our `wonderful\nsponsors <https://fund.django-rest-framework.org/topics/funding/#our-sponsors>`__,\nand in particular to our premium backers,\n`Rover <http://jobs.rover.com/>`__,\n`Sentry <https://getsentry.com/welcome/>`__,\n`Stream <https://getstream.io/try-the-api/?utm_source=drf&utm_medium=banner&utm_campaign=drf>`__,\n`Machinalis <https://hello.machinalis.co.uk/>`__, and\n`Rollbar <https://rollbar.com/>`__.\n\n--------------\n\nOverview\n========\n\nDjango REST framework is a powerful and flexible toolkit for building\nWeb APIs.\n\nSome reasons you might want to use REST framework:\n\n-  The `Web browsable API <https://restframework.herokuapp.com/>`__ is a\n   huge usability win for your developers.\n-  `Authentication\n   policies <http://www.django-rest-framework.org/api-guide/authentication/>`__\n   including optional packages for\n   `OAuth1a <http://www.django-rest-framework.org/api-guide/authentication/#django-rest-framework-oauth>`__\n   and\n   `OAuth2 <http://www.django-rest-framework.org/api-guide/authentication/#django-oauth-toolkit>`__.\n-  `Serialization <http://www.django-rest-framework.org/api-guide/serializers/>`__\n   that supports both\n   `ORM <http://www.django-rest-framework.org/api-guide/serializers/#modelserializer>`__\n   and\n   `non-ORM <http://www.django-rest-framework.org/api-guide/serializers/#serializers>`__\n   data sources.\n-  Customizable all the way down - just use `regular function-based\n   views <http://www.django-rest-framework.org/api-guide/views/#function-based-views>`__\n   if you don't need the\n   `more <http://www.django-rest-framework.org/api-guide/generic-views/>`__\n   `powerful <http://www.django-rest-framework.org/api-guide/viewsets/>`__\n   `features <http://www.django-rest-framework.org/api-guide/routers/>`__.\n-  `Extensive documentation <http://www.django-rest-framework.org/>`__,\n   and `great community\n   support <https://groups.google.com/forum/?fromgroups#!forum/django-rest-framework>`__.\n\nThere is a live example API for testing purposes, `available\nhere <https://restframework.herokuapp.com/>`__.\n\n**Below**: *Screenshot from the browsable API*\n\n.. figure:: http://www.django-rest-framework.org/img/quickstart.png\n   :alt: Screenshot\n\n   Screenshot\n\n--------------\n\nRequirements\n============\n\n-  Python (2.7, 3.4, 3.5, 3.6)\n-  Django (1.10, 1.11, 2.0)\n\nInstallation\n============\n\nInstall using ``pip``...\n\n::\n\n    pip install djangorestframework\n\nAdd ``'rest_framework'`` to your ``INSTALLED_APPS`` setting.\n\n::\n\n    INSTALLED_APPS = (\n        ...\n        'rest_framework',\n    )\n\nExample\n=======\n\nLet's take a look at a quick example of using REST framework to build a\nsimple model-backed API for accessing users and groups.\n\nStartup up a new project like so...\n\n::\n\n    pip install django\n    pip install djangorestframework\n    django-admin.py startproject example .\n    ./manage.py migrate\n    ./manage.py createsuperuser\n\nNow edit the ``example/urls.py`` module in your project:\n\n.. code:: python\n\n    from django.conf.urls import url, include\n    from django.contrib.auth.models import User\n    from rest_framework import serializers, viewsets, routers\n\n    # Serializers define the API representation.\n    class UserSerializer(serializers.HyperlinkedModelSerializer):\n        class Meta:\n            model = User\n            fields = ('url', 'username', 'email', 'is_staff')\n\n\n    # ViewSets define the view behavior.\n    class UserViewSet(viewsets.ModelViewSet):\n        queryset = User.objects.all()\n        serializer_class = UserSerializer\n\n\n    # Routers provide a way of automatically determining the URL conf.\n    router = routers.DefaultRouter()\n    router.register(r'users', UserViewSet)\n\n\n    # Wire up our API using automatic URL routing.\n    # Additionally, we include login URLs for the browsable API.\n    urlpatterns = [\n        url(r'^', include(router.urls)),\n        url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework'))\n    ]\n\nWe'd also like to configure a couple of settings for our API.\n\nAdd the following to your ``settings.py`` module:\n\n.. code:: python\n\n    INSTALLED_APPS = (\n        ...  # Make sure to include the default installed apps here.\n        'rest_framework',\n    )\n\n    REST_FRAMEWORK = {\n        # Use Django's standard `django.contrib.auth` permissions,\n        # or allow read-only access for unauthenticated users.\n        'DEFAULT_PERMISSION_CLASSES': [\n            'rest_framework.permissions.DjangoModelPermissionsOrAnonReadOnly'\n        ]\n    }\n\nThat's it, we're done!\n\n::\n\n    ./manage.py runserver\n\nYou can now open the API in your browser at ``http://127.0.0.1:8000/``,\nand view your new 'users' API. If you use the ``Login`` control in the\ntop right corner you'll also be able to add, create and delete users\nfrom the system.\n\nYou can also interact with the API using command line tools such as\n```curl`` <https://curl.haxx.se/>`__. For example, to list the users\nendpoint:\n\n::\n\n    $ curl -H 'Accept: application/json; indent=4' -u admin:password http://127.0.0.1:8000/users/\n    [\n        {\n            \"url\": \"http://127.0.0.1:8000/users/1/\",\n            \"username\": \"admin\",\n            \"email\": \"admin@example.com\",\n            \"is_staff\": true,\n        }\n    ]\n\nOr to create a new user:\n\n::\n\n    $ curl -X POST -d username=new -d email=new@example.com -d is_staff=false -H 'Accept: application/json; indent=4' -u admin:password http://127.0.0.1:8000/users/\n    {\n        \"url\": \"http://127.0.0.1:8000/users/2/\",\n        \"username\": \"new\",\n        \"email\": \"new@example.com\",\n        \"is_staff\": false,\n    }\n\nDocumentation & Support\n=======================\n\nFull documentation for the project is available at\n`http://www.django-rest-framework.org <http://www.django-rest-framework.org/>`__.\n\nFor questions and support, use the `REST framework discussion\ngroup <https://groups.google.com/forum/?fromgroups#!forum/django-rest-framework>`__,\nor ``#restframework`` on freenode IRC.\n\nYou may also want to `follow the author on\nTwitter <https://twitter.com/_tomchristie>`__.\n\nSecurity\n========\n\nIf you believe you've found something in Django REST framework which has\nsecurity implications, please **do not raise the issue in a public\nforum**.\n\nSend a description of the issue via email to\nrest-framework-security@googlegroups.com. The project maintainers will\nthen work with you to resolve any issues where required, prior to any\npublic disclosure.\n\n.. |build-status-image| image:: https://secure.travis-ci.org/encode/django-rest-framework.svg?branch=master\n   :target: https://travis-ci.org/encode/django-rest-framework?branch=master\n.. |coverage-status-image| image:: https://img.shields.io/codecov/c/github/encode/django-rest-framework/master.svg\n   :target: https://codecov.io/github/encode/django-rest-framework?branch=master\n.. |pypi-version| image:: https://img.shields.io/pypi/v/djangorestframework.svg\n   :target: https://pypi.python.org/pypi/djangorestframework\n.. |image3| image:: https://raw.githubusercontent.com/encode/django-rest-framework/master/docs/img/premium/rover-readme.png\n   :target: http://jobs.rover.com/\n.. |image4| image:: https://raw.githubusercontent.com/encode/django-rest-framework/master/docs/img/premium/sentry-readme.png\n   :target: https://getsentry.com/welcome/\n.. |image5| image:: https://raw.githubusercontent.com/encode/django-rest-framework/master/docs/img/premium/stream-readme.png\n   :target: https://getstream.io/try-the-api/?utm_source=drf&utm_medium=banner&utm_campaign=drf\n.. |image6| image:: https://raw.githubusercontent.com/encode/django-rest-framework/master/docs/img/premium/machinalis-readme.png\n   :target: https://hello.machinalis.co.uk/\n.. |image7| image:: https://raw.githubusercontent.com/encode/django-rest-framework/master/docs/img/premium/rollbar-readme.png\n   :target: https://rollbar.com/\n\n\n", 
    "lcname": "djangorestframework", 
    "bugtrack_url": "", 
    "github": false, 
    "name": "djangorestframework", 
    "license": "BSD", 
    "summary": "Web APIs for Django, made easy.", 
    "split_keywords": [], 
    "author_email": "tom@tomchristie.com", 
    "urls": [
        {
            "has_sig": false, 
            "upload_time": "2018-04-06T13:42:08", 
            "comment_text": "", 
            "python_version": "py2.py3", 
            "url": "https://pypi.python.org/packages/90/30/ad1148098ff0c375df2a30cc4494ed953cf7551fc1ecec30fc951c712d20/djangorestframework-3.8.2-py2.py3-none-any.whl", 
            "md5_digest": "1ed0f738971456eefa8b6d16ab6b11ad", 
            "downloads": 0, 
            "filename": "djangorestframework-3.8.2-py2.py3-none-any.whl", 
            "packagetype": "bdist_wheel", 
            "path": "90/30/ad1148098ff0c375df2a30cc4494ed953cf7551fc1ecec30fc951c712d20/djangorestframework-3.8.2-py2.py3-none-any.whl", 
            "digests": {
                "sha256": "c375e4f95a3a64fccac412e36fb42ba36881e52313ec021ef410b40f67cddca4", 
                "md5": "1ed0f738971456eefa8b6d16ab6b11ad"
            }, 
            "sha256_digest": "c375e4f95a3a64fccac412e36fb42ba36881e52313ec021ef410b40f67cddca4", 
            "size": 923371
        }, 
        {
            "has_sig": false, 
            "upload_time": "2018-04-06T13:42:12", 
            "comment_text": "", 
            "python_version": "source", 
            "url": "https://pypi.python.org/packages/c4/c0/a0d5a5872fb97c9210fb932116b2bf11f7b159239b00d514f5357b9cf11f/djangorestframework-3.8.2.tar.gz", 
            "md5_digest": "8f39a4211d0431d5df2d26dd0ad76b84", 
            "downloads": 0, 
            "filename": "djangorestframework-3.8.2.tar.gz", 
            "packagetype": "sdist", 
            "path": "c4/c0/a0d5a5872fb97c9210fb932116b2bf11f7b159239b00d514f5357b9cf11f/djangorestframework-3.8.2.tar.gz", 
            "digests": {
                "sha256": "b6714c3e4b0f8d524f193c91ecf5f5450092c2145439ac2769711f7eba89a9d9", 
                "md5": "8f39a4211d0431d5df2d26dd0ad76b84"
            }, 
            "sha256_digest": "b6714c3e4b0f8d524f193c91ecf5f5450092c2145439ac2769711f7eba89a9d9", 
            "size": 795446
        }
    ], 
    "_id": null, 
    "cheesecake_installability_id": null
}