Skip to main content

REST Framework XML

build-status-image pypi-version

XML support for Django REST Framework

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

Overview

XML support extracted as a third party package directly from the official Django REST Framework implementation. It requires the defusedxml package only because it safeguards against some security issues that were discovered.

Note: XML output provided is an ad-hoc format that isn't formally described. If you have specific XML requirements you'll need to write your own XML parsers/renderers in order to fully control the representation.

Requirements

  • Python 3.5+
  • Django 2.2+
  • Django REST Framework 3.11+

Installation

Install using pip...

$ pip install djangorestframework-xml

Example

REST_FRAMEWORK = {
    'DEFAULT_PARSER_CLASSES': (
        'rest_framework_xml.parsers.XMLParser',
    ),
    'DEFAULT_RENDERER_CLASSES': (
        'rest_framework_xml.renderers.XMLRenderer',
    ),
}

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_xml.parsers import XMLParser
from rest_framework_xml.renderers import XMLRenderer


class UserSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = User
        fields = ('url', 'username', 'email', 'is_staff')


class UserViewSet(viewsets.ModelViewSet):
    queryset = User.objects.all()
    serializer_class = UserSerializer
    parser_classes = (XMLParser,)
    renderer_classes = (XMLRenderer,)

Sample output

<?xml version="1.0" encoding="utf-8"?>
<root>
    <list-item>
        <url>http://127.0.0.1:8000/users/1/.xml</url>
        <username>jpadilla</username>
        <email>jpadilla@example.com</email>
        <is_staff>True</is_staff>
    </list-item>
</root>

Documentation & Support

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

You may also want to follow the author on Twitter.

Release files for djangorestframework-xml 2.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for djangorestframework-xml 2.0.0
File Size Uploaded
djangorestframework-xml-2.0.0.tar.gz 5.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for djangorestframework-xml 2.0.0
File Interpreter ABI Platform
djangorestframework_xml-2.0.0-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 11.5 kB

Release files / djangorestframework-xml-2.0.0.tar.gz

Download URL djangorestframework-xml-2.0.0.tar.gz
Size 5.4 kB
Tags Source
SHA-256 checksum
How to use checksums
35f6c811d0ab8c8466b26db234e16a2ed32d76381715257aebf4c7be2c202ca1
BLAKE2b-256 checksum
How to use checksums
4574b75939a779fddef1d3e108991f7edb199e6240f23b6aef64f3a222e1b4dd
Upload date
Uploaded using Trusted Publishing?
What is 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

Release files / djangorestframework_xml-2.0.0-py2.py3-none-any.whl

Download URL djangorestframework_xml-2.0.0-py2.py3-none-any.whl
Size 6.0 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
975955fbb0d49ac44a90bdeb33b7923d95b79884d283f983e116c80a936ef4d0
BLAKE2b-256 checksum
How to use checksums
0f7465485e0ceae183b9348cd080cc69126e498a95bcd5d37df84a598bf94bbd
Upload date
Uploaded using Trusted Publishing?
What is 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

Release history Release notifications | RSS feed

This release

2.0.0 This release

2 release files

1.4.0

2 release files

1.3.0

2 release files

1.2.0

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page