Skip to main content

fivalid is lightweight field data validator.

Features

data validation:

>>> from fivalid import validators
>>> num = validators.Number(max=20)
>>> num(10)
>>> num(21)
fivalid.validators.InvalidValueError: over max

data validation and conversion:

>>> from fivalid import BaseField, validators, converters
>>> class PercentageField(BaseField):
...   validator = validators.All(
...     validators.Number(min=0, max=100),
...     validators.String())
...   converter = converters.int_converter
>>> field = PercentageField()
>>> field('99')
99
>>> field('200')
fivalid.validators.InvalidValueError: over max

structured data (e.g. nested dict, nested list) validation and conversion:

>>> from fivalid import StructuredFields, Dict, BaseField
>>> from fivalid.validators import String, Length, All, Flag
>>> from fivalid.converters import truthvalue_converter
>>> class CommentField(BaseField):
...   validator = All(String(), Length(max=500))
>>> class NicknameField(BaseField):
...   validator = All(String(), Length(max=20))
>>> class RememberMeField(BaseField):
...   validator = Flag()
...   converter = truthvalue_converter
>>> rule = Dict(
...   {'comment': CommentField(required=True),
...    'nickname': NicknameField(),
...    'remember me': RememberMeField()}
... )
>>> stfields = StructuredFields(rule)
>>> stfields({'comment': 'Hello, fivalid.',
...           'nickname': 'John Doe',
...           'remember me': '1'}
... )
{'comment': u'Hello, fivalid.', 'nickname': u'John Doe', 'remember me': True}

Download files

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

Source Distribution

fivalid-0.3.0.zip (17.2 kB view details)

Uploaded Source

File details

Details for the file fivalid-0.3.0.zip.

File metadata

  • Download URL: fivalid-0.3.0.zip
  • Upload date:
  • Size: 17.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for fivalid-0.3.0.zip
Algorithm Hash digest
SHA256 f197ec472df10dc10210fabad1863dc9f3ee7b68940cc3c04ea1b6ee353d228f
MD5 926af5d9271b68fced45b9e7a082a9d8
BLAKE2b-256 27c06a8c124c5c2be145ae5af8d0eda98762d356c9054f456ed750b3f947d62c

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.3.0 This release

1 file

0.2.5

1 file

0.2.4

1 file

0.2.3

1 file

0.2.2

1 file

0.2.1

1 file

0.2.0

1 file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page