Skip to main content

A powerful validations framework

Project description

🔍 V6E

A simple, type-safe, and extensible Python validations framework

Why the name?

v6e comes from the numeronym of "validate".

Examples

Check out the examples in ./examples! You can run them locally with:

uv run examples/<name>

For example:

uv run examples/validations.py

Usage

First, you'll need to import the validations module:

from term import validations as v

Basic validations

my_validation = v.Range(18, 21)

# .test(...)
my_validation.test(18)  # True
my_validation.test(21)  # True
my_validation.test(54)  # False

# .validate(...)
my_validation.validate(21)  # Nothing happens -> continue to next line
my_validation.validate(54)  # Raises a ValidationException()

AND and OR validations

my_validation = (v.StartsWith("foo") | v.EndsWith("foo")) & v.ReMatch(r"^[a-z]*$")
my_validation.test("foo12")  # True
my_validation.test("12foo")  # True
my_validation.test("1foo2")  # False

Custom validations

def is_div_three(x: int):
    if x % 3 != 0:
        raise ValueError("Woops! The Earth is 4.543 billion years old. (Try 4543000000)")

my_validation = v.Custom(validate_earth_age)
my_validation.test(3)  # True
my_validation.test(6)  # True
my_validation.test(4)  # False

🐍 Type-checking

This library is fully type-checked. This means that all types will be correctly inferred from the arguments you pass in.

In this example your editor will correctly infer the type:

my_validation = v.StartsWith("foo") | v.Range(1, 4)
reveal_type(hours)  # Type of "res" is "timedelta | str | int"

In some cases, like prompting, the type will also indicate how to validate and parse the passed argument. For example, the following code will validate that the passed input is a valid number:

age = term.prompt("What's your age?", klass=int)

Why do I care?

Type checking will help you catch issues way earlier in the development cycle. It will also provide nice autocomplete features in your editor that will make you faster 󱐋.

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

v6e-0.1.0.tar.gz (6.3 kB view details)

Uploaded Source

Built Distribution

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

v6e-0.1.0-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

Details for the file v6e-0.1.0.tar.gz.

File metadata

  • Download URL: v6e-0.1.0.tar.gz
  • Upload date:
  • Size: 6.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.2

File hashes

Hashes for v6e-0.1.0.tar.gz
Algorithm Hash digest
SHA256 1441e8640a51c293d85158a4e2e9075d82466558ca5c1308243d54e9045a33aa
MD5 0e5f3a86cc851e3b59351d3efd54dbd1
BLAKE2b-256 8d74e6652666d804361c858638c1713ac248fd7d829bc7e18d4a221e971c29b7

See more details on using hashes here.

File details

Details for the file v6e-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: v6e-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.2

File hashes

Hashes for v6e-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 eaece3eb9dc6f00be39808ec700f5aed5a7cb578d09abfa61917d12227c9e6d1
MD5 43619a440e63d29c4f7512a233945fcf
BLAKE2b-256 106965ccdf129bf7ddb9efdc56316b125be050741df9680cdc66dc41b97c524d

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