Skip to main content

drf-multi-serializers

Handle multiple serializers for the same view in Django Rest Framework.

This package uses uv for project management. To get started, ensure that uv is installed on your machine and updated to the 0.5.6 version. Detailed installation instructions for uv can be found here.

Installation

uv add drf-multi-serializers

Usage

Simply import the MultiSerializerMixin and use it in your API views:

from rest_framework.generics import ListCreateAPIView
from rest_framework.viewsets import ModelViewSet
from drf_multi_serializers import MultiSerializerMixin

...

class MyListCreateAPIView(MultiSerializerMixin, ListCreateAPIView):
    ...
    serializer_classes = {
        "create": MyCreateSerializer,
        "list": MyListSerializer,
    }
    ...

class MyViewSet(MultiSerializerMixin, ModelViewSet):
    ...
    serializer_classes = {
        "create": MyCreateSerializer,
        "list": MyListSerializer,
        "metadata": MyMetadataSerializer,  # create ViewSets require either serializer_class or metadata serializer for OPTION requests
        "partial_update": MyUpdateSerializer,
        "retrieve": MyRetrieveSerializer,
        "update": MyUpdateSerializer,
    }
    ...

drf-multi-serializers also supports Django Rest Framework's versioning system!

from rest_framework.generics import ListCreateAPIView
from rest_framework.viewsets import ModelViewSet
from drf_multi_serializers import MultiSerializerMixin

...

class MyAPIView(MultiSerializerMixin, APIView):
    ...
    serializer_classes = {
        "v1": MyV1Serializer,
        "v2": MyV2Serializer,
    }
    ...

class MyViewSet(MultiSerializerMixin, ModelViewSet):
    ...
    serializer_classes = {
        "create": {"v1": MyV1CreateSerializer, "v2": MyV2CreateSerializer},
        "list": MyListSerializer,
        "metadata": MyMetadataSerializer,  # create ViewSets require either serializer_class or metadata serializer for OPTION requests
        "partial_update": MyUpdateSerializer,
        "retrieve": MyRetrieveSerializer,
        "update": MyUpdateSerializer,
    }
    ...

Development

uv sync --frozen --group=development
uv run --frozen pre-commit install --install-hooks
uv run --frozen pre-commit install --hook-type=commit-msg

Contributing

Contributions are welcome! To get started, please refer to our contribution guidelines.

Issues

If you encounter any problems while using this package, please open a new issue here.

Metadata

Release files for drf-multi-serializers 1.4.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 drf-multi-serializers 1.4.0
File Size Uploaded Provenance Actions
drf_multi_serializers-1.4.0.tar.gz 11.5 kB Without provenance Details for drf_multi_serializers-1.4.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for drf-multi-serializers 1.4.0
File Interpreter ABI Platform Actions
drf_multi_serializers-1.4.0-py3-none-any.whl Python 3 none any Details for drf_multi_serializers-1.4.0-py3-none-any.whl

Total release size: 15.5 kB

Release files / drf_multi_serializers-1.4.0.tar.gz

Download URL drf_multi_serializers-1.4.0.tar.gz
Size 11.5 kB
Tags Source
SHA-256 checksum
How to use checksums
847d3e6d837398815d6c170c6afefccd7949683d59408bd367d2d4498fb29bed
BLAKE2b-256 checksum
How to use checksums
83d3ada6d9ecd3992783287fd6b306dce929e993855b6a5e6deaead657856907
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.5.6

Release files / drf_multi_serializers-1.4.0-py3-none-any.whl

Download URL drf_multi_serializers-1.4.0-py3-none-any.whl
Size 3.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e4448c289a81c86c2a07f31384f4237714ae317fffc056dff490dc8f3a740455
BLAKE2b-256 checksum
How to use checksums
fc173d6c3b4fe7db771b84f480bea77e7a647bc0b40a3eaf9d2f3775207516ae
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.5.6

Security for drf-multi-serializers 1.4.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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