Skip to main content

YAML support for Django REST Framework

Project description

build-status-image pypi-version

YAML support for Django REST Framework

Full documentation for the project is available at http://jpadilla.github.io/django-rest-framework-yaml.

Overview

YAML support extracted as a third party package directly from the official Django REST Framework implementation. It’s built using the PyYAML package.

Requirements

  • Python (2.7, 3.3, 3.4)

  • Django (1.6, 1.7)

Installation

Install using pip

$ pip install djangorestframework-yaml

Example

REST_FRAMEWORK = {
    'DEFAULT_PARSER_CLASSES': (
        'rest_framework_yaml.parsers.YAMLParser',
    ),
    'DEFAULT_RENDERER_CLASSES': (
        'rest_framework_yaml.renderers.YAMLRenderer',
    ),
}

You can also set the renderer and parser used for an individual view, or viewset, using the APIView class based views.

from rest_framework import routers, serializers, viewsets
from rest_framework_yaml.parsers import YAMLParser
from rest_framework_yaml.renderers import YAMLRenderer

# 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
    parser_classes = (YAMLParser,)
    renderer_classes = (YAMLRenderer,)

Sample output

---
-
  email: jpadilla@example.com
  is_staff: true
  url: "http://127.0.0.1:8000/users/1/"
  username: jpadilla

Documentation & Support

Full documentation for the project is available at http://jpadilla.github.io/django-rest-framework-yaml.

You may also want to follow the author on Twitter.

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

djangorestframework-yaml-1.0.2.tar.gz (3.9 kB view details)

Uploaded Source

Built Distribution

djangorestframework_yaml-1.0.2-py2.py3-none-any.whl (5.5 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file djangorestframework-yaml-1.0.2.tar.gz.

File metadata

File hashes

Hashes for djangorestframework-yaml-1.0.2.tar.gz
Algorithm Hash digest
SHA256 99fe315703a8ea90c18426990fbf34632619390aace2ca261db88232b46c0846
MD5 c3902ae1e2938a08d7a1bc83e3163647
BLAKE2b-256 763f0fa255c63a007c2cedd8ea0f2b361d2b55e8577b61aa8d04b5e912fae346

See more details on using hashes here.

File details

Details for the file djangorestframework_yaml-1.0.2-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for djangorestframework_yaml-1.0.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 60dca307df50c76dec4845d534ef945f2d92f65ff310fb6555ba7a2e3f84552b
MD5 db4c79f99cb2e388dc2e1792fc7cf6de
BLAKE2b-256 412f5d112ac5c7164400554d15aa9b657cef0624b21b3adb5c64082eff750658

See more details on using hashes here.

Supported by

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