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.1.0.tar.gz (19.2 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.1.0-py3-none-any.whl (14.1 kB view details)

Uploaded Python 3

File details

Details for the file csv_surgeon-1.1.0.tar.gz.

File metadata

  • Download URL: csv_surgeon-1.1.0.tar.gz
  • Upload date:
  • Size: 19.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.2

File hashes

Hashes for csv_surgeon-1.1.0.tar.gz
Algorithm Hash digest
SHA256 4d955afa7788a78de330b39603c4f6c29654292a7a7e60c859ee645556b665f1
MD5 e9c32cc2047053b7968767e2d460abf1
BLAKE2b-256 a3c420b465a2895bd8ec43fcc9cc69dbf7e03e6b71e3b7484becade6cabf36c3

See more details on using hashes here.

File details

Details for the file csv_surgeon-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: csv_surgeon-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 14.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.2

File hashes

Hashes for csv_surgeon-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8f2ef43e4685722b2199151da672e6fd0cb64a712e8dcf18d4c6f3bf236a323d
MD5 19a5c82f84675e66498212263e0591fc
BLAKE2b-256 99fbeade16adb569b31f699f4c026e887125ecf61a195c9bfd3e5b7ade9d7901

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