Safe atomic file writer for Pandas, Polars, NumPy, and other data objects
Project description
๐ Table of Contents
- ๐ฏ Overview
- ๐ 30-Second Quick Start
- ๐ Supported Formats & Libraries
- ๐๏ธ Architecture
- โก Performance Comparison
- ๐ก Real-World Use Cases
- ๐ฏ Core Features
- ๐ง Advanced Usage
- ๐ ๏ธ Installation
- ๐ Documentation & Examples
- ๐ Why Choose Atio?
- ๐ License
๐ฏ Overview
Atio is a Python library that prevents data loss and ensures safe file writing. Through atomic writing, it protects existing data even when errors occur during file writing, and supports various data formats and database connections.
โจ Why Atio?
- ๐ Zero Data Loss: Atomic operations guarantee file integrity
- โก High Performance: Minimal overhead with maximum safety
- ๐ Auto Rollback: Automatic recovery when errors occur
- ๐ Universal Support: Works with Pandas, Polars, NumPy, and more
- ๐ฏ Simple API: Drop-in replacement for existing code
๐ 30-Second Quick Start
pip install atio
import atio
import pandas as pd
# Create sample data
df = pd.DataFrame({
"name": ["Alice", "Bob", "Charlie"],
"age": [25, 30, 35],
"city": ["Seoul", "Busan", "Incheon"]
})
# Safe atomic writing
atio.write(df, "users.parquet", format="parquet")
# โ
File saved safely with atomic operation!
๐ Supported Formats & Libraries
| Format | Pandas | Polars | NumPy | Description |
|---|---|---|---|---|
| CSV | โ | โ | โ | Comma-separated values |
| Parquet | โ | โ | โ | Columnar storage format |
| Excel | โ | โ | โ | Microsoft Excel files |
| JSON | โ | โ | โ | JavaScript Object Notation |
| SQL | โ | โ | โ | SQL database storage |
| Database | โ | โ | โ | Direct database connection |
| NPY/NPZ | โ | โ | โ | NumPy binary formats |
| Pickle | โ | โ | โ | Python serialization |
| HTML | โ | โ | โ | HTML table format |
๐๏ธ Architecture
Atomic Writing Process
graph LR
A[Data Object] --> B[Temp File]
B --> C[Validation]
C --> D[Atomic Replace]
D --> E[Success Flag]
C -->|Error| F[Rollback]
F --> G[Original File Preserved]
style A fill:#e1f5fe
style E fill:#c8e6c9
style F fill:#ffcdd2
style G fill:#c8e6c9
Key Components
- ๐ก๏ธ Atomic Operations: Temporary file โ Validation โ Atomic replacement
- ๐ Rollback Mechanism: Automatic recovery on failure
- ๐ Progress Monitoring: Real-time progress for large files
- ๐ Version Management: Snapshot-based data versioning
- ๐งน Auto Cleanup: Automatic cleanup of temporary files
๐ก Real-World Use Cases
๐ฅ Data Pipeline Protection
# ETL pipeline with automatic rollback
try:
atio.write(processed_data, "final_results.parquet", format="parquet")
print("โ
Pipeline completed successfully")
except Exception as e:
print("โ Pipeline failed, but original data is safe")
# Original file remains untouched
๐งช Machine Learning Experiments
# Version-controlled experiment results
atio.write_snapshot(model_results, "experiment_v1", mode="overwrite")
atio.write_snapshot(improved_results, "experiment_v1", mode="append")
# Rollback to previous version if needed
atio.rollback("experiment_v1", version_id=1)
๐ Large Data Processing
# Progress monitoring for large datasets
atio.write(large_df, "big_data.parquet",
format="parquet",
show_progress=True)
# Shows: โ Writing big_data.parquet... [ 45.2 MB | 12.3 MB/s | 00:15 ]
๐ฏ Core Features
1. Atomic File Writing
# Safe writing with automatic rollback
atio.write(df, "data.parquet", format="parquet")
# Creates: data.parquet + .data.parquet._SUCCESS
2. Database Integration
# Direct database storage
from sqlalchemy import create_engine
engine = create_engine('postgresql://user:pass@localhost/db')
atio.write(df, format="sql", name="users", con=engine, if_exists="replace")
3. Version Management
# Snapshot-based versioning
atio.write_snapshot(df, "my_table", mode="overwrite") # v1
atio.write_snapshot(new_df, "my_table", mode="append") # v2
# Read specific version
df_v1 = atio.read_table("my_table", version=1)
4. Progress Monitoring
# Real-time progress for large files
atio.write(large_df, "data.parquet",
format="parquet",
show_progress=True,
verbose=True)
๐ง Advanced Usage
Multi-Format Support
import polars as pl
import numpy as np
# Polars DataFrame
pl_df = pl.DataFrame({"a": [1, 2, 3], "b": [4, 5, 6]})
atio.write(pl_df, "data.parquet", format="parquet")
# NumPy Arrays
arr = np.random.randn(1000, 100)
atio.write(arr, "array.npy", format="npy")
# Multiple arrays
atio.write({'arr1': arr, 'arr2': arr*2}, "arrays.npz", format="npz")
Error Handling & Recovery
# Automatic rollback on failure
try:
atio.write(df, "data.parquet", format="parquet")
except Exception as e:
print(f"Write failed: {e}")
# Original file is automatically preserved
Performance Monitoring
# Detailed performance analysis
atio.write(df, "data.parquet", format="parquet", verbose=True)
# Output:
# [INFO] Temporary directory created: /tmp/tmp12345
# [INFO] Writer to use: to_parquet (format: parquet)
# [INFO] โ
File writing completed (total time: 0.1234s)
๐ ๏ธ Installation
Basic Installation
pip install atio
With Optional Dependencies
# For Excel support
pip install atio[excel]
# For database support
pip install atio[database]
# For all features
pip install atio[all]
Development Installation
git clone https://github.com/seojaeohcode/atio.git
cd atio
pip install -e .
๐ Documentation & Examples
๐ Documentation
- Complete Documentation - Full API reference
- Quick Start Guide - Get started in minutes
- Advanced Usage - Power user features
๐ฏ Examples
๐ Basic Usage - Simple file operations
import atio
import pandas as pd
# Create sample data
df = pd.DataFrame({
"name": ["Alice", "Bob", "Charlie"],
"age": [25, 30, 35],
"city": ["Seoul", "Busan", "Incheon"]
})
# Safe atomic writing
atio.write(df, "users.parquet", format="parquet")
print("โ
File saved safely!")
# Read back to verify
df_read = pd.read_parquet("users.parquet")
print(df_read)
๐ Progress Monitoring - Large file handling
import atio
import pandas as pd
import numpy as np
# Create large dataset
large_df = pd.DataFrame(np.random.randn(200000, 5), columns=list("ABCDE"))
# Save with progress monitoring
atio.write(large_df, "large_data.parquet",
format="parquet",
show_progress=True)
# Shows: โ Writing large_data.parquet... [ 45.2 MB | 12.3 MB/s | 00:15 ]
๐ Snapshot Management - Version control
import atio
import pandas as pd
# Version 1: Initial data
df_v1 = pd.DataFrame({"id": [1, 2, 3], "value": ["A", "B", "C"]})
atio.write_snapshot(df_v1, "my_table", mode="overwrite")
# Version 2: Append new data
df_v2 = pd.DataFrame({"score": [95, 87, 92]})
atio.write_snapshot(df_v2, "my_table", mode="append")
# Read specific version
df_latest = atio.read_table("my_table") # Latest version
df_v1 = atio.read_table("my_table", version=1) # Version 1
โก Performance Testing - Benchmarking
import atio
import pandas as pd
import time
# Performance comparison
df = pd.DataFrame(np.random.randn(100000, 10))
# Standard pandas
start = time.time()
df.to_parquet("standard.parquet")
pandas_time = time.time() - start
# Atio with safety
start = time.time()
atio.write(df, "safe.parquet", format="parquet", verbose=True)
atio_time = time.time() - start
print(f"Pandas: {pandas_time:.3f}s")
print(f"Atio: {atio_time:.3f}s")
print(f"Safety overhead: {((atio_time/pandas_time - 1) * 100):.1f}%")
๐งช Test Scenarios
โจ๏ธ Keyboard Interrupt - Ctrl+C safety
# test_interrupt.py
import atio
import pandas as pd
import numpy as np
print("Creating large dataset...")
df = pd.DataFrame(np.random.randn(1000000, 10))
print("Starting write operation...")
print("Press Ctrl+C to test interrupt safety!")
try:
atio.write(df, "test_interrupt.parquet",
format="parquet",
show_progress=True)
print("โ
Write completed successfully!")
except KeyboardInterrupt:
print("โ Interrupted by user!")
print("๐ Checking file safety...")
import os
if os.path.exists("test_interrupt.parquet"):
print("โ ๏ธ File exists but may be corrupted")
else:
print("โ
No corrupted file left behind!")
๐พ Out of Memory - Memory failure handling
# test_oom.py
import atio
import pandas as pd
import numpy as np
def simulate_oom():
print("Creating extremely large dataset...")
# This will likely cause OOM
huge_df = pd.DataFrame(np.random.randn(10000000, 100))
print("Attempting to save...")
try:
atio.write(huge_df, "huge_data.parquet", format="parquet")
print("โ
Successfully saved!")
except MemoryError:
print("โ Out of Memory error!")
print("โ
But original file is safe!")
except Exception as e:
print(f"โ Error: {e}")
print("โ
Atio protected your data!")
# Run the test
simulate_oom()
๐ CI/CD Pipeline - Automated deployment safety
# ci_pipeline.py
import atio
import pandas as pd
import os
def deploy_artifacts():
"""Simulate CI/CD pipeline deployment"""
# Generate deployment artifacts
config = pd.DataFrame({
"service": ["api", "web", "db"],
"version": ["v1.2.3", "v1.2.3", "v1.2.3"],
"status": ["ready", "ready", "ready"]
})
metrics = pd.DataFrame({
"metric": ["cpu", "memory", "disk"],
"value": [75.5, 68.2, 45.1],
"unit": ["%", "%", "%"]
})
print("๐ Starting deployment...")
try:
# Atomic deployment - either all succeed or all fail
atio.write(config, "deployment_config.json", format="json")
atio.write(metrics, "deployment_metrics.parquet", format="parquet")
# Create success marker
atio.write(pd.DataFrame({"status": ["deployed"]}),
"deployment_success.parquet", format="parquet")
print("โ
Deployment completed successfully!")
return True
except Exception as e:
print(f"โ Deployment failed: {e}")
print("๐ Rolling back...")
# Clean up any partial files
for file in ["deployment_config.json", "deployment_metrics.parquet"]:
if os.path.exists(file):
os.remove(file)
print("โ
Rollback completed - system is clean!")
return False
# Test the pipeline
deploy_artifacts()
๐ Why Choose Atio?
โ Data Safety First
- Zero data loss even during system failures
- Automatic rollback on any error
- File integrity guaranteed by atomic operations
โก Performance Optimized
- Minimal overhead (1.1-1.2x vs native libraries)
- Progress monitoring for large files
- Memory efficient processing
๐ง Developer Friendly
- Drop-in replacement for existing code
- Simple API with powerful features
- Comprehensive documentation and examples
๐ Universal Compatibility
- Multiple data formats (CSV, Parquet, Excel, JSON, etc.)
- Multiple libraries (Pandas, Polars, NumPy)
- Database integration (SQL, NoSQL)
๐ License
This project is distributed under the Apache 2.0 License. See the LICENSE file for details.
Project details
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 atio-3.1.0.tar.gz.
File metadata
- Download URL: atio-3.1.0.tar.gz
- Upload date:
- Size: 49.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
705a83faf459d571e03013883ade50619139d1ecb888fc14193b15cf5921494f
|
|
| MD5 |
8b6ee16bc3a6718a3a5c7353625fd18d
|
|
| BLAKE2b-256 |
b502fc51ea72d046d11bc56f41a6ef0a9d6d01c7d9966ffec82fd53d99847154
|
File details
Details for the file atio-3.1.0-py3-none-any.whl.
File metadata
- Download URL: atio-3.1.0-py3-none-any.whl
- Upload date:
- Size: 34.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2cdc2ee846587954dc8022965423fbd571e085e1c1fd8425641312965c586700
|
|
| MD5 |
67de26219f23655b204364858caa713e
|
|
| BLAKE2b-256 |
bc96b6085a3c14464ed6b82b53d7ed9717f8f5b6e1691639de1dcedadce75407
|