Skip to main content
https://img.shields.io/pypi/v/dataclasses.svg

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 https://mail.python.org/mailman/listinfo/python-dev. 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 https://www.python.org/dev/peps/pep-0557/ for the details of how Data Classes work.

A test file can be found at https://github.com/ericvsmith/dataclasses/blob/master/test/test_dataclasses.py, or in the sdist file.

Installation

pip install dataclasses

Example Usage

from dataclasses import dataclass

@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)
print(item.total_cost())

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

Compatibility

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:

https://mail.python.org/pipermail/python-dev/2017-December/151325.html

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

Version

Date

Description

0.8

2020-11-13

Fix ClassVar in .replace()

0.7

2019-10-20

Require python 3.6 only

0.6

2018-05-17

Equivalent to Python 3.7.0rc1

0.5

2018-03-28

Equivalent to Python 3.7.0b3

Release files for dataclasses 0.8

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dataclasses 0.8
File Size Uploaded
dataclasses-0.8.tar.gz 36.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for dataclasses 0.8
File Interpreter ABI Platform
dataclasses-0.8-py3-none-any.whl Python 3 none any Details

Total release size: 55.6 kB

Release files / dataclasses-0.8.tar.gz

Download URL dataclasses-0.8.tar.gz
Size 36.6 kB
Tags Source
SHA-256 checksum
How to use checksums
8479067f342acf957dc82ec415d355ab5edb7e7646b90dc6e2fd1d96ad084c97
BLAKE2b-256 checksum
How to use checksums
1f127919c5d8b9c497f9180db15ea8ead6499812ea8264a6ae18766d93c59fe5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.4.2 requests/2.24.0 setuptools/28.8.0 requests-toolbelt/0.8.0 tqdm/4.23.4 CPython/3.6.10

Release files / dataclasses-0.8-py3-none-any.whl

Download URL dataclasses-0.8-py3-none-any.whl
Size 19.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0201d89fa866f68c8ebd9d08ee6ff50c0b255f8ec63a71c16fda7af82bb887bf
BLAKE2b-256 checksum
How to use checksums
feca75fac5856ab5cfa51bbbcefa250182e50441074fdc3f803f6e76451fab43
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.4.2 requests/2.24.0 setuptools/28.8.0 requests-toolbelt/0.8.0 tqdm/4.23.4 CPython/3.6.10

Release history Release notifications | RSS feed

This release

0.8 This release

2 release files

0.7

2 release files

0.6

2 release files

0.5

2 release files

0.4

2 release files

0.3

2 release files

0.2

2 release files

0.1

2 release files

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