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:

GitHub sponsors (Phzamora)

GitHub sponsors (JeremySkinner)

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__(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 &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-4.3.31.tar.gz (108.9 kB view details)

Uploaded Source

Built Distribution

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

fluent_validation-4.3.31-py3-none-any.whl (226.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: fluent_validation-4.3.31.tar.gz
  • Upload date:
  • Size: 108.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.10 Darwin/24.6.0

File hashes

Hashes for fluent_validation-4.3.31.tar.gz
Algorithm Hash digest
SHA256 5d0c7118412e54376d3d81744747ef07e7d26e9886d8386842f8927db9e2080a
MD5 ef72ffd2fee7828e7f0690455afc8ae0
BLAKE2b-256 4139d67de19555fef7f14e23bd904057287f4c198979752ac3c3d459692abffb

See more details on using hashes here.

File details

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

File metadata

  • Download URL: fluent_validation-4.3.31-py3-none-any.whl
  • Upload date:
  • Size: 226.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.10 Darwin/24.6.0

File hashes

Hashes for fluent_validation-4.3.31-py3-none-any.whl
Algorithm Hash digest
SHA256 6a0058cf7aa45f174c41128ef12d02f18106c1a6f26f1c9f94bf1f3fd6039269
MD5 2fdc70f818b0fbd63b7eeeaf4091909c
BLAKE2b-256 67825b85d68babc0324da8801260711cf50fe8c596cf5bc0529f736fcac494bf

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