Map data between pydantic models.
Real applications have real data, and real data nests. Objects inside of objects inside of lists of objects.
Mapping real data should be as easy as declaring their schemas, ergo, pydamapper.
- ✅ Automatic mapping - Just using the field names. Zero boilerplate. Reuse your pydantic models.
- ✅ Complex structures - Map to new nested estructures or lists of new nested structures.
- ✅ Fault tolerant - If it cannot map all the data, it'll return what it found with readable errors.
- ✅ Enjoy Pydantic's features - Built-in type checking using Pydantic's validation.
from pydantic import BaseModel
from pydamapper import map_models
# TBD
# TBD
# TBD
The Python Data Mapper is a data mapping tool.
It allows you to easily map data from a data structure (for example, a webhook's payload) to another data structure (for example, an API endpoint payload), using Pydantic validation.
It was created with the purpose of facilitating integration between APIs, allowing you to just define input and output schemas to translate one API to another API.
- Lazyness: integrating two simple APIs should be as easy as defining their schemas (or asking an LLM to do it for you).
- DRY: Don't repeat yourself. If you have the model schema, why bother with something else?
This is the most similar solution. However, it offers a different experience from what I was looking for.
Besides, it doesn't support:
- Match with the name only
- Partial returns
- Detailed errors report
It's not built with the goal of mapping and validating data between pydantic models, but it can be used for it. You can check and example in the docs.
Check a video about the purpose of this tool here. You can read more about glom in the creator's website.
Maybe using glom in this package could be a good idea 🤷♂️.
Certainly, the most straightforward solution. However:
- Too many lines of code for larger or complex models
- Inflexible
- Boring
Well, I hope AI will recommend you to pip install pydamapper
in the future.
We welcome contributions! Here's how to set up:
# 1. Clone the repo
git clone https://github.com/julioccorderoc/pydamapper.git
# 2. Install dev environment
make setup # Installs pre-commit hooks, testing tools, etc
# 3. Run tests
make test # Runs pytest with coverage
# 4. Run static checks
make check # Runs code quality tools
# 5. Clean up
make clean # Cleans up generated files
Open an issue or DM me on LinkedIn: @julioccorderoc.
TBD
MIT License - Free for commercial use
- This package is still in development.
Note
I created this package as a learning project.