{"id":16417846,"url":"https://github.com/funnydman/pymapme","last_synced_at":"2025-06-28T22:42:47.215Z","repository":{"id":110922769,"uuid":"559503351","full_name":"funnydman/pymapme","owner":"funnydman","description":"Transform Pydantic models from one structure to another with declarative field mapping.","archived":false,"fork":false,"pushed_at":"2025-06-22T15:27:58.000Z","size":61,"stargazers_count":19,"open_issues_count":0,"forks_count":5,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-22T16:32:26.310Z","etag":null,"topics":["models","nested","pydantic","pydantic-models","transformation"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/funnydman.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-10-30T10:21:42.000Z","updated_at":"2025-06-22T15:36:07.000Z","dependencies_parsed_at":null,"dependency_job_id":"0a100adb-ad8c-4744-9133-02b33ebea8f0","html_url":"https://github.com/funnydman/pymapme","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/funnydman/pymapme","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/funnydman%2Fpymapme","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/funnydman%2Fpymapme/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/funnydman%2Fpymapme/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/funnydman%2Fpymapme/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/funnydman","download_url":"https://codeload.github.com/funnydman/pymapme/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/funnydman%2Fpymapme/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262508266,"owners_count":23321978,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["models","nested","pydantic","pydantic-models","transformation"],"created_at":"2024-10-11T07:12:26.758Z","updated_at":"2025-06-28T22:42:47.207Z","avatar_url":"https://github.com/funnydman.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 🗺️ PyMapMe\n\n[![Python 3.13+](https://img.shields.io/badge/python-3.13+-blue.svg)](https://www.python.org/downloads/)\n[![Pydantic 2.0+](https://img.shields.io/badge/pydantic-2.0+-green.svg)](https://pydantic.dev/)\n[![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)\n[![Tests](https://img.shields.io/badge/tests-98%25%20coverage-brightgreen.svg)](https://github.com/funnydman/pymapme)\n\nTransform Pydantic models from one structure to another with declarative field mapping.\n\n✨ **Reshape data between APIs** \n\n🎯 **Flatten nested structures**\n\n🔄 **Aggregate complex models** \n\nAll while maintaining Pydantic's validation and type safety.\n\n---\n\n## 📋 Table of Contents\n\n- [🚀 Quick Start](#-quick-start)\n- [✨ Features](#-features)\n- [📦 Installation](#-installation)\n- [🔧 Requirements](#-requirements)\n- [🛠️ Development](#️-development)\n- [🤝 Contributing](#-contributing)\n- [📄 License](#-license)\n\n---\n\n## 🚀 Quick Start\n\nMap data from a source Pydantic model to a target model with a different structure, using simple field declarations.\n\n### Common Use Case: Third-Party API Integration\nConvert camelCase third-party API responses with nested structures to snake_case Python models:\n\n```python\nfrom pydantic import BaseModel, Field\nfrom pymapme.models.mapping import MappingModel\n\n# Third-party API response models (camelCase with nesting)\nclass ThirdPartyAddress(BaseModel):\n    streetName: str\n    cityName: str\n    zipCode: str\n\nclass ThirdPartyUserProfile(BaseModel):\n    firstName: str\n    lastName: str\n    userEmail: str\n    homeAddress: ThirdPartyAddress\n    isActive: bool\n\n# Your application's Python model (snake_case, flattened)\nclass User(MappingModel):\n    first_name: str = Field(json_schema_extra={\"source\": \"firstName\"})\n    last_name: str = Field(json_schema_extra={\"source\": \"lastName\"})\n    email: str = Field(json_schema_extra={\"source\": \"userEmail\"})\n    street: str = Field(json_schema_extra={\"source\": \"homeAddress.streetName\"})\n    city: str = Field(json_schema_extra={\"source\": \"homeAddress.cityName\"})\n    zip_code: str = Field(json_schema_extra={\"source\": \"homeAddress.zipCode\"})\n    is_active: bool = Field(json_schema_extra={\"source\": \"isActive\"})\n\n# Transform third-party API response to your application model\nthird_party_data = ThirdPartyUserProfile(\n    firstName=\"John\", \n    lastName=\"Doe\", \n    userEmail=\"john@example.com\",\n    homeAddress=ThirdPartyAddress(\n        streetName=\"123 Main St\",\n        cityName=\"New York\", \n        zipCode=\"10001\"\n    ),\n    isActive=True\n)\nuser = User.build_from_model(third_party_data)\n# User(first_name=\"John\", last_name=\"Doe\", email=\"john@example.com\", \n#      street=\"123 Main St\", city=\"New York\", zip_code=\"10001\", is_active=True)\n```\n\n### Basic Structure Mapping\n\n```python\nfrom pydantic import BaseModel, Field\nfrom pymapme.models.mapping import MappingModel\n\n# Source models\nclass PersonalInfo(BaseModel):\n    first_name: str\n    last_name: str\n\nclass JobInfo(BaseModel):\n    title: str\n    company: str\n\nclass UserProfile(BaseModel):\n    personal: PersonalInfo\n    job: JobInfo\n\n# Target model with flattened structure\nclass UserSummary(MappingModel):\n    name: str = Field(json_schema_extra={\"source\": \"personal.first_name\"})\n    title: str = Field(json_schema_extra={\"source\": \"job.title\"})\n\n# Transform\nprofile = UserProfile(\n    personal=PersonalInfo(first_name=\"John\", last_name=\"Smith\"),\n    job=JobInfo(title=\"Developer\", company=\"Acme\")\n)\nsummary = UserSummary.build_from_model(profile)\n# UserSummary(name=\"John\", title=\"Developer\")\n```\n\n## ✨ Features\n\n### 🎯 Nested Field Mapping\nMap deeply nested fields using dot notation:\n\n```python\nfrom pydantic import Field\nfrom pymapme.models.mapping import MappingModel\n\nclass OrderSummary(MappingModel):\n    customer_name: str = Field(json_schema_extra={\"source\": \"customer.profile.name\"})\n    payment_total: float = Field(json_schema_extra={\"source\": \"payment.amount\"})\n    shipping_city: str = Field(json_schema_extra={\"source\": \"shipping.address.city\"})\n```\n\n### 🔧 Custom Transformation Functions\nTransform data using custom functions with access to the source model:\n\n```python\nfrom pydantic import Field\nfrom pymapme.models.mapping import MappingModel\n\nclass UserDisplay(MappingModel):\n    full_name: str = Field(json_schema_extra={\"source_func\": \"_build_full_name\"})\n    \n    @staticmethod\n    def _build_full_name(source_model, default):\n        return f\"{source_model.first_name} {source_model.last_name}\".strip()\n```\n\n### 📊 Context Data Injection\nInject additional data during transformation:\n\n```python\nfrom pydantic import BaseModel, Field\nfrom pymapme.models.mapping import MappingModel\n\nclass User(BaseModel):\n    name: str\n\nclass EnrichedUser(MappingModel):\n    name: str = Field(json_schema_extra={\"source\": \"name\"})\n    is_premium: bool = Field(json_schema_extra={\"source_func\": \"_check_premium\"})\n    \n    @staticmethod\n    def _check_premium(source_model, default, user_tier: str = \"basic\"):\n        return user_tier == \"premium\"\n\n# Usage with context\nuser = User(name=\"John\")\nenriched = EnrichedUser.build_from_model(user, context={\"user_tier\": \"premium\"})\n# EnrichedUser(name=\"John\", is_premium=True)\n```\n\n### ⚡ Automatic Field Mapping\nFields without explicit mapping use the same field name from source:\n\n```python\nfrom pydantic import Field\nfrom pymapme.models.mapping import MappingModel\n\nclass SimpleMapping(MappingModel):\n    # These map automatically by name\n    name: str\n    email: str\n    # This uses explicit mapping\n    user_id: int = Field(json_schema_extra={\"source\": \"id\"})\n```\n\n\n## 📦 Installation\n\n```bash\n# Using pip\npip install pymapme\n\n# Using Poetry\npoetry add pymapme\n```\n\n## 🔧 Requirements\n\n- Python 3.13+\n- Pydantic 2.0+\n\n## 🛠️ Development\n\n### Setup\n```bash\n# Clone the repository\ngit clone https://github.com/funnydman/pymapme.git\ncd pymapme\n\n# Install dependencies\npoetry install\n```\n\n### Commands\n```bash\n# Run tests with coverage\nmake run-unit-tests\n\n# Run static analysis (Ruff + mypy)\nmake run-static-analysis\n\n# Auto-format code\nmake format\n\n# Build package\nmake build-package\n```\n\n## 🤝 Contributing\n\nWe welcome contributions! Please follow these steps:\n\n### 1. Fork and Clone\n```bash\ngit clone https://github.com/funnydman/pymapme.git\ncd pymapme\n```\n\n### 2. Create Feature Branch\n```bash\ngit checkout -b feature/your-feature-name\n```\n\n### 3. Make Changes\n- Write tests for new functionality\n- Follow existing code patterns\n- Update documentation if needed\n\n### 4. Verify Quality\n```bash\n# Run full test suite\nmake run-unit-tests\n\n# Check code quality\nmake run-static-analysis\n\n# Format code\nmake format\n```\n\n### 5. Submit Pull Request\n- Ensure all tests pass\n- Include clear description of changes\n- Reference any related issues\n\n### Development Guidelines\n- **Tests**: Write tests for all new features and bug fixes\n- **Type hints**: Use modern Python type annotations\n- **Documentation**: Update examples and docstrings as needed\n- **Commit messages**: Use clear, descriptive commit messages\n\n## 📄 License\n\nThis project is licensed under the GNU General Public License v3.0 - see the [LICENSE](LICENSE) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffunnydman%2Fpymapme","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffunnydman%2Fpymapme","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffunnydman%2Fpymapme/lists"}