djangorestframework-dataclasses
A dataclasses serializer for Django REST Framework
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-dataclassesuv
uv add djangorestframework-dataclassespoetry
poetry add djangorestframework-dataclassesInstalling 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
Tags
More Python Modules packages
Converts domain names between Unicode and…
permissive · top 100 on PyPI
setuptoolsSetuptools is a Python build backend and…
permissive · top 100 on PyPI
PyYAMLPyYAML parses and emits YAML 1.1 data format,…
permissive · top 100 on PyPI
pydanticPydantic validates Python data structures…
permissive · top 100 on PyPI
annotated-typesProvides reusable metadata objects for use with…
permissive · top 100 on PyPI
typing-inspectionProvides runtime tools to inspect and…
permissive · top 100 on PyPI
dataclassesProvides the PEP 557 dataclasses module for…
permissive · top 5,000 on PyPI
drf-pydanticBridges pydantic models and Django REST…
permissive · top 15,000 on PyPI
django-typomaticGenerates TypeScript interfaces and enums from…
unclear · top 15,000 on PyPI
jax-dataclassesProvides a JAX-compatible wrapper around Python…
permissive · top 15,000 on PyPI
desertDesert generates marshmallow serialization…
permissive · top 15,000 on PyPI
drf-extra-fieldsProvides specialized serializer fields for…
permissive · top 15,000 on PyPI
serpyco-rsSerializes and deserializes Python dataclasses…
permissive · top 15,000 on PyPI
rest-framework-generic-relationsProvides Django REST Framework serializers that…
permissive · top 15,000 on PyPI
dataclasses-jsonConverts Python dataclasses to and from JSON…
permissive · top 1,000 on PyPI
drf-jsonschema-serializerConverts Django REST Framework serializers to…
permissive · top 15,000 on PyPI