Overview

attrs 22.1, released on July 28, 2022, drops Python 2 support and adds comparison validators.

Main Features

Dropped Python 2

attrs is now Python 3 only, enabling cleaner internal code and native type annotations.

python
import attrs

# Modern API, Python 3 only
@attrs.define
class Config:
    host: str = 'localhost'
    port: int = attrs.field(default=8080)
    debug: bool = False

Comparison validators

The gt, ge, lt, le validators allow validating numeric field values.

python
import attrs

@attrs.define
class Temperature:
    celsius: float = attrs.field(
        validator=attrs.validators.ge(-273.15)
    )

t = Temperature(20.0)   # OK
# Temperature(-300.0)   # ValueError

Sources