A Brand-new feature in Python 3.7 is “Data Classes”. Data classes are a way of automating the generation of boiler-plate code for classes which store multiple properties. They also carry the benefit of using Python 3’s new type hinting. Dataclasses come in the new module within the standard library in Python 3.7 and there are 2 important things you’ll need. dataclasses The decorator, for decorating a data class dataclass The method, for configuring fields field Default magic methods In the default setting, any dataclass will implement , , and for you. __init__ __repr__ __str__ __eq__ The method will have with the same type annotations that are specified on the class. __init__ keyword-arguments The method will compare all dataclass attributes in order. __eq__ All fields are declared at the top of the class and type hinting is . required This method will have a signature of . You can see this by just typing __init__ (field_a: int, field_b: str) -> None print(inspect.signature(example.__init__)) Type hinting Quite importantly, the type hints are merely hints. So giving the wrong types doesn’t issue a warning or attempt a conversion. Because type hinting is (otherwise the field is ignored), if you don’t have a specific type, use the type from the module. required Any typing Mutability The dataclass decorator has a argument, which is False by default. If specified, fields will be “ ”, ie read-only and if is set to True, which it is by default then the magic will be implemented and object instances will be hashable so you can use them as dictionary keys or within a set. frozen frozen eq __hash__ Customizing the fields The core type in dataclasses is the type, which belongs to a dataclass. Field By default, just setting a class attribute will instantiate a Field on your class as shown in previous examples. If you need to customise the behaviour, you can use the field factory inside the module. dataclasses The parameters to field() are: : If provided, this will be the default value for this field. This is needed because the field call itself replaces the normal position of the default value. default : A 0-argument callable that will be called when a default value is needed for this field. default_factory : Included as a parameter to the generated __init__ method. init : Included in the string returned by the generated __repr__ method. repr : Included in the generated equality and comparison methods (__eq__, __gt__, et al.). compare : Included in the generated __hash__ method. hash There is also another argument, metadata which is not in use yet. Similar to keyword arguments, fields with default values must be declared last. Demonstrating the default factory argument, Post-Init Processing You can declare a method, which will run after the auto-generated . __post_init__ __init__ Inheritance Inheritance works as you would expect. You need to wrap the classes in for the inherited the base class definitions. dataclass and Although, because you can’t declare a non-default field after a default one, you can’t mix default and non-default fields between base and child classes. This example raises TypeError: non-default argument ‘field_a’ follows default argument This is pretty annoying and probably going to stop people from using either inheritance or default fields too much. All-in-all, this is a great feature and I’ll likely stop using attrs once Python 3.7 is released. Still stuck on Python 2? Check out my new course on Pluralsight for moving from Python 2 to 3.