Skip to main content

Intelligent CSV repair and sanitization for broken data files

Project description

CSV Surgeon

Intelligent CSV repair and sanitization for broken data files

License: MIT

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

csv_surgeon-1.0.0.tar.gz (16.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

csv_surgeon-1.0.0-py3-none-any.whl (11.0 kB view details)

Uploaded Python 3

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

Hashes for csv_surgeon-1.0.0.tar.gz
Algorithm Hash digest
SHA256 f55aed215d3b8337c8710a5953cd3c28ba06c31886f44d97d159da18c325a4dc
MD5 d9ffb9c30d643d7c4fe13dae15f5276d
BLAKE2b-256 568427aa0413fb617e643b53f843bedb9bb5ed055efc0a91b3a20240903470bf

See more details on using hashes here.

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

Hashes for csv_surgeon-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0ef121c548b2bbff8f315fabe1d9ccec8102a9c039c290bacee5dc318e87a27b
MD5 2860ff79ec679a263f6afe5d4ac29b9b
BLAKE2b-256 fc55696714f1237e87ba6543ea12044037f5cb0f3038bb64c682ed27b84560b5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page