Registry / serialization / py-automapper

py-automapper

JSON →
library2.2.0pypypi✓ verified 85d ago

py-automapper is a Python library designed for automatically mapping data from one object to another, reducing boilerplate code in data transfer operations. It is currently at version 2.2.0 and receives active maintenance with several releases per year.

pip install py-automapper
INSTALL
IMPORT
SIG · PY-AUTOMAPPER
P
py-automapper
serializationpythonv2.2.0
Install
1.6s avg
Import
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v2.2.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.910 runs
installs and imports cleanly · install 0.0s · import 0.000s · 17.9MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 1.6s · import 0.000s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Mapper
from automapper import Mapper
from py_automapper import automap
create_mapper
from automapper import create_mapper
from py_automapper import automap
MappingError
from automapper import MappingError
from py_automapper import automap

This quickstart demonstrates how to map a SourceDTO object to a UserDomainModel. It includes mapping configuration for different field names and a function configuration for custom value transformations, specifically concatenating first and last names into a full name.

from py_automapper import automap class SourceDTO: def __init__(self, first_name: str, last_name: str, age: int): self.first_name = first_name self.last_name = last_name self.age = age class UserDomainModel: def __init__(self, full_name: str, years_old: int): self.full_name = full_name self.years_old = years_old source_data = SourceDTO(first_name="Alice", last_name="Smith", age=30) # Map with custom field names and a transformation function domain_model = automap( source_data, UserDomainModel, mapping_cfg={ "first_name": "full_name", "last_name": lambda src: src.last_name, # Can also use lambdas for complex transformations "age": "years_old" }, func_cfg={ "full_name": lambda src: f"{src.first_name} {src.last_name}" } ) print(f"Full Name: {domain_model.full_name}") print(f"Years Old: {domain_model.years_old}")
Debug
Known issues
breakingThe `automap` function signature changed significantly in v2.0.0. It now expects the destination *type* (class) as the second argument, not an instance. The `Automapper` class was also removed.
fix
Update calls to `automap` to pass the destination class, e.g., `automap(source_obj, DestinationClass)` instead of `automap(source_obj, DestinationClass())`.
affects: >=2.0.0
breakingThe argument for custom field mapping was renamed from `map_config` to `mapping_cfg` in v2.0.0.
fix
Replace `map_config=...` with `mapping_cfg=...` in `automap` calls.
affects: >=2.0.0
breakingThe `automap_list` function was removed in v2.0.0. For mapping lists, use the `automap` function with a `list` type hint for the destination and pass `many=True`.
fix
Change `automap_list(source_list, Destination)` to `automap(source_list, List[Destination], many=True)`.
affects: >=2.0.0
gotchaIf source and destination field names do not match exactly, `automap` will raise an `AttributeError` unless a `mapping_cfg` dictionary is provided.
fix
Always provide a `mapping_cfg` dictionary when field names differ, or use `func_cfg` for value transformations.
affects: All
Upgrade
Version history
2.2.0latest on PyPI · released Mar 9, 2025
Audit
Dependencies

No dependency data recorded yet.

Agent activity
5 hits · last 30 days
node
4
Resources
py-automapper — pip install py-automapper · libregistry