Skip to main content

A lightweight Python library for cleaning, auditing, and validating tabular data.

Project description

Datra

A lightweight Python library for cleaning, auditing, and validating tabular data. It helps data scientists, analysts, and engineers quickly identify data quality issues, clean datasets using simple rules, and generate reports.

Why Datra?

Data quality problems often consume more time than analysis itself. Missing values, duplicate records, inconsistent column names, and invalid entries can silently affect downstream models and business decisions.

Datra provides a simple workflow for understanding and improving dataset quality before analysis or machine learning.

With Datra, you can:

  • Audit datasets to identify quality issues.
  • Clean data using configurable rules.
  • Validate datasets against business rules.
  • Generate JSON and HTML quality reports.
  • Work directly with Pandas DataFrames or CSV and Excel files.

Features

  • Dataset profiling
  • Missing value analysis
  • Duplicate detection
  • Outlier detection (IQR-based)
  • Rule-based data validation
  • Automated data quality scoring
  • Configurable data cleaning
  • Column name standardization
  • Support for Pandas DataFrames
  • CSV and Excel file support
  • JSON and HTML report generation
  • Save cleaned datasets directly to disk

Installation

Install Datra from PyPI:

pip install datra

Or install the latest development version:

git clone https://github.com/raphaelj1/datra.git

cd datra

pip install -e .

Quick Start

Clean a dataset

from datra import clean

cleaned = clean(
    "patients.csv",
    drop_duplicates=True,
    fill_numeric="median",
    fill_categorical="mode",
    standardize_columns=True,
)

Audit a dataset

from datra import Audit

audit = Audit("patients.csv")

print(audit.profile)
print(audit.score)

Validate a dataset

rules = {
    "Age": {
        "min": 0,
        "max": 120,
    },
    "Gender": {
        "allowed": [
            "Male",
            "Female",
        ],
    },
}

report = audit.validate(rules)

Cleaning Data

The clean() function applies one or more cleaning operations to a dataset and returns a new DataFrame. It accepts either a Pandas DataFrame or the path to a CSV or Excel file.

Using keyword arguments

from datra import clean

cleaned = clean(
    "patients.csv",
    drop_duplicates=True,
    fill_numeric="median",
    fill_categorical="mode",
    standardize_columns=True,
)

Using cleaning rules

rules = {
    "duplicates": {
        "drop": True,
    },
    "missing": {
        "numeric": "median",
        "categorical": "mode",
    },
    "columns": {
        "standardize": True,
    },
}

cleaned = clean("patients.csv", rules=rules)

Save the cleaned dataset

clean(
    "patients.csv",
    drop_duplicates=True,
    output="cleaned_patients.xlsx",
)

Auditing Data

Create an audit object to inspect dataset quality.

from datra import Audit

audit = Audit("patients.csv")

Retrieve individual quality checks.

audit.profile

audit.completeness

audit.uniqueness

audit.outliers

audit.score

Or access all audit results at once.

audit.results

Validation

Validate datasets against custom business rules.

rules = {
    "Age": {
        "min": 0,
        "max": 120,
    },
    "Patient ID": {
        "unique": True,
    },
    "Gender": {
        "allowed": [
            "Male",
            "Female",
        ],
    },
}

report = audit.validate(rules)

Validation returns a structured report describing which checks passed, which failed, and the number of violations for each rule.

Reports

Build a data quality report as a Python dictionary.

from datra import Audit

audit = Audit("patients.csv")

report = audit.build_report()

Save the report as JSON.

audit.save_report(
    format="json",
)

Or save it as an HTML report.

audit.save_report(
    format="html",
)

Supported File Formats

Datra supports both Pandas DataFrames and common tabular file formats.

Input Supported
Pandas DataFrame
CSV
Excel (.xlsx)
Excel (.xls)

Report Formats

Format Supported
JSON
HTML
PDF 🚧 Planned

Project Structure

datra/
├── datra/              # Library source code
├── examples/           # Example usage
├── tests/
├── pyproject.toml
├── README.md
└── LICENSE

Roadmap

Planned improvements include:

  • PDF report generation
  • Command-line interface (CLI)
  • Additional cleaning operations
  • Additional validation rules
  • More data quality checks
  • Interactive HTML reports
  • Support for additional file formats

Contributing

Contributions, feature requests, and bug reports are welcome.

If you would like to contribute:

  1. Fork the repository.
  2. Create a new feature branch.
  3. Commit your changes.
  4. Open a pull request.

Please ensure all tests pass before submitting a pull request.

License

This project is licensed under the 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

datra-0.1.0.tar.gz (16.1 kB view details)

Uploaded Source

Built Distribution

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

datra-0.1.0-py3-none-any.whl (14.9 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for datra-0.1.0.tar.gz
Algorithm Hash digest
SHA256 d58439e9fc8a9ca822c16d79b9de05b7a63add24c5dd9169cd8ee4861b75e47a
MD5 8b475381a96ec298ab05d6c7d4b63738
BLAKE2b-256 93f9d1406462e04bb8b8affab8805116b2c7f3b976bec8b2a7108aaed658d84c

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for datra-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9df6678950256fef9204f7ca03800db7c28578efaa0c1f8fd5078f0403c899cd
MD5 fdf8726b856651dfbdfe9f2ac305f46b
BLAKE2b-256 6d95749e86c3fca478b68a05463c6dee51890a38f312b9a16c47c30f1b2b2056

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