Dataclass-mapper

Latest version: v1.9.3

Safety actively analyzes 702088 Python packages for vulnerabilities to keep your Python projects secure.

Scan your dependencies

Page 4 of 5

1.4.0

Enums

With this release it's now possible to create mappings for enums (using `enum_mapper` and `enum_mapper_from`).

py
class Foo(Enum):
A = 1
B = 2
OTHER = 99

enum_mapper(Foo, {"ELSE": "OTHER"})
class Bar(str, Enum):
A = "A"
B = "B"
ELSE = "ELSE"


Notice, that the order of the mapping parameters is exactly the other way round. It's not `target: source`. That is important for dataclasses, as every target field needs to be mapped by something - and can potentially be defined via a lambda. So every target field had at most one definition, that relied of one or multiple other pieces.

But with enums it's important, that every single member of the source enum is mapped to something. And it's possible that multiple source values map to the same target field. So the mapping definition `source:target` makes a lot more sense.

Pydantic's alias

Also there is now full support for Pydantic's aliases. If an alias was defined for a field, you need to create object with those alias.

py
class Baz(BaseModel):
x: int = Field(alias="y")

baz = Baz(y=42)


The `dataclass-mapper<1.4.0` library would have instantiated those class objects wrongly with `Baz(x=42)`. With this release, it will use the alias if required by the class/field definition. But it will fallback to the field name, if the option `allow_population_by_field_name` is set - just in case non-Python variable names are use as aliases.

1.3.0

In the last release 1.2.0 you had to set a flag `bypass_validators` to get a speedup.
That was unsafe, as it didn't check if the class really had validators, and in the worst case changed the behavior of the class (e.g. if you bypass a validator that modifies some values).
With 1.3.0 the `dataclass-mapper` library will automatically detect if there are validators in use, and will construct the new object only with `.construct` if no validators are in use. If there are any, it will fallback to the slow initialization with `__init__`.

1.2.0

Disable Pydantic validations by using `.construct` in order to give a huge speed improvement. You have to enable it with the `bypass_validators` flag.

1.1.0

**Changes:**

- `IGNORE_MISSING_MAPPING` literal as replacement for `USE_DEFAULT` (2)
- `USE_DEFAULT` is deprecated (2)
- Optional Fields in Pydantic are only mapped, if they are set. I.e. the target object still reflects in `__fields_set__` the fields that were set in the original object, so that it's possible to distinguish between `None` and `Undefined`.

1.0.2

1.0.1

Adds additional information to the packages, like a description, the Readme, the repository and docs, ...

Page 4 of 5

© 2025 Safety CLI Cybersecurity Inc. All Rights Reserved.