Skip to main content

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

Metadata

Release files for csv-surgeon 1.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for csv-surgeon 1.1.0
File Size Uploaded Provenance
csv_surgeon-1.1.0.tar.gz 19.2 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for csv-surgeon 1.1.0
File Interpreter ABI Platform
csv_surgeon-1.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 33.2 kB

Release files / csv_surgeon-1.1.0.tar.gz

Download URL csv_surgeon-1.1.0.tar.gz
Size 19.2 kB
Tags Source
SHA-256 checksum
How to use checksums
4d955afa7788a78de330b39603c4f6c29654292a7a7e60c859ee645556b665f1
BLAKE2b-256 checksum
How to use checksums
a3c420b465a2895bd8ec43fcc9cc69dbf7e03e6b71e3b7484becade6cabf36c3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.2

Release files / csv_surgeon-1.1.0-py3-none-any.whl

Download URL csv_surgeon-1.1.0-py3-none-any.whl
Size 14.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8f2ef43e4685722b2199151da672e6fd0cb64a712e8dcf18d4c6f3bf236a323d
BLAKE2b-256 checksum
How to use checksums
99fbeade16adb569b31f699f4c026e887125ecf61a195c9bfd3e5b7ade9d7901
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.2

Security for csv-surgeon 1.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page