PitchHut logo
Validate dictionaries effortlessly with biggusdictus.
Pitch

biggusdictus is a powerful library designed to simplify the process of validating dictionaries against specified schemas. Easily generate validation schemes for JSON files and ensure data integrity with customizable constraints, making your data validation robust and straightforward.

Description

biggusdictus is a powerful library designed for validating dictionaries, particularly useful for ensuring the integrity of JSON data. This library simplifies the process of generating validation schemes and validating data against predefined structures.

Key Features

  • Flexible Validation: Easily validate dictionaries with a variety of checks, ensuring that the data conforms to expected formats, types, and constraints.
  • Custom Schemes: Users can define their own validation schemes by specifying the required types and conditions for each field within the dictionary.
  • Pedantic Mode: Offers an optional strict validation mode that enforces more detailed constraints to increase the reliability of the data validation process.
  • Dynamic Type Checking: Supports a wide range of data types and allows users to create custom types.

Usage Example

To validate a dictionary using biggusdictus, simply import the library, create a scheme, and define the expected structure of your data. For instance:

from biggusdictus import *

sche = Scheme()

data = {
    "private": False,
    "date": "2025-02-22T00:00:00+0000",
    "id": 24,
    "avg": -24.2,
    "name": "user82224",
    "badges": ["b1", "b2", 24],
    "info": {
        "country": "Brazil",
        "posts": 421
    },
    "comments": [
        { "id": 254, "msg": "!!!!!!" },
        { "id": 254, "msg": "------", "likes": -2 }
    ]
}

sche.dict(
    data,
    ("private", bool),
    ("date", Isodate),
    ("id", uint),
    ("avg", float),
    ("name", str, 1), 
    ("badges", list, (Or, str, uint)), 
    ("info", dict,
        ("country", str),
        ("posts", uint)
    ),
    ("comments", list, (dict,
        ("id", uint),
        ("msg", str),
        (None, "likes", int)
    ))
)

This example demonstrates how to define a validation scheme by specifying the expected fields, their data types, and additional constraints. If the data does not meet the specified conditions, a DictError() will be raised, allowing for efficient error handling during data processing.

Customizing Validation

biggusdictus includes a framework for creating custom validation types and constraints by extending the basic functionality. This allows users to tailor the validation process to fit their specific requirements without compromising on performance or usability.

For comprehensive details about all functionalities and capabilities, refer to the complete documentation provided within the repository.

0 comments

No comments yet.

Sign in to be the first to comment.