A data matching and canonicalization library with multipl database connector support
Project description
CanonMap
A powerful data matching and canonicalization library with MySQL connector support.
Features
- Data Matching: Advanced algorithms for fuzzy string matching and record linkage
- MySQL Integration: Seamless connection and management of MySQL databases
- Canonicalization: Standardize and normalize data across different formats
- Rich Logging: Beautiful console output with structured logging
- FastAPI Support: Optional FastAPI integration for web services
Installation
pip install canonmap
For development dependencies:
pip install canonmap[dev]
For FastAPI support:
pip install canonmap[fastapi]
Quick Start
Command Line Interface
CanonMap provides a CLI tool for quick project setup:
# Create a new API project (default name: app)
cm create-api
# Create a new API project with custom name
cm create-api --name my-api
# Create a new API project with spaces (will be normalized)
cm create-api --name "My API"
The CLI will automatically:
- Normalize directory names to follow Python conventions
- Auto-increment names if the directory already exists (app, app-2, app-3, etc.)
- Copy and customize the example API template
- Replace all references from "app" to your chosen name
- Install required dependencies (fastapi, uvicorn, python-dotenv)
Basic Usage
from canonmap import make_console_handler
from canonmap.connectors.mysql_connector import MySQLConnector
# Set up logging
make_console_handler(set_root=True)
# Create a MySQL connector
connector = MySQLConnector(
host="localhost",
port=3306,
user="your_user",
password="your_password",
database="your_database"
)
# Use the connector for data operations
# ... your data matching and canonicalization code
Data Matching Example
from canonmap.connectors.mysql_connector.matching import Matcher
# Initialize matcher
matcher = Matcher()
# Perform fuzzy matching
matches = matcher.find_matches(
source_data=source_records,
target_data=target_records,
fields_to_match=["name", "address"],
threshold=0.8
)
Table Management with Primary Key Support
CanonMap supports creating tables from data with intelligent primary key handling:
import pandas as pd
from canonmap.connectors.mysql_connector import MySQLConnector, TableManager
from canonmap.connectors.mysql_connector.managers.table_manager.validators.requests import CreateTableRequest
from canonmap.connectors.mysql_connector.managers.database_manager.validators.models import Database
from canonmap.connectors.mysql_connector.validators.models import IfExists
# Create connector and table manager
connector = MySQLConnector(config)
table_manager = TableManager(connector)
# Example 1: Create table with user-specified primary key (if valid)
data = pd.DataFrame({
'user_id': [1001, 1002, 1003, 1004, 1005], # Unique values
'name': ['Alice', 'Bob', 'Charlie', 'David', 'Eve'],
'email': ['alice@test.com', 'bob@test.com', 'charlie@test.com', 'david@test.com', 'eve@test.com']
})
request = CreateTableRequest(
database=Database(name="my_database"),
name="users",
data=data,
primary_key_field="user_id", # Will be validated for uniqueness
if_exists=IfExists.REPLACE
)
result = table_manager.create_table(request)
# Result: Table created with 'user_id' as PRIMARY KEY
Primary Key Validation Features:
- Automatic Validation: The system validates that the specified field is unique and contains no null values
- Smart Fallback: If validation fails, automatically falls back to auto-increment
idcolumn - Logging: Clear log messages inform you about validation results and fallback decisions
- Multiple Data Sources: Works with DataFrames, CSV files, lists of dictionaries, and more
Validation Rules:
- Field must exist in the data
- Field must contain no null/empty values
- Field must have unique values across all rows
- If any rule is violated, falls back to auto-increment
idPRIMARY KEY
Documentation
For detailed documentation, visit the project homepage.
Development
Setup
- Clone the repository:
git clone https://github.com/yourusername/canonmap.git
cd canonmap
- Install development dependencies:
pip install -e ".[dev]"
- Run tests:
pytest
Code Quality
This project uses several tools to maintain code quality:
- Black: Code formatting
- isort: Import sorting
- flake8: Linting
- mypy: Type checking
- pytest: Testing
Run all quality checks:
black src/ tests/
isort src/ tests/
flake8 src/ tests/
mypy src/
pytest
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Ensure all tests pass
- Submit a pull request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Changelog
See CHANGELOG.md for a list of changes and version history.
Support
- Issues: GitHub Issues
- Documentation: Project README
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
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 canonmap-0.4.30.tar.gz.
File metadata
- Download URL: canonmap-0.4.30.tar.gz
- Upload date:
- Size: 46.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
162aba5d9d7ce2b858f9b257a79ad1faab19fafa986dee859ae8e95e025fb6dd
|
|
| MD5 |
f883a410cfb9d2c4c3f683a845332d49
|
|
| BLAKE2b-256 |
b41adbf687512cb4c20a4f1cc3ab39bda52b2bfc2f462566c2a915c252a7069d
|
File details
Details for the file canonmap-0.4.30-py3-none-any.whl.
File metadata
- Download URL: canonmap-0.4.30-py3-none-any.whl
- Upload date:
- Size: 67.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
965cc2594ec0610dd0f137ba8a88482ceee222d11b355f75d75c9523faf4614f
|
|
| MD5 |
fb7ca6e47a34d9c0db947f186bfc7f76
|
|
| BLAKE2b-256 |
6356704ce041dca29e93ce625f167f1794731e05e609a0b112874eaa8fb8fcc8
|