python_dto_mappers.auto_mapper¶
Auto-mapping engine for matching fields between models.
Classes¶
Class-based auto-mapper for matching fields. |
Module Contents¶
- class python_dto_mappers.auto_mapper.AutoMapper(source_type: Type, target_type: Type, exclude: Set[str] | None = None)¶
Class-based auto-mapper for matching fields.
Automatically maps fields with matching names between source and target Pydantic models. Custom transforms override auto-mapping.
- Example:
>>> mapper = AutoMapper(UserORM, UserDTO, exclude={'internal_id'}) >>> dto = mapper.map(user_orm)
- add_transform(field: str, func: Any) AutoMapper¶
Register a custom transform for a field.
- Args:
field: Field name to transform func: Callable(source) -> value
- Returns:
Self for chaining
- map(source: Any) Any¶
Map source instance to target type.
- Args:
source: Source model instance
- Returns:
Target model instance with mapped fields
- property source_type: Type¶
Source model type.
- property target_type: Type¶
Target model type.
- property mapped_fields: Set[str]¶
Set of fields being mapped.