Skip to main content

datacleaner-lite

PyPI version Actions Status Python Versions License

Utilities for inspecting, cleaning and streaming CSV datasets with a small CLI and a simple Python API.


Features

  • Detect CSV delimiter and encoding (gzip + BOM aware)
  • Normalize column names
  • Remove duplicate rows and trim padding
  • Stream large files without loading everything into memory
  • CLI and programmatic API

Installation

Install from PyPI:

pip install datacleaner-lite

Or install from source:

pip install -e .

CLI

The package exposes a datacleaner CLI entry point.

Basic usage:

# Inspect a CSV (detect delimiter, encoding, basic metrics)
datacleaner inspect input.csv

# Clean a CSV, write to output (removes duplicates and trims whitespace)
datacleaner clean input.csv -o cleaned.csv

# Show help
datacleaner --help

Options (examples):

  • inspect <path> — Prints detected delimiter, total rows/cols and sample
  • clean <path> -o <out> — Streams cleaned CSV to <out> (defaults to stdout if not provided)

Use datacleaner --help for a full list of flags and options.


Python API

Import the package and call the high-level helpers:

import datacleaner as dc

# Inspect a file (returns a dict with metrics)
metrics = dc.inspect_csv("data.csv")
print(metrics)

# datacleaner-lite

[![PyPI version](https://img.shields.io/pypi/v/datacleaner-lite.svg)](https://pypi.org/project/datacleaner-lite/)
[![CI status](https://github.com/sergiduran2011-droid/datacleaner-lite/actions/workflows/ci.yml/badge.svg)](https://github.com/sergiduran2011-droid/datacleaner-lite/actions)
[![Python Versions](https://img.shields.io/pypi/pyversions/datacleaner-lite.svg)](https://pypi.org/project/datacleaner-lite/)
[![License](https://img.shields.io/pypi/l/datacleaner-lite.svg)](https://opensource.org/licenses/MIT)

Utilities to inspect, clean and stream CSV datasets. Provides a small CLI
(`datacleaner`) and an ergonomic Python API suitable for pipelines and
batch processing.

---

## Table of contents

- Quickstart
- CLI examples
- Python API
- Development
- Publishing
- Contributing & Support

---

## Quickstart

Install from PyPI:

```bash
pip install datacleaner-lite

Inspect a CSV:

datacleaner inspect data.csv

Clean and write output (supports .gz input/output transparently):

datacleaner clean data.csv -o cleaned.csv

Or use programmatically:

import datacleaner as dc

metrics = dc.inspect_csv("data.csv")
print(dc.generate_report(metrics))

dc.clean_file("data.csv", output_path="cleaned.csv")

CLI

Usage: datacleaner <command> [options]

Common commands:

  • inspect <path> — detects delimiter, encoding, counts rows/cols and shows a small sample
  • clean <path> -o <out> — cleans rows (trim, dedupe) and writes CSV to out (or stdout)

Examples:

# Inspect gzipped CSV with BOM
datacleaner inspect data.csv.gz

# Clean, remove duplicate rows, and compress output
datacleaner clean input.csv -o output.csv.gz

# Clean and stream to stdout (pipe into another tool)
datacleaner clean large.csv | gzip > clean.gz

Options you may find useful (CLI flags):

  • -o, --output : output path (if omitted prints to stdout)
  • --deduplicate/--no-deduplicate : enable/disable deduplication
  • --delimiter : force delimiter detection override (e.g. , or ;)
  • --encoding : force input encoding (use with care; default tries detection)

Run datacleaner <command> --help for per-command options.


Python API

High-level functions (short API reference):

  • inspect_csv(path: str | Path) -> dict — Returns metrics: total_rows, total_cols, sample_rows, delimiter, encoding.
  • clean_file(in_path: str | Path, output_path: Optional[str|Path]=None, deduplicate: bool=True) -> Optional[Path] — Streams cleaned CSV to output_path (or stdout) and returns the output path when given.
  • clean_column_name(name: str) -> str — Normalizes a single column name (strip, lowercase, remove punctuation).
  • clean_column_names(names: Iterable[str]) -> List[str] — Applies clean_column_name to a sequence.
  • detect_delimiter(path: str | Path) -> str — Heuristic delimiter detection with fallback.
  • generate_report(metrics: dict) -> str — Human-readable report string from inspect_csv metrics.

Example (detailed):

from pathlib import Path
import datacleaner as dc

in_file = Path("data.csv.gz")
metrics = dc.inspect_csv(in_file)
print(dc.generate_report(metrics))

out = Path("cleaned.csv.gz")
dc.clean_file(in_file, output_path=out)
print("Wrote:", out)

Notes:

  • clean_file will preserve gzip compression if the output filename ends with .gz.
  • Encoding detection attempts to handle UTF-8 BOM and common encodings; use --encoding or encoding= parameter to override when necessary.

Development

Run tests and linters locally:

python -m venv .venv
source .venv/bin/activate
pip install -e .[dev]
pre-commit install
pre-commit run --all-files
pytest -q

Formatting / style:

  • black .
  • isort --profile black .

Publishing (PyPI) — OIDC (recommended)

This repository includes .github/workflows/publish.yml which builds with python -m build and uses the pypa/gh-action-pypi-publish action. It is configured to request id-token: write so the job can authenticate to PyPI using GitHub's OIDC provider and a Trusted Publisher on PyPI.

Steps to enable Trusted Publisher on PyPI:

  1. Go to https://pypi.org/manage/account/ and under API tokens / Trusted publishers follow the instructions to register this GitHub repository or organization as a trusted publisher.
  2. Ensure the workflow has permissions: id-token: write (already present in the workflow file).
  3. Create a test release on GitHub and use the manual Run workflow button (workflow_dispatch) to trigger publish once configured.

If you prefer using a classic API token (less recommended), create a PYPI_API_TOKEN secret in GitHub and switch the workflow to use it instead.


Contributing & Support

Contributions, bug reports and PRs are welcome. Open an issue with a minimal repro if you find a bug.

For questions or maintenance contact: Sergi Durán sergiduran2011@gmail.com

Please follow the contributor checklist in CONTRIBUTING.md if you add features.


License

MIT — see 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

datacleaner_lite-0.2.1.tar.gz (12.3 kB view details)

Uploaded Source

Built Distribution

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

datacleaner_lite-0.2.1-py3-none-any.whl (8.8 kB view details)

Uploaded Python 3

File details

Details for the file datacleaner_lite-0.2.1.tar.gz.

File metadata

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

File hashes

Hashes for datacleaner_lite-0.2.1.tar.gz
Algorithm Hash digest
SHA256 d24bc61d2e8edb1cb00c71104cabd7b839987b8e78c2a05cb32667fc04729348
MD5 b0c534be521ca9d53c7972b672388343
BLAKE2b-256 ed49a8718b49aac1f10f6412cec01ca32741cecab90cbb173fa782923bac5df1

See more details on using hashes here.

Provenance

The following attestation bundles were made for datacleaner_lite-0.2.1.tar.gz:

Publisher: publish.yml on sergiduran2011-droid/datacleaner-lite

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

File details

Details for the file datacleaner_lite-0.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for datacleaner_lite-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2afd517b3637100fea005dacda2bde59225430a809d8a5c338742264f57f7c83
MD5 e7429dbe02944facbeb50085596c7771
BLAKE2b-256 bd9e972fee9dbc295e52c995caee96e1f5323e59b7f3cb4869255531423598ab

See more details on using hashes here.

Provenance

The following attestation bundles were made for datacleaner_lite-0.2.1-py3-none-any.whl:

Publisher: publish.yml on sergiduran2011-droid/datacleaner-lite

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

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page