Skip to main content
PyPI version Supported Python versions License Documentation

Small, focused CSV utilities for common data wrangling tasks.

csvsmith provides a handful of practical tools for working with CSV files, including cleaning numeric values, filtering rows, deduplicating records, classifying files, converting Excel spreadsheets to CSV, moving files by suffix, and finding matches inside CSV content. It also includes a lightweight CSV viewer for quick terminal inspection.

Documentation

Read the full documentation at:

https://csvsmith.readthedocs.io/en/latest/

Features

  • Clean numeric strings into normalized values

  • Filter CSV rows by substring matching

  • Deduplicate row data and generate reports

  • Classify CSV files into folders based on headers/signatures

  • Convert Excel workbooks to CSV

  • Generate sample CSV files for testing and examples

  • View selected CSV rows and columns as a text table

  • Mark rows selected by a knapsack-style capacity fit

  • Move files by suffix

  • Find matching values inside CSV files

  • Concatenate CSV files with identical headers

  • Tokenize repeated CSV values and restore them with a versioned map

  • Use the tools either from Python or from the command line

Installation

Install the package in your environment as usual for your project setup.

Example:

pip install csvsmith

If you are developing locally, install it in editable mode from the project root:

pip install -e .

Quick start

You can use the library from Python:

from csvsmith.utils.clean_numeric import clean_currency_numeric

print(clean_currency_numeric("$1,234.56"))

For command-line usage, use single quotes around values containing $:

csvsmith --help

Command-line usage

The package provides a CLI with several subcommands.

Clean numeric values:

csvsmith clean-numeric "1,234.56" --sep "," --decimal "."

Clean currency-prefixed numeric values:

csvsmith clean-currency-numeric '$1,234.56' --sep "," --decimal "."

Filter rows in a CSV:

csvsmith drop-rows input.csv notes spam --case-insensitive --drop-header

Deduplicate rows:

csvsmith dedupe input.csv -o out.csv --subset id --keep first

Classify CSV files:

csvsmith classify src_dir dst_dir --mode relaxed --match subset --auto --dry-run

Convert Excel to CSV:

csvsmith excel-to-csv input.xlsx

Generate a sample CSV:

csvsmith sample-csv -o sample.csv --rows 16 --seed 42

View a CSV file:

csvsmith view sample.csv --columns date,value --filter value ">" 700 --head 5

Mark rows whose values best fit a capacity:

csvsmith knapsack sample.csv value 2036 -o marked.csv

Move files by suffix:

csvsmith move-files src_dir dst_dir --suffixes .csv,.pdf

Find matches in a CSV:

csvsmith find-matches input.csv target --ignore-case --ignore-whitespace

Concatenate CSV files:

csvsmith strict-concat incoming/ -o combined.csv

Concentrate repeated values and restore them later:

csvsmith concentrate input.csv
csvsmith rehydrate input.dense.csv -m input.dense-map.json -o restored.csv

Dense CSV scope and performance

The dense CSV workflow is intended for spreadsheet-oriented and medium-sized CSV files, roughly in the 100 MB class. Concentration makes two passes over the input and keeps value counts in memory, so memory use depends on the number and size of distinct values in the selected columns.

For substantially larger datasets, especially gigabyte-scale pipelines, a flat CSV plus a separate JSON map is usually the wrong interchange format. Consider a binary columnar format such as Apache Parquet instead.

Dense CSV replaces repeated values with tokens containing a 64-character SHA-256 digest. The complete token includes the csvsmith:sha256: prefix and is therefore 79 ASCII characters. The JSON map also stores each original value.

The workflow can still reduce expensive downstream work even when the files become larger. A consumer can process each mapped value once, store the result against its token, and apply that result to every repeated occurrence during rehydration. The CLI reports this potential repeated-operation reduction among mapped cells.

For example, 937 mapped cell occurrences backed by 82 unique map values imply 855 avoidable repeated operations, or about 91.2%. This is a deduplication ratio for mapped work, not a file-compression ratio or a guarantee of total pipeline savings.

Find matches in a CSV

find_matches_in_csv searches a CSV file for a target value and returns match records containing coordinates and row context information.

Python API:

from csvsmith import find_matches_in_csv

results = find_matches_in_csv("input.csv", "target")

CLI:

csvsmith find-matches input.csv target

Options:

  • --ignore-case: ignore case while matching

  • --ignore-whitespace: ignore whitespace while matching

  • --no-nfkc: disable NFKC normalization

If matches are found, the CLI prints formatted JSON. If no matches are found, it prints a simple message.

Other Python APIs

The package also exposes a few other helper functions and classes from its top-level API.

Numeric and row tools:

from csvsmith import (
    clean_numeric,
    count_duplicates_sorted,
    add_row_digest,
    find_duplicate_rows,
    dedupe_with_report,
    read_csv_rows,
    write_csv_rows,
)

CSV classification and filtering:

from csvsmith import CSVClassifier, DropRowsBySubstring

File and conversion helpers:

from csvsmith import (
    concentrate_csv,
    excel_to_csv,
    move_by_suffix,
    rehydrate_csv,
    save_csv,
    strict_concat_rows,
)

String comparison utilities:

from csvsmith import StringDistance, Relation, Result, analyze_pair

Project structure

The code is organized into two main areas:

  • csvsmith.tools for higher-level CSV workflows

  • csvsmith.utils for reusable utility helpers

Testing

Run the test suite with your preferred Python test runner.

Example:

pytest

License

See the project license for details.

Download files

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

Source Distribution

csvsmith-0.11.0.tar.gz (44.3 kB view details)

Uploaded Source

Built Distribution

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

csvsmith-0.11.0-py3-none-any.whl (36.3 kB view details)

Uploaded Python 3

File details

Details for the file csvsmith-0.11.0.tar.gz.

File metadata

  • Download URL: csvsmith-0.11.0.tar.gz
  • Upload date:
  • Size: 44.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for csvsmith-0.11.0.tar.gz
Algorithm Hash digest
SHA256 d6c8b51041af5bf8814690c4ed351ee43e4e87430152254f58f5807eb0aca896
MD5 fd3037898234fc17b08759d5c609cdc7
BLAKE2b-256 4cfff8df816f648fd9b59da430bdd918196f49750c0a4e04a0a80d1a7f6117be

See more details on using hashes here.

Provenance

The following attestation bundles were made for csvsmith-0.11.0.tar.gz:

Publisher: pypi.yml on yeiichi/csvsmith

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file csvsmith-0.11.0-py3-none-any.whl.

File metadata

  • Download URL: csvsmith-0.11.0-py3-none-any.whl
  • Upload date:
  • Size: 36.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for csvsmith-0.11.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0379183f5febbca34704da17614e24a7a9182e2152a074b0c7333621ae1002e8
MD5 a5363285871eb97a9cf61cd75b088ea6
BLAKE2b-256 f80eee6d61b57f1ff233dcb4ef1560e85a99c8f9ab5dc2c0f58d899490253272

See more details on using hashes here.

Provenance

The following attestation bundles were made for csvsmith-0.11.0-py3-none-any.whl:

Publisher: pypi.yml on yeiichi/csvsmith

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

0.13.0

2 files

0.12.0

2 files

0.11.1

2 files

This release

0.11.0 This release

2 files

0.10.0

2 files

0.9.0

2 files

0.8.0

2 files

0.7.3

2 files

0.7.2

2 files

0.7.1

2 files

0.7.0

2 files

0.6.0

2 files

0.5.0

2 files

0.4.0

2 files

0.2.3

2 files

0.2.2

2 files

0.2.1

2 files

0.2.0

2 files

0.1.1

2 files

0.1.0

2 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