Skip to main content

CSV Refine

CSV Refine is a Python CLI for cleaning, filtering, and normalizing CSV files.

It lets you define exactly how each column should be validated, cleaned, and normalized through a YAML contract. CSV Refine then separates valid and invalid rows and generates reports to assess the overall health of the dataset.

Features

  • Clean and normalize messy CSV data
  • Filter out invalid rows while preserving valid data
  • Detect missing values, duplicates, invalid formats, and rule violations
  • Separate valid and invalid rows into dedicated CSV files
  • Generate JSON and HTML reports to assess CSV data quality

Installation

git clone https://github.com/alexiskuypers/csv-refine.git
cd csv-refine

python3 -m venv .venv
source .venv/bin/activate

pip install -e .

Check the CLI:

csv-refine --help

Quick start

csv-refine \
  --contract examples/01-input/example-contract.yaml \
  --csv examples/01-input/example.csv \
  --mode permissive

By default, generated files are written to output/.

A custom output directory can be provided with --output.

YAML contract

CSV Refine is configured through a YAML contract that defines exactly how each column should be validated and normalized.

A contract can define data types, nullability, uniqueness, validation rules, transformations, delimiter, and encoding.

Example:

columns:
  Transaction ID:
    type: str
    nullable: false
    unique: true
    rules:
      starts_with: "TXN_"

For the complete contract syntax and all supported options, see the contract README.

Validation modes

Permissive

Invalid rows are collected while processing continues.

Strict

Structural, type conversion, nullability, and uniqueness failures can stop processing.

Validation-rule violations still act as row filters.

Outputs

CSV Refine generates:

output/
├── validated_example.csv
├── errors_example.csv
├── report_example.json
└── report_example.html
  • Validated CSV — valid rows with transformations applied
  • Error CSV — invalid rows with their detected errors
  • JSON report — machine-readable summary
  • HTML report — human-readable overview of CSV health

The original CSV is never modified.

Real-world example

The repository includes a 200-row retail dataset containing missing values, invalid categories, malformed identifiers, duplicate values, invalid dates, and conversion errors.

examples/
├── 01-input/
│   ├── example.csv
│   └── example-contract.yaml
└── 02-expected-output/
    ├── validated_example.csv
    ├── errors_example.csv
    ├── report_example.json
    └── report_example.html

Run the example with:

csv-refine \
  --contract examples/01-input/example-contract.yaml \
  --csv examples/01-input/example.csv \
  --mode permissive

Example result:

Total rows:    200
Valid rows:    133
Invalid rows:   67
Total errors:  117

Tests

Run the test suite with:

python3 -m pytest

Stack

Python 3.12+, PyYAML, email-validator, pytest, argparse, pathlib, logging.

Status

Version 1 is functionally complete.

Metadata

Release files for csv-refine 0.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-refine 0.1.0
File Size Uploaded
csv_refine-0.1.0.tar.gz 30.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for csv-refine 0.1.0
File Interpreter ABI Platform
csv_refine-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 54.1 kB

Release files / csv_refine-0.1.0.tar.gz

Download URL csv_refine-0.1.0.tar.gz
Size 30.8 kB
Tags Source
SHA-256 checksum
How to use checksums
5c9cb75127ba97cb25a2cf61139bbaaa18aaf748c1f16a3635bcc858ee62f96e
BLAKE2b-256 checksum
How to use checksums
843de475b94e5919dbc670b943be3aeea743d9829d7d8700c61b2bb840c40827
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Release files / csv_refine-0.1.0-py3-none-any.whl

Download URL csv_refine-0.1.0-py3-none-any.whl
Size 23.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
eec685e96fe9372d8481ce5640efcf4796ab1988c6e0bec0cfef0641bbcd3028
BLAKE2b-256 checksum
How to use checksums
df5dd28edabcaa6adce5385fbc30ccd818a54044938883897ccccc9b155408e4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Release history Release notifications | RSS feed

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

This release

0.1.0 This release

2 release files

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