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/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.1.tar.gz (11.2 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.1-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for v6e-0.1.1.tar.gz
Algorithm Hash digest
SHA256 a60e9ede31058c924781cb6adcce3e296dcff35de2a6f9f84c7ad43b7a3adb41
MD5 5fd035b9c13c1bdca2ef4ff89feb7713
BLAKE2b-256 fdb8f2aea99f8deb85f7c61c61dd4b6986bb85402877c1cf1e7eaf422c0b16da

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for v6e-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7e08d011f5977fbbd20464190dea68a5fca0c7559d2cfaa54026c8ff4c72c35d
MD5 49204c09630dd9dc277b34efb7ab1f33
BLAKE2b-256 984ec6423fe57309982a43e81add38719fcc0dc447baa812a85c4b67e8ef7aaf

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