Intelligent CSV repair and sanitization for broken data files
Project description
CSV Surgeon
Intelligent CSV repair and sanitization for broken data files
Overview
CSV Surgeon is a CLI tool that automatically detects and repairs broken CSV files with encoding issues, delimiter mismatches, malformed quotes, embedded linebreaks, and structural inconsistencies. Unlike web-based tools or manual approaches, it uses statistical analysis and heuristic algorithms to infer correct file structure, normalize encodings, and reconstruct malformed records while preserving data integrity.
Installation
pip install csv-surgeon
Usage
# Repair broken CSV
csv-surgeon repair broken.csv
# Save to file with encoding
csv-surgeon repair data.csv -o cleaned.csv --encoding utf-8
# Analyze without repair
csv-surgeon analyze messy.csv
# Redact PII
csv-surgeon repair input.csv --delimiter , --sanitize-pii
Features
- Multi-pass encoding detection: Uses chardet with fallback chain (UTF-8, UTF-16, Latin-1, CP1252) and confidence scoring
- Statistical delimiter inference: Tests 4 delimiter types (comma, semicolon, tab, pipe) using coefficient of variation
- Context-aware quote repair: Detects and repairs unclosed quotes using delimiter-aware heuristics
- Embedded linebreak reconstruction: Merges records split across multiple lines using column count consistency
- Header auto-detection: Distinguishes headers from data using type consistency analysis
- PII sanitization: Detects and redacts emails, phone numbers (3 formats), and SSNs using regex patterns
- Detailed reporting: Provides confidence scores (0.0-1.0) for encoding and delimiter detection
- Error handling: Gracefully handles permission errors, empty files, and binary files
How It Works
Uses chardet for encoding detection, statistical analysis for delimiter inference (coefficient of variation), state machine for quote repair, and column count mode for record reconstruction.
Why CSV Surgeon?
Unlike RepairMyCSV (web-only), csvkit (complex), OpenRefine (GUI), or Excel (manual), CSV Surgeon combines automatic detection, CLI automation, and intelligent algorithms in one simple tool.
License
MIT License - Copyright (c) 2026 Intellirim
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 csv_surgeon-1.0.0.tar.gz.
File metadata
- Download URL: csv_surgeon-1.0.0.tar.gz
- Upload date:
- Size: 16.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.25
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f55aed215d3b8337c8710a5953cd3c28ba06c31886f44d97d159da18c325a4dc
|
|
| MD5 |
d9ffb9c30d643d7c4fe13dae15f5276d
|
|
| BLAKE2b-256 |
568427aa0413fb617e643b53f843bedb9bb5ed055efc0a91b3a20240903470bf
|
File details
Details for the file csv_surgeon-1.0.0-py3-none-any.whl.
File metadata
- Download URL: csv_surgeon-1.0.0-py3-none-any.whl
- Upload date:
- Size: 11.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.25
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0ef121c548b2bbff8f315fabe1d9ccec8102a9c039c290bacee5dc318e87a27b
|
|
| MD5 |
2860ff79ec679a263f6afe5d4ac29b9b
|
|
| BLAKE2b-256 |
fc55696714f1237e87ba6543ea12044037f5cb0f3038bb64c682ed27b84560b5
|