skillfed

djangorestframework-dataclasses

A dataclasses serializer for Django REST Framework

djangorestframework-dataclasses v1.4.0 2.8M downloads/30d#2,867 on PyPI468
Permissive license Copyright (c) 2019-2021, Oxan van Leeuwen Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1.… (full text in the JSON record) AGING released

What it is and what it does

This package provides a DataclassSerializer that automatically generates Django REST Framework serializer fields from dataclass type annotations. Instead of manually declaring each field twice—once in the dataclass and again in a DRF Serializer—you define the dataclass with type hints and let the serializer introspect it. The package handles common Python types (str, bool, int, float, date, datetime, time, timedelta, Decimal, UUID, Enum, Literal, Union, Iterable, Mapping) and generates corresponding REST Framework fields, respecting optional fields, nullable types, and read-only markers.

It follows the ModelSerializer pattern familiar to Django developers: you specify the dataclass in a Meta subclass, optionally override or add fields, and get create() and update() implementations for free. The serializer works with the standard DRF workflow—calling .data for serialized output, .validated_data for deserialized instances, and save() to persist or update objects. This is most useful in projects that use dataclasses for domain models or DTOs rather than Django ORM models.

Use it for:

  • Serialize and deserialize dataclass-based domain models in REST APIs without duplicating field definitions.
  • Build REST endpoints that accept and return typed dataclass instances instead of raw dictionaries.
  • Reduce boilerplate when working with dataclasses as request/response DTOs in Django views or viewsets.
  • Automatically validate incoming data against dataclass type annotations and constraints.
  • Migrate from ModelSerializer-based APIs to dataclass-based architectures with minimal refactoring.

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

Automatically generates Django REST Framework serializers from Python dataclasses, mapping dataclass fields to REST serializer fields without manual duplication.

Yes, if you use dataclasses as your primary data model layer in Django REST Framework projects. The package is stable and permissively licensed, with low install friction. The 457-day release gap suggests slower maintenance, so verify compatibility with your Django and DRF versions before adopting; otherwise it is a solid fit for eliminating serializer boilerplate.

Install

djangorestframework-dataclasses on PyPI

pip

pip install djangorestframework-dataclasses

uv

uv add djangorestframework-dataclasses

poetry

poetry add djangorestframework-dataclasses

Installing djangorestframework-dataclasses

Before you install

Low friction install with three straightforward runtime dependencies (django, djangorestframework, typing_extensions). Maintenance status is aging—last release was 457 days ago—but the repository remains active and marked Production/Stable.

License in practice

BSD-3-clause license is permissive; you can use, modify, and distribute this package freely in commercial and private projects with minimal restrictions.

Quickstart

pip install djangorestframework-dataclasses

from dataclasses import dataclass
from djangorestframework_dataclasses.serializers import DataclassSerializer

@dataclass
class Person:
    name: str
    email: str

class PersonSerializer(DataclassSerializer):
    class Meta:
        dataclass = Person

Requires Django 3.2+ and Django REST Framework 3.11+; Python 3.7+ (description lists 3.8+ as tested minimum).

Verify before relying

  • Whether the 457-day gap since last release indicates active maintenance or dormancy relative to Django/DRF release cycles.
  • Support status for the latest versions of Django and Django REST Framework beyond what the description guarantees.
  • Full scope of type annotations supported beyond str, bool, int, float, date, datetime, time, timedelta, Decimal, UUID, Enum, Iterable, Mapping, Literal, Union, and django.db.Model.

Package facts

License Copyright (c) 2019-2021, Oxan van Leeuwen Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1.… (full text in the JSON record) (permissive)
Python support supports the current Python release (>=3.7)
Install friction low — pure-Python wheel
Runtime dependencies 3 — django, djangorestframework, typing_extensions
Maintenance aging — 457 days since the last release
Last repo commit
First released
Downloads 2,838,854/month — #2,867 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: djangorestframework_dataclasses-1.4.0-py3-none-any.whl

Development Status :: 5 - Production/StableEnvironment :: Web EnvironmentFramework :: DjangoIntended Audience :: DevelopersLicense :: OSI Approved :: BSD LicenseOperating System :: OS IndependentProgramming Language :: PythonTopic :: Internet :: WWW/HTTPTopic :: Software Development :: Libraries :: Application FrameworksTopic :: Software Development :: Libraries :: Python ModulesTyping :: Typed

Tags

dataclass serializer django rest frameworkautomatic serializer generation dataclassesdjango rest framework dataclass supportserialize dataclasses drfdataclass to rest serializerdjango dataclass serialization
django-rest-frameworkdataclass-serializationapi-development

More Python Modules packages