Skip to main content

Custom field validation

Project description

PyValidX

PyPI version Python versions PyPI - Status License: MIT

Custom field validation for Python with Pydantic

PyValidX is a powerful and flexible validation library built on top of Pydantic that provides a rich set of validators for common use cases while allowing you to create custom validation logic with ease.

✨ Features

  • 🎯 Easy to Use: Simple validation with clear, readable syntax
  • 🔧 Flexible: Support for custom validators and conditional validation
  • 📝 Type Safe: Built on Pydantic with full type annotation support
  • 🌍 Comprehensive: Wide range of built-in validators for strings, numbers, dates, and more
  • 🚀 Performance: Efficient validation with minimal overhead
  • 📖 Well Documented: Comprehensive documentation with examples

🚀 Quick Example

from pyvalidx import ValidatedModel, field_validated
from pyvalidx.core import is_required
from pyvalidx.string import is_email, is_strong_password
from pyvalidx.numeric import min_value

class User(ValidatedModel):
    name: str = field_validated(is_required())
    email: str = field_validated(is_required(), is_email())
    password: str = field_validated(is_required(), is_strong_password())
    age: int = field_validated(is_required(), min_value(18))

# This will validate automatically
try:
    user = User(
        name="John Doe",
        email="john@example.com", 
        password="SecurePass123!",
        age=25
    )
    print("User created successfully!")
except ValidationException as e:
    print(f"Validation failed: {e.to_dict()}")

📦 Installation

Install PyValidX using pip:

pip install pyvalidx

Or with poetry:

poetry add pyvalidx

🎯 Core Concepts

Validators

Validators are functions that check if a value meets certain criteria. They return True if valid, False otherwise.

ValidatedModel

A Pydantic model that automatically runs custom validators on initialization and provides error handling.

field_validated

A field decorator that attaches validators to model fields.

ValidationException

A custom exception that provides structured error information when validation fails.

📚 Available Validators

Core Validators

  • is_required() - Ensures field is not None, empty string, or empty list
  • min_length() - Minimum string/list length
  • max_length() - Maximum string/list length
  • same_as() - Field must match another field
  • required_if() - Conditional requirement based on another field

String Validators

  • is_email() - Valid email format
  • is_strong_password() - Strong password requirements
  • matches_regex() - Custom regex pattern matching
  • no_whitespace() - No spaces allowed
  • is_phone() - Colombian phone number format

Numeric Validators

  • is_positive() - Positive numbers only
  • is_integer() - Integer type validation
  • is_float() - Float type validation
  • min_value() - Minimum numeric value
  • max_value() - Maximum numeric value

Date Validators

  • is_date() - Valid date format
  • is_future_date() - Date must be in the future
  • is_past_date() - Date must be in the past
  • is_today() - Date must be today

Type Validators

  • is_dict() - Dictionary type validation
  • is_list() - List type validation
  • is_boolean() - Boolean type validation
  • is_in() - Value must be in specified choices

🔗 Quick Links

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.

📄 License

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

👤 Author

Harrison Alonso Arroyave Gaviria

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

pyvalidx-0.1.3.tar.gz (10.6 kB view details)

Uploaded Source

Built Distribution

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

pyvalidx-0.1.3-py3-none-any.whl (11.3 kB view details)

Uploaded Python 3

File details

Details for the file pyvalidx-0.1.3.tar.gz.

File metadata

  • Download URL: pyvalidx-0.1.3.tar.gz
  • Upload date:
  • Size: 10.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.9

File hashes

Hashes for pyvalidx-0.1.3.tar.gz
Algorithm Hash digest
SHA256 49b4b650f061a0637feb2d17c29c7e5f5b02fca89ef5e66eca66d0deffeaa8e4
MD5 0c8397f3f4ecf9e64b231d395fdb99cc
BLAKE2b-256 01298d4dd2ecbdd6a17ac7e4a23355dbee4aa080a6d2daee4969dee7d0912607

See more details on using hashes here.

File details

Details for the file pyvalidx-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: pyvalidx-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 11.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.9

File hashes

Hashes for pyvalidx-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 84453b1be41bcab3c1cb78668253ed7509f07cb57c3aae17fe7e186fb822284a
MD5 aaac8b2897d6b64bf458034d44ed1f6a
BLAKE2b-256 9d84dc50c589c732d610130cf0718cf6c691a67e99e8c9a00677f133628164fd

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