Skip to main content

Dictionary schema validation

Project description

validdict ✅

Dictionary schema validation for Python.

Installation

pip install validdict

Usage

from validdict import validate, String, Integer, Email, Boolean

data = {
    "name": "John Doe",
    "age": 30,
    "email": "john@example.com",
    "active": True
}

schema = {
    "name": String(min_length=1, max_length=100),
    "age": Integer(min_value=0, max_value=150),
    "email": Email(required=False),
    "active": Boolean(default=True),
}

result = validate(data, schema)

Field Types

Field Description
String String with length/pattern validation
Integer Integer with min/max validation
Float Float with min/max validation
Boolean Boolean value
List_ List with item type validation
Dict_ Nested dictionary
Email Email format validation
Enum_ Value from allowed list

Field Options

# Required (default)
String()

# Optional with default
String(required=False, default="unknown")

# String constraints
String(min_length=1, max_length=100, pattern=r"^[a-z]+$")

# Number constraints
Integer(min_value=0, max_value=100)

# List with item validation
List_(item_type=String(), min_length=1)

# Nested schema
Dict_({
    "street": String(),
    "city": String(),
})

Error Handling

from validdict import validate, ValidationError

try:
    result = validate(data, schema)
except ValidationError as e:
    print(f"Validation failed: {e.message}")
    print(f"At path: {e.path}")

License

MIT

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

pyvaliddict_rj-1.0.0.tar.gz (3.5 kB view details)

Uploaded Source

Built Distribution

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

pyvaliddict_rj-1.0.0-py3-none-any.whl (3.8 kB view details)

Uploaded Python 3

File details

Details for the file pyvaliddict_rj-1.0.0.tar.gz.

File metadata

  • Download URL: pyvaliddict_rj-1.0.0.tar.gz
  • Upload date:
  • Size: 3.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for pyvaliddict_rj-1.0.0.tar.gz
Algorithm Hash digest
SHA256 c14f3de300095f70ad25da2766e025251eed26ff310afe7eafb88d9a138a6a10
MD5 6ea6245688f3e3f3889ea6ed3c75095f
BLAKE2b-256 95e487b86d2c349b3ce69b4fee7e4633ace451a47a31fbbb691cf3987f47601a

See more details on using hashes here.

File details

Details for the file pyvaliddict_rj-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: pyvaliddict_rj-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 3.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for pyvaliddict_rj-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 05d69faebbbddfe8fd51c0d5d7f60832776d8145d0d13ea095065ed65de966ea
MD5 23bbe91189083d913dbe6f964b73fd6e
BLAKE2b-256 8cb532e67ecd3feeb7fdf058d77dc4834b574f0730678f93bceb76bd59c22f09

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