Skip to main content

Decorator for creating dict based on the drf serializer class for swagger

Project Status
CI/CD Latest Release
Quality Coverage
Package PyPI - Version PyPI - Support Python Versions Project PyPI - Downloads
Meta types - Mypy License - MIT code style - Ruff

Provides a decorator for converting the drf serializer class to a dictionary

Install

  1. Install package
    pip install drf-serializer-dumps
    

About decorator

serializer_dumps decorator is based on the assignment of fields in the serializer to generate a dict, for SerializerMethodField, the definition is made by OpenApiTypes or the usual python type hints.

  • Optional parameters:
    • exclude_fields Exclude a number of serializer fields when generating a dictionary.
    • renew_type_value Generate a new uuid and datetime, date, time when calling the function.
    • extend_type_map Expand the type dictionary to default values, new types and their values, or redefine existing types and their values.

Usage example

Example 1

from rest_framework import serializers
from drf_serializer_dumps.decorators import serializer_dumps


class PersonCars(serializers.Serializer):
    car_name = serializers.CharField()
    car_price = serializers.IntegerField()


class PersonSerializer(serializers.Serializer):
    name = serializers.CharField()
    age = serializers.IntegerField()
    cars = PersonCars(many=True)


result = serializer_dumps(PersonSerializer)
print(result)
>>> {'name': 'string', 'age': 1, 'cars': [{'car_name': 'string', 'car_price': 1}]}

Example 2

from rest_framework import serializers
from django.contrib.postgres.fields import ArrayField
from drf_serializer_dumps.decorators import serializer_dumps


class Person(models.Model):
    name = models.CharField(max_length=256)
    phones = ArrayField(models.CharField(max_length=256))


class PersonSerializer(serializers.ModelSerializer):
    class Meta:
        model = Person
        fields = '__all__'


result = serializer_dumps(PersonSerializer)
print(result)
>>> {'id': 1, 'name': 'string', 'phones': ['string']}

Example 3

Integration with drf-spectacular extend_schema decorator

@extend_schema(
    examples=[
        OpenApiExample('Name1', serializer_dumps(Some1Serializer)),
        OpenApiExample('Name2', serializer_dumps(Some2Serializer)),
    ]
)
def your_api_method(self, request, *args, **kwargs):
    ...

Contributing

We would love you to contribute to drf-serializer-dumps, pull requests are very welcome! Please see CONTRIBUTING.md for more information.

Metadata

Release files for drf-serializer-dumps 1.0.6

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-serializer-dumps 1.0.6
File Size Uploaded Provenance Actions
drf_serializer_dumps-1.0.6.tar.gz 17.5 kB With provenance Details for drf_serializer_dumps-1.0.6.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for drf-serializer-dumps 1.0.6
File Interpreter ABI Platform Actions
drf_serializer_dumps-1.0.6-py3-none-any.whl Python 3 none any Details for drf_serializer_dumps-1.0.6-py3-none-any.whl

Total release size: 25.5 kB

Release files / drf_serializer_dumps-1.0.6.tar.gz

Download URL drf_serializer_dumps-1.0.6.tar.gz
Size 17.5 kB
Tags Source
SHA-256 checksum
How to use checksums
f6eb4ffdce7ff4309052e9250fc086c494d644af4325b7963f5f8e4304a098ac
BLAKE2b-256 checksum
How to use checksums
24f551e020e571900dd0ac233aab96d62f803ee5525bab1e042fc7038e7f3879
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.1 CPython/3.12.7

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 30, 2024.

Transparency log

Release files / drf_serializer_dumps-1.0.6-py3-none-any.whl

Download URL drf_serializer_dumps-1.0.6-py3-none-any.whl
Size 8.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b8f167b4026c3f38f9b48410c4027a790cf4093f0b63eb54bcdec075316ddc7c
BLAKE2b-256 checksum
How to use checksums
89be99df2d7303595f2516483528b3f277eeecc8f30d0559d30371d40745b86c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.1 CPython/3.12.7

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 30, 2024.

Transparency log

Security for drf-serializer-dumps 1.0.6

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.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for drf_serializer_dumps-1.0.6.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 30, 2024.

Transparency log

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