Skip to main content

Process and validate JSON and CSV data with ease.

Project description

Data Validator Framework

A Python-based data validation framework for CSV and JSON data. This project provides a unified approach to validate data formats and contents using specialised validators built on a common foundation. The framework is easily extendable and leverages industry-standard libraries such as Pandas, Polars, and Pydantic.


Overview

The Data Validator Framework is designed to simplify and standardise data validation tasks. It consists of:

  • CSV Validator: Validates CSV files using either the Pandas or Polars engine. It checks for issues such as missing data, incorrect data types, invalid date formats, fixed column values, and duplicate entries.
  • JSON Validator: Validates JSON objects against Pydantic models, ensuring the data conforms to the expected schema while providing detailed error messages.
  • Common Validator Base: An abstract BaseValidator class that defines a standard interface and error management for all validators.
  • Custom Errors: A set of custom error classes that offer precise and informative error reporting, helping to identify and resolve data issues efficiently.

Features

  • CSV Validation

    • Supports both Pandas and Polars engines.
    • Reads multiple CSV files concurrently.
    • Validates data types, missing data, date formats, fixed values, and uniqueness constraints.
  • JSON Validation

    • Uses Pydantic for schema validation.
    • Automatically converts JSON keys to strings to ensure compatibility.
    • Aggregates and formats error messages for clarity.
  • Extensible Architecture

    • A unified abstract base class (BaseValidator) that standardises validation methods.
    • Customisable error handling with detailed messages.

Requirements


Installation

  1. Clone the Repository:

    pip install px_processor
    poetry add px_processor
    uv add px_processor
    

--

Usage

CSV Validation Example

from processor import CSVValidator

validator = CSVValidator(
    csv_paths=["data/file1.csv", "data/file2.csv"],
    data_types=["str", "int", "float"],
    column_names=["id", "name", "value"],
    unique_value_columns=["id"],
    columns_with_no_missing_data=["name"],
    missing_data_column_mapping={"value": ["NaN", "None"]},
    valid_column_values={"name": ["Alice", "Bob", "Charlie"]},
    drop_columns=["unused_column"],
    strict_validation=True,
)

validator.validate()

JSON Validation Example

from pydantic import BaseModel
from processor import JSONValidator

class UserModel(BaseModel):
    id: int
    name: str
    email: str

json_data = {
    "id": 123,
    "name": "Alice",
    "email": "alice@example.com"
}

validator = JSONValidator(model=UserModel, input_=json_data)
validator.validate()

--

Project Structure

validator/
├── .gitignore
├── .python-version
├── CHANGELOG.md
├── CONTRIBUTING.md
├── LICENSE
├── pyproject.toml
├── uv.lock
├── requirements.txt
├── README.md
├── src/
    └── validator/
        └── config/
           ├── __init.py__
           └── csv_.py           # Configuration settings for CSV validation.
        ├── __init.py__
        ├── base.py               # Abstract base class for validators.
        ├── errors.py             # Custom error classes for validation.
        ├── README.md
        ├── csv/
           ├── __init.py__
           ├── README.md
           └── main.py           # CSV validation implementation.
        └── json/
           ├── __init.py__
           ├── README.md
           └── main.py          # JSON validation implementation.
        └── tests/
            ├── __init.py__
            ├── config.py           # Test configuration settings.
            |── integration/
            |   ├── __init.py__
            |   ├── test_integration_json.py   # Integration tests for JSON validation.
            |   └── test_integration_csv.py    # Integration tests for CSV validation.
            ├── unit/
            |   ├── __init.py__
            |   ├── test_csv.py     # Unit tests for CSV validation.
            |   └── test_json.py    # Unit tests for JSON validation.
            ├── csvs/               # CSV files for testing.
            └── jsons/              # JSON files for testing.

Contributing

Contributions are welcome! Please adhere to standard code review practices and ensure your contributions are well tested and documented.

Licence

This project is licensed under the MIT License. See the LICENSE file for details.

For developers

To generate requirements.txt

uv export --format requirements.txt --no-emit-project --no-emit-workspace --no-annotate --no-header --no-hashes --no-editable -o requirements.txt

To generate CHANGELOG.md

uv run git-cliff -o CHANGELOG.md

To bump version.

 uv run bump-my-version show-bump

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

px_processor-0.2.4.tar.gz (23.6 kB view details)

Uploaded Source

Built Distribution

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

px_processor-0.2.4-py3-none-any.whl (28.4 kB view details)

Uploaded Python 3

File details

Details for the file px_processor-0.2.4.tar.gz.

File metadata

  • Download URL: px_processor-0.2.4.tar.gz
  • Upload date:
  • Size: 23.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.14

File hashes

Hashes for px_processor-0.2.4.tar.gz
Algorithm Hash digest
SHA256 2e76783ed1d8922b1805f0ddd02fdb77c745c160a81c6c422af3354fe5ec4ea6
MD5 bc3e2ce2c7ba31f7e0c1d881f367df39
BLAKE2b-256 485f7633cfde3d9af470cd2be46fa44ed9facb9b3db99aa09ab20272c71a8209

See more details on using hashes here.

File details

Details for the file px_processor-0.2.4-py3-none-any.whl.

File metadata

File hashes

Hashes for px_processor-0.2.4-py3-none-any.whl
Algorithm Hash digest
SHA256 50e72a1d0a227c7b77e4a4da4b437e9eef078076299cb7e062d81d79ec5cbbe8
MD5 100c34f7152388d2755f6c9e0106efcf
BLAKE2b-256 54b97bb0663321b219d95a3699fd40e416b813aabd31bd0e00b32e1e07164146

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