Skip to content
YAML support for Django REST Framework
Branch: master
Clone or download
jpadilla Merge pull request #8 from jayvdb/patch-1
Set LICENSE to BSD-3-Clause
Latest commit 4067e59 Apr 13, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
docs Use shields.io May 27, 2015
rest_framework_yaml Bump up version Dec 20, 2015
tests Fix handling of Hyperlink. Sep 1, 2015
.gitignore Initial commit Nov 24, 2014
.travis.yml
LICENSE Set LICENSE to BSD-3-Clause Apr 10, 2019
MANIFEST.in Update setup.py and requirements Dec 18, 2014
README.md Update README.md May 27, 2015
mkdocs.yml Initial commit Nov 24, 2014
requirements.txt Update setup.py and requirements Dec 18, 2014
runtests.py
setup.cfg Initial commit Nov 24, 2014
setup.py
tox.ini Run tests against official 3.0 build Dec 16, 2014

README.md

REST Framework YAML

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.

You can’t perform that action at this time.