YAML support for Django REST Framework
Project description
REST Framework YAML
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
Built Distribution
File details
Details for the file djangorestframework-yaml-2.0.0.tar.gz
.
File metadata
- Download URL: djangorestframework-yaml-2.0.0.tar.gz
- Upload date:
- Size: 5.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1b2cfd7482425f3c6924a8eb803d6f73276e76b03293cd7144c755753e029f15 |
|
MD5 | f0ff5bb3af5b198ccbb51bcf0f390f73 |
|
BLAKE2b-256 | 613f3bfebf3d0bcfd3aa448534b0631efdf74851cc8777adf327a157ae800834 |
File details
Details for the file djangorestframework_yaml-2.0.0-py2.py3-none-any.whl
.
File metadata
- Download URL: djangorestframework_yaml-2.0.0-py2.py3-none-any.whl
- Upload date:
- Size: 6.7 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7fe744e6004d2191fa1cb8a4fc62f98150202bfebd60702a04f8187cc240b7c4 |
|
MD5 | a867eac1249419da7fb8ab7044d881aa |
|
BLAKE2b-256 | c1d8033eae74851b5c8894a5a35fb5bb3ec6d45714f3183962dbce5a2b17f18f |