Skip to main content

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

PyPI version downloads License: Apache

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

Configuring Validators

Building Rules

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__()
    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 &copy 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fluent_validation-3.1.0.tar.gz (58.4 kB view details)

Uploaded Source

Built Distribution

fluent_validation-3.1.0-py3-none-any.whl (86.9 kB view details)

Uploaded Python 3

File details

Details for the file fluent_validation-3.1.0.tar.gz.

File metadata

  • Download URL: fluent_validation-3.1.0.tar.gz
  • Upload date:
  • Size: 58.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.2 CPython/3.12.2 Darwin/23.5.0

File hashes

Hashes for fluent_validation-3.1.0.tar.gz
Algorithm Hash digest
SHA256 dad46e2ec73aa131cd8ac3d46c76579d5418c4004695c2fee5e0e852884d1ce8
MD5 035b0577ee7cd8b0e4b45fd90bbbd63b
BLAKE2b-256 3807175d01f591b6c7c73c28221621b2bfbecdf28f7903c42d1aec2eb762ecb7

See more details on using hashes here.

File details

Details for the file fluent_validation-3.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for fluent_validation-3.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d1ef089ddf3ecd9415b16899f56f7df9bd0ec91fee933193ba50e2356bac071e
MD5 a05becf801c1c3d8598b91646dd2c4ab
BLAKE2b-256 9f86fe25145f6059c3c253b8e434530e02ef6a287c759780a0533b93774419c0

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page