{"id":10072,"library":"py-automapper","title":"py-automapper: Object Mapping Library","description":"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.","status":"active","version":"2.2.0","language":"en","source_language":"en","source_url":"https://github.com/anikolaienko/py-automapper.git","tags":["mapping","object-mapping","data-transformation","boilerplate-reduction","dto"],"install":[{"cmd":"pip install py-automapper","lang":"bash","label":"Install stable version"}],"dependencies":[],"imports":[{"note":"The Automapper class was removed in v2.0.0; use the automap function directly.","wrong":"from py_automapper import Automapper","symbol":"automap","correct":"from py_automapper import automap"}],"quickstart":{"code":"from py_automapper import automap\n\nclass SourceDTO:\n    def __init__(self, first_name: str, last_name: str, age: int):\n        self.first_name = first_name\n        self.last_name = last_name\n        self.age = age\n\nclass UserDomainModel:\n    def __init__(self, full_name: str, years_old: int):\n        self.full_name = full_name\n        self.years_old = years_old\n\nsource_data = SourceDTO(first_name=\"Alice\", last_name=\"Smith\", age=30)\n\n# Map with custom field names and a transformation function\ndomain_model = automap(\n    source_data,\n    UserDomainModel,\n    mapping_cfg={\n        \"first_name\": \"full_name\",\n        \"last_name\": lambda src: src.last_name, # Can also use lambdas for complex transformations\n        \"age\": \"years_old\"\n    },\n    func_cfg={\n        \"full_name\": lambda src: f\"{src.first_name} {src.last_name}\"\n    }\n)\n\nprint(f\"Full Name: {domain_model.full_name}\")\nprint(f\"Years Old: {domain_model.years_old}\")","lang":"python","description":"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."},"warnings":[{"fix":"Update calls to `automap` to pass the destination class, e.g., `automap(source_obj, DestinationClass)` instead of `automap(source_obj, DestinationClass())`.","message":"The `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.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Replace `map_config=...` with `mapping_cfg=...` in `automap` calls.","message":"The argument for custom field mapping was renamed from `map_config` to `mapping_cfg` in v2.0.0.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Change `automap_list(source_list, Destination)` to `automap(source_list, List[Destination], many=True)`.","message":"The `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`.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Always provide a `mapping_cfg` dictionary when field names differ, or use `func_cfg` for value transformations.","message":"If source and destination field names do not match exactly, `automap` will raise an `AttributeError` unless a `mapping_cfg` dictionary is provided.","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"Replace usage of `Automapper` class with direct calls to the `automap` function: `from py_automapper import automap`.","cause":"Attempting to use the `Automapper` class which was removed in `v2.0.0`.","error":"NameError: name 'Automapper' is not defined"},{"fix":"Modify the `automap` call to pass the destination *type* (class) as the second argument, e.g., `automap(source_obj, DestinationClass)`.","cause":"Passing an instance of the destination object (e.g., `DestinationClass()`) instead of the destination class (e.g., `DestinationClass`) to `automap` after v2.0.0.","error":"TypeError: automap() got multiple values for argument 'destination_type' (or similar signature error for destination object)"},{"fix":"Update the argument name from `map_config` to `mapping_cfg` in your `automap` calls.","cause":"Using the old keyword argument name `map_config` which was renamed to `mapping_cfg` in `v2.0.0`.","error":"TypeError: automap() got an unexpected keyword argument 'map_config'"},{"fix":"Provide a `mapping_cfg` dictionary to specify how the destination field should be populated, or use `func_cfg` for complex transformations. For example: `mapping_cfg={'first_name': 'full_name'}` or `func_cfg={'full_name': lambda src: f'{src.first_name} {src.last_name}'}`.","cause":"The destination object has a field (e.g., `full_name`) that does not exist in the source object and no custom mapping or function was provided for it.","error":"AttributeError: 'SourceDTO' object has no attribute 'full_name' (or similar for an unmatched field)"}]}