A popular .NET validation library developed by 'Jeremy Skinner' for building strongly-typed validation rules, rewritten in python by 'Pablo Hernández'
Project description
FluentValidation
A validation library for Python that uses a fluent interface and lambda expressions for building strongly-typed validation rules.
The original library is written in .NET.
Supporting the project
This module has been translated by @p-hzamora.
If you use FluentValidation in a commercial project, please sponsor the project financially. FluentValidation is developed and supported by @JeremySkinner for free in his spare time and financial sponsorship helps keep the project going. You can sponsor the project via either GitHub sponsors or OpenCollective.
Table of contents
Getting started
- Installation
- Creating your first validator
- Chaining Validator
- Throwing Exceptions
- Complex Properties
- Collections
Configuring Validators
Building Rules
-
- NotNull Validator
- NotEmpty Validator
- NotEqual Validator
- Equal Validator
- Length Validator
- MaxLength Validator
- MinLength Validator
- Less Than Validator
- Less Than Or Equal Validator
- Greater Than Validator
- Greater Than Or Equal Validator
- Predicate Validator
- Regular Expression Validator
- Email Validator
- Credit Card Validator
- Enum Validator
- Enum Name Validator
- Empty Validator
- Null Validator
- Exclusive Between Validator
- Inclusive Between Validator
- PrecisionScale Validator
Other Features
Localization
Get Started
FluentValidation can be installed using the pip
package manager.
pip install fluent_validation
Example
from fluent_validation import AbstractValidator
def BeAValidPostcode(postcode:str)->bool:
# custom postcode validating logic goes here
class CustomerValidator(AbstractValidator[Customer]):
def __init__(self)-> None:
super().__init__(Customer)
self.rule_for(lambda x: x.Surname).not_empty()
self.rule_for(lambda x: x.Forename).not_empty().with_message("Please specify a first name")
self.rule_for(lambda x: x.Discount).not_equal(0).when(lambda x: x.HasDiscount)
self.rule_for(lambda x: x.Address).length(20, 250)
self.rule_for(lambda x: x.Postcode).must(BeAValidPostcode).with_message("Please specify a valid postcode")
customer = Customer()
validator = CustomerValidator()
# Execute the validator
results = validator.validate(customer)
# Inspect any validation failures.
success = results.is_valid
failures = results.errors
License, Copyright etc
FluentValidation is copyright © 2008-2022 .NET Foundation, Jeremy Skinner and other contributors and is licensed under the Apache2 license.
Sponsors
The original project is sponsored by the following organisations whose support help keep this project going:
- Microsoft for their financial contribution
- JetBrains for providing licenses to their developer tools
The original project is part of the .NET Foundation.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file fluent_validation-4.3.1.tar.gz
.
File metadata
- Download URL: fluent_validation-4.3.1.tar.gz
- Upload date:
- Size: 61.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.12.6 Darwin/23.5.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5a5603a7aa979c41ead5b75aeefbfd7854b5b39cca66f02f77ef487bd2d35719 |
|
MD5 | 0e30b6f59d41ebb8b7ab59e35afdef5d |
|
BLAKE2b-256 | bd1b7eed72b7d407f5352f824c5f4b957b18bf372de775ff77e40d07588e3122 |
File details
Details for the file fluent_validation-4.3.1-py3-none-any.whl
.
File metadata
- Download URL: fluent_validation-4.3.1-py3-none-any.whl
- Upload date:
- Size: 91.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.12.6 Darwin/23.5.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ee30cc2029c4773f5bba6c043c7c1b697cac39a53762883b74530e7bb4c0c53c |
|
MD5 | 48ec09878ca773bb2fb9dee68e8b96b5 |
|
BLAKE2b-256 | 31c94b76837556830432910fb8022c676ff0d96f8490bfce649432ca71fcec59 |