A data transformation library for flattening complex nested structures into tabular formats while preserving hierarchical relationships
Project description
Transmog
Transform nested data into flat tables with a simple, intuitive API.
Overview
Transmog transforms nested JSON data into flat, tabular formats while preserving relationships between parent and child records.
Key Features:
- Simple one-function API with smart defaults
- Multiple output formats (JSON, CSV, Parquet)
- Automatic relationship preservation
- Memory-efficient streaming for large datasets
Quick Start
pip install transmog
import transmog as tm
# Transform nested data into flat tables
result = tm.flatten({"name": "Product", "specs": {"cpu": "i7", "ram": "16GB"}})
print(result.main) # Flattened data: [{'name': 'Product', 'specs_cpu': 'i7', ...}]
# Save in any format
result.save("output.json")
Example
Transform complex nested data into relational tables:
data = {
"user": {"name": "Alice", "email": "alice@example.com"},
"orders": [
{"id": 101, "amount": 99.99},
{"id": 102, "amount": 45.50}
]
}
result = tm.flatten(data, name="customer")
# Main table: [{'user_name': 'Alice', 'user_email': 'alice@...', '_id': '...'}]
# Orders table: [{'id': 101, 'amount': 99.99, '_parent_id': '...'}, ...]
Key Options:
- Custom field separators:
separator="." - Use existing IDs:
id_field="customer_id" - Error handling:
errors="skip" - File processing:
tm.flatten_file("data.json")
Advanced Options
For more control:
result = tm.flatten(
data,
name="products",
# Naming
separator=".", # Use dots: user.name
nested_threshold=3, # Simplify deeply nested names
# IDs
id_field="sku", # Use existing field as ID
parent_id_field="_parent", # Customize parent reference name
add_timestamp=True, # Add timestamp to records
# Arrays
arrays="inline", # Keep arrays as JSON instead of separate tables
# Data handling
preserve_types=True, # Keep original types (don't convert to strings)
skip_null=False, # Include null values
skip_empty=False, # Include empty strings/lists
# Performance
batch_size=5000, # Process in larger batches
low_memory=True, # Optimize for low memory usage
)
Documentation
Complete documentation is available at scottdraper8.github.io/transmog, including:
Contributing
For contribution guidelines, development setup, and coding standards, see the Contributing Guide in the documentation.
License
MIT License
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 transmog-1.1.0.tar.gz.
File metadata
- Download URL: transmog-1.1.0.tar.gz
- Upload date:
- Size: 104.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
be8f213887e54f4f1f4ef1a205150fbb4b6f249ae6d1fba3cfff37e4966ceb6d
|
|
| MD5 |
2b3cb8ddfce0dbe2c70d88a6e700c0b6
|
|
| BLAKE2b-256 |
8b37062352c4b1b3c2447a1758da9855c221fa864b34f0d60b6fb015026fc8aa
|
File details
Details for the file transmog-1.1.0-py3-none-any.whl.
File metadata
- Download URL: transmog-1.1.0-py3-none-any.whl
- Upload date:
- Size: 140.4 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 |
27232e255af2b62f70ee85582340ade16a087500561c92b5fa4e85fc6465816a
|
|
| MD5 |
10fd8d83e7997bb4936288c60739b747
|
|
| BLAKE2b-256 |
b8db73ed6439394b9ac52260f62077ad67ebee9c64f3c47c011459d7d20b1bd2
|