Skip to main content

Small CSV utilities: duplicates, row digests, and CLI helpers.

Project description

csvsmith

PyPI version Python versions License

csvsmith is a small collection of CSV utilities.


Current focus:

  • Duplicate value counting (count_duplicates_sorted)
  • Row-level digest creation (add_row_digest)
  • Duplicate-row detection (find_duplicate_rows)
  • Deduplication with full duplicate report (dedupe_with_report)
  • Command-line interface (CLI) for quick operations

Installation

From PyPI (future):

pip install csvsmith

For local development:

git clone https://github.com/YOUR_GITHUB_USERNAME/csvsmith.git
cd csvsmith
python -m venv .venv
source .venv/bin/activate
pip install -e .[dev]

Python API Usage

Count duplicate values

from csvsmith import count_duplicates_sorted

items = ["a", "b", "a", "c", "a", "b"]
print(count_duplicates_sorted(items))
# [('a', 3), ('b', 2)]

Find duplicate rows in a DataFrame

import pandas as pd
from csvsmith import find_duplicate_rows

df = pd.read_csv("input.csv")
dup_rows = find_duplicate_rows(df)
print(dup_rows)

Deduplicate with report

import pandas as pd
from csvsmith import dedupe_with_report

df = pd.read_csv("input.csv")

# Use all columns
deduped, report = dedupe_with_report(df)
deduped.to_csv("deduped.csv", index=False)
report.to_csv("duplicate_report.csv", index=False)

# Use all columns except an ID column
deduped_no_id, report_no_id = dedupe_with_report(df, exclude=["id"])

CLI Usage

csvsmith includes a small command-line interface for duplicate detection and CSV deduplication.

Show duplicate rows

csvsmith row-duplicates input.csv

Save only duplicate rows to a file:

csvsmith row-duplicates input.csv -o duplicates_only.csv

Use only a subset of columns to determine duplicates:

csvsmith row-duplicates input.csv --subset col1 col2 -o dup_rows_subset.csv

Exclude ID column(s) when looking for duplicates:

csvsmith row-duplicates input.csv --exclude id -o dup_rows_no_id.csv

Deduplicate and generate a duplicate report

csvsmith dedupe input.csv   --deduped deduped.csv   --report duplicate_report.csv

Deduplicate using selected columns

csvsmith dedupe input.csv   --subset col1 col2   --deduped deduped_subset.csv   --report duplicate_report_subset.csv

Remove all occurrences of duplicated rows

csvsmith dedupe input.csv   --subset col1   --keep False   --deduped deduped_no_dups.csv   --report duplicate_report_col1.csv

Exclude “id” from duplicate logic:

csvsmith dedupe input.csv   --exclude id   --deduped deduped_no_id.csv   --report duplicate_report_no_id.csv

Philosophy (“csvsmith Manifesto”)

  1. CSVs deserve tools that are simple, predictable, and transparent.
  2. A row has meaning only when its identity is stable and hashable.
  3. Collisions are sin; determinism is virtue.
  4. Let no delimiter sow ambiguity among fields.
  5. Love thy \x1f.
    The unseen separator, the quiet guardian of clean hashes.
    Chosen not for aesthetics, but for truth.
  6. The pipeline should be silent unless something is wrong.
  7. Your data deserves respect — and your tools should help you give it.

For more, see MANIFESTO.md.


License

MIT License.

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

csvsmith-0.1.0.tar.gz (10.7 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.1.0-py3-none-any.whl (9.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: csvsmith-0.1.0.tar.gz
  • Upload date:
  • Size: 10.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.9

File hashes

Hashes for csvsmith-0.1.0.tar.gz
Algorithm Hash digest
SHA256 18f44e2116adebd6a267f222848c8f80ff2baa17ce7bdf49ddf2373599b377df
MD5 5ca3534d60b9a63c40612544a7c9b83c
BLAKE2b-256 76180154517c7f2c605f3298bb51474fd2c5ef703acfbfedf35167b26aa05828

See more details on using hashes here.

File details

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

File metadata

  • Download URL: csvsmith-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 9.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.9

File hashes

Hashes for csvsmith-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 523b9a0e34f12771f69f157dcdfde7aeacc682834d92eceea8fdef34a689aa8e
MD5 ad49fe69b17a29616ee47f9bafd0ae68
BLAKE2b-256 4a3eca6b17deb2ffa33f4491e4905558188c09d086794939c9a9fdd13954e0c2

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