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_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 sort 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.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.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 dataclasses 0.6
File Size Uploaded
dataclasses-0.6.tar.gz 36.8 kB Details

Built distribution (wheel)

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

Total release size: 51.6 kB

Release files / dataclasses-0.6.tar.gz

Download URL dataclasses-0.6.tar.gz
Size 36.8 kB
Tags Source
SHA-256 checksum
How to use checksums
6988bd2b895eef432d562370bb707d540f32f7360ab13da45340101bc2307d84
BLAKE2b-256 checksum
How to use checksums
59e42f921edfdf1493bdc07b914cbea43bc334996df4841a34523baf73d1fb4f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

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

Download URL dataclasses-0.6-py3-none-any.whl
Size 14.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
454a69d788c7fda44efd71e259be79577822f5e3f53f029a22d08004e951dc9f
BLAKE2b-256 checksum
How to use checksums
262f1095cdc2868052dd1e64520f7c0d5c8c550ad297e944e641dbf1ffbb9a5d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

0.8

2 release files

0.7

2 release files

This release

0.6 This release

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