Skip to main content

A backport of the dataclasses module for Python 3.6

Project description

This is an implementation of PEP 557, Data Classes. It is a backport for Python 3.6. Because dataclasses will be included in Python 3.7, any discussion of dataclass features should occur on the python-dev mailing list at At this point this repo should only be used for historical purposes (it’s where the original dataclasses discussions took place) and for discussion of the actual backport to Python 3.6.

See for the details of how Data Classes work.

A test file can be found at, or in the sdist file.


pip install dataclasses

Example Usage

from dataclasses import dataclass

class InventoryItem:
    name: str
    unit_price: float
    quantity_on_hand: int = 0

    def total_cost(self) -> float:
        return self.unit_price * self.quantity_on_hand

item = InventoryItem('hammers', 10.49, 12)

Some additional tools can be found in, included in the sdist.


This backport assumes that dict objects retain their insertion order. This is true in the language spec for Python 3.7 and greater. Since this is a backport to Python 3.6, it raises an interesting question: does that guarantee apply to 3.6? For CPython 3.6 it does. As of the time of this writing, it’s also true for all other Python implementations that claim to be 3.6 compatible, of which there are none. Any new 3.6 implementations are expected to have ordered dicts. See the analysis at the end of this email:

As of version 0.4, this code no longer works with Python 3.7. For 3.7, use the built-in dataclasses module.

Release History






Fix ClassVar in .replace()



Require python 3.6 only



Equivalent to Python 3.7.0rc1



Equivalent to Python 3.7.0b3

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dataclasses-0.8.tar.gz (36.6 kB view hashes)

Uploaded source

Built Distribution

dataclasses-0.8-py3-none-any.whl (19.0 kB view hashes)

Uploaded py3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page