python_dto_mappers.decorators ============================= .. py:module:: python_dto_mappers.decorators .. autoapi-nested-parse:: Decorators for auto-mapping (syntactic sugar over AutoMapper). Functions --------- .. autoapisummary:: python_dto_mappers.decorators.auto_map python_dto_mappers.decorators.field_transform Module Contents --------------- .. py:function:: auto_map(source_type: Type, target_type: Type, exclude: Optional[Set[str]] = None) -> Callable Decorator to auto-generate mapping for matching fields. Uses AutoMapper engine under the hood. Custom transforms can be defined with transform_{field_name} methods on the class. Args: source_type: Source model type target_type: Target model type exclude: Set of field names to exclude from auto-mapping Returns: Class decorator function Example: >>> @auto_map(UserEntity, UserDTO, exclude={'id'}) ... class UserMapper: ... def transform_name(self, source): ... return source.name.upper() .. py:function:: field_transform(field_name: str) -> Callable Mark a method as a field transformation. Args: field_name: Name of the field this transforms Returns: Method decorator Example: >>> @field_transform("created_at") ... def transform_date(self, source): ... return source.created_at.isoformat()