Uma biblioteca C++ para mapeamento e transformação de dados
Project description
Mapper Lib
Uma biblioteca Python de alta performance para mapeamento e transformação de dados, construída com extensões C++ para máxima eficiência.
📋 Descrição
O Mapper Lib é uma biblioteca especializada em transformar e mapear estruturas de dados JSON complexas. Ela oferece funcionalidades para:
- Flattening: Converter dicionários aninhados em estruturas planas
- Field Mapping: Mapear campos entre diferentes formatos usando configurações JSON
- High Performance: Implementação em C++ para operações rápidas de transformação de dados
🚀 Características
- ⚡ Alta Performance: Implementação em C++ com bindings Python
- 🔧 Configurável: Mapeamento baseado em arquivos JSON de configuração
- 🐍 Python Native: API simples e intuitiva para Python
- 🎯 Flexível: Suporte a separadores customizáveis e chaves pai
- 🏗️ Cross-Platform: Suporte para Windows e Linux
📦 Instalação
Pré-requisitos
- Python 3.7+
- Compilador C++ com suporte a C++17
- pybind11
Instalação via pip
pip install -r requirements.txt
pip install -e .
Instalação manual
# Clone o repositório
git clone https://github.com/compre-sua-peca/csp_mapper.git
cd csp_mapper
# Instale as dependências
pip install -r requirements.txt
# Compile e instale
python setup.py build_ext --inplace
python setup.py install
💻 Exemplos de Uso
📝 Como Funciona a Configuração
A biblioteca lê arquivos JSON de configuração do sistema de arquivos. O arquivo deve conter um dicionário onde cada chave representa um "trigger" (gatilho) que define como mapear os campos.
Estrutura típica do arquivo de configuração:
{
"trigger_1": {
"campo_saida_1": "caminho.campo.entrada.1",
"campo_saida_2": "caminho.campo.entrada.2"
},
"trigger_2": {
"outro_campo": "outro.caminho.campo"
}
}
Exemplo 1: Mapeamento Básico
Primeiro, crie o arquivo de configuração mapping_config.json:
{
"user_mapping": {
"nome": "user.personal.name",
"idade": "user.personal.age",
"endereco": "user.address.street",
"cidade": "user.address.city",
"pedido_id": "order.id",
"valor_total": "order.total"
}
}
Depois, use o Python:
from mapper import mapper
# Criar instância do mapper
mapper_instance = mapper(sep=".", parent_key="data")
# Dados de entrada aninhados
input_data = {
"user": {
"personal": {
"name": "João Silva",
"age": 30
},
"address": {
"street": "Rua das Flores",
"city": "São Paulo"
}
},
"order": {
"id": "12345",
"total": 99.99
}
}
# Mapeamento usando arquivo de configuração
result = mapper_instance.map_dic(
input_dict=input_data,
config_path="mapping_config.json",
trigger="user_mapping"
)
print(result)
Exemplo 2: Mapeamento com Arquivo de Configuração
arquivo_config.json:
{
"user_mapping": {
"nome_completo": "user.personal.name",
"idade_usuario": "user.personal.age",
"endereco_completo": "user.address.street",
"cidade_usuario": "user.address.city"
},
"order_mapping": {
"id_pedido": "order.id",
"valor": "order.total"
}
}
Python:
# Mapeamento usando arquivo de configuração
result = mapper_instance.map_dic(
input_dict=input_data,
config_path="arquivo_config.json",
trigger="user_mapping"
)
print(result)
Saída:
{
"nome_completo": "João Silva",
"idade_usuario": 30,
"endereco_completo": "Rua das Flores",
"cidade_usuario": "São Paulo"
}
Exemplo 3: Mapeamento sem Trigger (Configuração Completa)
# Mapeamento usando toda a configuração (sem trigger específico)
result = mapper_instance.map_dic(
input_dict=input_data,
config_path="arquivo_config.json"
# trigger=None (padrão)
)
print(result)
Saída:
{
"user_mapping": {
"nome_completo": "João Silva",
"idade_usuario": 30,
"endereco_completo": "Rua das Flores",
"cidade_usuario": "São Paulo"
},
"order_mapping": {
"id_pedido": "12345",
"valor": 99.99
}
}
Exemplo 4: Diferentes Separadores
# Usar ponto como separador
mapper_dot = mapper(sep=".", parent_key="")
result_dot = mapper_dot.map_dic(input_data, "config.json", "user_mapping")
# Usar underscore como separador
mapper_underscore = mapper(sep="_", parent_key="")
result_underscore = mapper_underscore.map_dic(input_data, "config.json", "user_mapping")
# Usar barra como separador
mapper_bar = mapper(sep="/", parent_key="")
result_bar = mapper_bar.map_dic(input_data, "config.json", "user_mapping")
print("Resultado com ponto:", result_dot)
print("Resultado com underscore:", result_underscore)
print("Resultado com barra:", result_bar)
Exemplo 5: Mapeamento com Chave Pai
# Mapper com chave pai "api_data"
mapper_with_parent = mapper(sep=".", parent_key="api_data")
result_with_parent = mapper_with_parent.map_dic(input_data, "config.json", "user_mapping")
print("Resultado com chave pai 'api_data':")
print(result_with_parent)
🔧 API Reference
Classe mapper
Construtor
mapper(sep: str = "|", parent_key: str = "")
Parâmetros:
sep: Separador para concatenar chaves aninhadas (padrão: "|")parent_key: Chave pai para prefixar todas as chaves (padrão: "")
Métodos
map_dic(input_dict: dict, config_path: str, trigger: str = None) -> dict
Método principal que combina flattening e mapeamento de campos.
Parâmetros:
input_dict: Dicionário de entrada a ser mapeadoconfig_path: Caminho para o arquivo JSON de configuraçãotrigger: Chave específica na configuração a ser usada (opcional)
Retorna:
- Dicionário com dados mapeados conforme a configuração
Nota: Este método internamente utiliza os métodos privados _flatten_dict() e _mapping_fields() para realizar o processamento, mas o usuário só precisa conhecer este método público.
📁 Estrutura do Projeto
mapper-lib/
├── mapper/ # Módulo principal
│ ├── __init__.py # Inicializador do módulo
│ ├── main.cpp # Implementação principal em C++
│ ├── mapping_fields.cpp # Lógica de mapeamento de campos
│ ├── flattener.cpp # Lógica de flattening
│ └── includes/ # Headers específicos por plataforma
├── setup.py # Configuração de build
├── pyproject.toml # Configuração do projeto
├── requirements.txt # Dependências Python
└── main.py # Interface Python principal
🛠️ Desenvolvimento
Compilação
# Compilar extensões C++
python setup.py build_ext --inplace
# Instalar em modo desenvolvimento
pip install -e .
Testes
# Executar testes (quando implementados)
python -m pytest tests/
📄 Licença
Este projeto está licenciado sob a Licença MIT - veja o arquivo LICENSE para detalhes.
👥 Contribuição
Contribuições são bem-vindas! Por favor, sinta-se à vontade para:
- Fazer fork do projeto
- Criar uma branch para sua feature (
git checkout -b feature/AmazingFeature) - Commit suas mudanças (
git commit -m 'Add some AmazingFeature') - Push para a branch (
git push origin feature/AmazingFeature) - Abrir um Pull Request
📞 Suporte
Para suporte e dúvidas:
- Autor: Gustavo de Oliveira
- Email: devops15@compresuapeca.com.br
- Repositório: https://github.com/compre-sua-peca/csp_mapper
🔄 Histórico de Versões
- v1.0.2 - Versão atual com suporte cross-platform
- v1.0.1 - Melhorias de performance
- v1.0.0 - Lançamento inicial
⭐ Se este projeto foi útil para você, considere dar uma estrela no repositório!
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mapper_lib-1.0.2-cp314-cp314t-musllinux_1_2_x86_64.whl.
File metadata
- Download URL: mapper_lib-1.0.2-cp314-cp314t-musllinux_1_2_x86_64.whl
- Upload date:
- Size: 1.5 MB
- Tags: CPython 3.14t, musllinux: musl 1.2+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2a1cc6aa87476938381775a41f06cccc205c53d8616ab61f4b45ba90b77a0267
|
|
| MD5 |
cdcfdf15f536bf69e3713342ab76dc96
|
|
| BLAKE2b-256 |
d3dd2e9c36ce817e023872e728545726a88a38602bd5694570c27da688b3ae16
|
File details
Details for the file mapper_lib-1.0.2-cp314-cp314t-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.
File metadata
- Download URL: mapper_lib-1.0.2-cp314-cp314t-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 478.0 kB
- Tags: CPython 3.14t, manylinux: glibc 2.24+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
177a63ca8568929e94b376116489dd98f0b9a2ad9e47383ac9b45b29d73930f1
|
|
| MD5 |
64f785b35f12d840f73a098a8ebfaa5c
|
|
| BLAKE2b-256 |
20ef4ab654328f138b2d67320eabad0425b70879559b7a73bfb21d062367e3bb
|
File details
Details for the file mapper_lib-1.0.2-cp314-cp314-musllinux_1_2_x86_64.whl.
File metadata
- Download URL: mapper_lib-1.0.2-cp314-cp314-musllinux_1_2_x86_64.whl
- Upload date:
- Size: 1.5 MB
- Tags: CPython 3.14, musllinux: musl 1.2+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
da2d0e684e35cdee1f4510be367768bf6280f38c3946a99e74a1f60a93bb5a1a
|
|
| MD5 |
2b68fa01208bb707e24ce17b11c0fb14
|
|
| BLAKE2b-256 |
13b4edd04928816352b4c9b09b1303564b7cde9a2a47b57cb3106f6fb634360f
|
File details
Details for the file mapper_lib-1.0.2-cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.
File metadata
- Download URL: mapper_lib-1.0.2-cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 475.4 kB
- Tags: CPython 3.14, manylinux: glibc 2.24+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e3acfd7bd3ce0f8aeb20db20e05fb135c54cacaf1d0027a1512292ee64acfde0
|
|
| MD5 |
20ed70a4cdd02800bd931a12f6af4035
|
|
| BLAKE2b-256 |
f4e2a5eab2abcee1564a73d1f51000f8439d87273f01a340f3aa8e775a8ff456
|
File details
Details for the file mapper_lib-1.0.2-cp313-cp313-musllinux_1_2_x86_64.whl.
File metadata
- Download URL: mapper_lib-1.0.2-cp313-cp313-musllinux_1_2_x86_64.whl
- Upload date:
- Size: 1.5 MB
- Tags: CPython 3.13, musllinux: musl 1.2+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2cd31806ecd5db63949441f73802d7a5ba6ad358d117d3b3493a38139ebfc670
|
|
| MD5 |
ec3e1932c76a48fe46f479e5b85d0141
|
|
| BLAKE2b-256 |
ca02a59daa20c8dc7d4aa025d192ca5685729ae621d7b74579b874f3466b57b0
|
File details
Details for the file mapper_lib-1.0.2-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.
File metadata
- Download URL: mapper_lib-1.0.2-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 475.3 kB
- Tags: CPython 3.13, manylinux: glibc 2.24+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b4317baa1cb85479c356b3798d322806f57884fa47a07f1a24f85b4b0c321a5e
|
|
| MD5 |
73adb00dc4103c2859f250d59b4fb021
|
|
| BLAKE2b-256 |
4b7175a5108d9a059d74939bdbed1488b6c118c3ec98326ec76919a9378e4bdf
|
File details
Details for the file mapper_lib-1.0.2-cp312-cp312-win_amd64.whl.
File metadata
- Download URL: mapper_lib-1.0.2-cp312-cp312-win_amd64.whl
- Upload date:
- Size: 41.9 kB
- Tags: CPython 3.12, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6f1b92e655148d440098e27d6fe5fad70f33e48cbf1806526a3739d5585777bc
|
|
| MD5 |
d6b3f526740821a2b2f9efe9ea2e362d
|
|
| BLAKE2b-256 |
430d187abcd65ee85f7afac64e9ef87837c7989352b807917410ece14782fb35
|
File details
Details for the file mapper_lib-1.0.2-cp312-cp312-musllinux_1_2_x86_64.whl.
File metadata
- Download URL: mapper_lib-1.0.2-cp312-cp312-musllinux_1_2_x86_64.whl
- Upload date:
- Size: 1.5 MB
- Tags: CPython 3.12, musllinux: musl 1.2+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e3f57696f8285745fcc4669d7dd3ca1503a7948c0dabb58c76ce6a8835e3f1c7
|
|
| MD5 |
f3ed2a300a9fd39ced2e6add31e7df8c
|
|
| BLAKE2b-256 |
e525a3d60fd40e7ed140a48439312fdf3d97dca4cb2e66315ebac1b09b56d037
|
File details
Details for the file mapper_lib-1.0.2-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.
File metadata
- Download URL: mapper_lib-1.0.2-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 475.3 kB
- Tags: CPython 3.12, manylinux: glibc 2.24+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b3ca3ffe7388ac3af21d3dbd12471d0156ea910fa28e6e123549a6e07c6627e7
|
|
| MD5 |
57ed1597484543d00f42a6ec1778c33f
|
|
| BLAKE2b-256 |
16ee1e9fd287c2e5df6c63e9e88e157d360e299c19bc66a3b9e9b16e0f716e32
|
File details
Details for the file mapper_lib-1.0.2-cp311-cp311-musllinux_1_2_x86_64.whl.
File metadata
- Download URL: mapper_lib-1.0.2-cp311-cp311-musllinux_1_2_x86_64.whl
- Upload date:
- Size: 1.5 MB
- Tags: CPython 3.11, musllinux: musl 1.2+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1bad8e46af4a5148f9bd4eb4288f264a0d940b3d85578dd792209acd35949b41
|
|
| MD5 |
af53f026e0d23872a399d426be568431
|
|
| BLAKE2b-256 |
ac715be448dbc895a0c5c80b8d453f5fc68160fe10d1bb1d573c2661c41b158a
|
File details
Details for the file mapper_lib-1.0.2-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.
File metadata
- Download URL: mapper_lib-1.0.2-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 474.4 kB
- Tags: CPython 3.11, manylinux: glibc 2.24+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4b318b75b5c885f53fb59ca7c55dda62ebc4aac37c3e0e243db4dee769f49a8f
|
|
| MD5 |
593870efd61eb9f1441ff9949eff132f
|
|
| BLAKE2b-256 |
5a7ccfc8b8a42f677f5d81f9caa4d37583235aa0dfc2b5103267ad6c943fdd44
|
File details
Details for the file mapper_lib-1.0.2-cp310-cp310-musllinux_1_2_x86_64.whl.
File metadata
- Download URL: mapper_lib-1.0.2-cp310-cp310-musllinux_1_2_x86_64.whl
- Upload date:
- Size: 1.5 MB
- Tags: CPython 3.10, musllinux: musl 1.2+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9a7b2db67d569c720ca0b2e2a7b3e7bc527157a59ce33f21e489d7dacf0c7f06
|
|
| MD5 |
5fd758cea7fe7053bd3ac0d1d66e68ce
|
|
| BLAKE2b-256 |
d488bf442c7de52489bdbeb18f6df807af4f23bf38bbf56be9bcd51437f90eb0
|
File details
Details for the file mapper_lib-1.0.2-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.
File metadata
- Download URL: mapper_lib-1.0.2-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 474.2 kB
- Tags: CPython 3.10, manylinux: glibc 2.24+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e8aa660fe7932c03d6c356e9df7493cfe5d144b7d1c75bb26c7f91ffe6783c46
|
|
| MD5 |
b4664ad5c42b57df70f070ca0a461542
|
|
| BLAKE2b-256 |
48425e63a633a441a02af936c5b50e30a312dde9d03328dffddbc81a07b79ebb
|
File details
Details for the file mapper_lib-1.0.2-cp39-cp39-musllinux_1_2_x86_64.whl.
File metadata
- Download URL: mapper_lib-1.0.2-cp39-cp39-musllinux_1_2_x86_64.whl
- Upload date:
- Size: 1.5 MB
- Tags: CPython 3.9, musllinux: musl 1.2+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
40ec1f18f12dbf92f1ac28cc215d52c5f77471ba531d40ef99b2cea6be6293b5
|
|
| MD5 |
7b208721c57c61c0bea0579d8100d5da
|
|
| BLAKE2b-256 |
c8b8bfe1b90744ae448311e6fb4df0402b435c399be4ff084e5950c04365b9d3
|
File details
Details for the file mapper_lib-1.0.2-cp39-cp39-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.
File metadata
- Download URL: mapper_lib-1.0.2-cp39-cp39-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 473.5 kB
- Tags: CPython 3.9, manylinux: glibc 2.24+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
91a365e1e432ca892924b40094335dbb1d1e3429c881a74b0a37a25f0ffac651
|
|
| MD5 |
7024e924da9db104d881d659a103d458
|
|
| BLAKE2b-256 |
9c9e37ed94fc9139b2a86ac7eec1b9282c3dc000a3c54b22c7d37e70c3cf326c
|
File details
Details for the file mapper_lib-1.0.2-cp38-cp38-musllinux_1_2_x86_64.whl.
File metadata
- Download URL: mapper_lib-1.0.2-cp38-cp38-musllinux_1_2_x86_64.whl
- Upload date:
- Size: 1.5 MB
- Tags: CPython 3.8, musllinux: musl 1.2+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e06d3f56875733a6e136c48dd0ed07125a723166436a052de99628214bddb1a7
|
|
| MD5 |
113bea419961fcb121ab719bd7a0136f
|
|
| BLAKE2b-256 |
167ab5c8d927dfdf2d610b4675c61d337d968ab3667b4969c8b2bd8a6f415eff
|
File details
Details for the file mapper_lib-1.0.2-cp38-cp38-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.
File metadata
- Download URL: mapper_lib-1.0.2-cp38-cp38-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 472.4 kB
- Tags: CPython 3.8, manylinux: glibc 2.24+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ec06ab49ab88d683245bfc0f9baca2a6df30a54ec23126891a2d2777f5b7cc21
|
|
| MD5 |
563d9a0685d6ab8832d8cc009e8c32b7
|
|
| BLAKE2b-256 |
30e41b1d5d5e7e39a7332d06ff4230a74e28ab24ce04de4c5d262ccc07efc3e2
|