Skip to main content

VAA

VAlidators Adapter makes validation by any existing validator with the same interface.

Supported validators:

validator adapter
Cerberus va.cerberus
Django Forms va.django
Marshmallow va.marshmallow
PySchemes va.pyschemes
Django REST Framework va.restframework
WTForms va.wtforms
python3 -m pip install --user vaa

Example

import marshmallow
import vaa

@vaa.marshmallow
class Scheme(marshmallow.Schema):
  id = marshmallow.fields.Int(required=True)
  name = marshmallow.fields.Str(required=True)

Validating data

All schemes adopted by vaa has the same interface:

validator = Scheme({'id': '1', 'name': 'Oleg'})
validator.is_valid()    # True
validator.cleaned_data  # {'name': 'Oleg', 'id': 1}

validator = Scheme({'id': 'no', 'name': 'Oleg'})
validator.is_valid()    # False
validator.errors        # [Error(message='Not a valid integer.', field='id')]

Simple scheme

If you want to do validation with simple function, you can use va.simple adapter. For example, you want to check that in dict {'a': ..., 'b': ...} both values are positive. There are many ways to do so.

It can return bool:

@vaa.simple
def validate(a, b) -> bool:
  return a > 0 and b > 0

Or return message for error:

@vaa.simple
def validate(a, b) -> bool:
  if a > 0 and b > 0:
    return True
  return 'should be positive'

Or return errors dict:

@vaa.simple
def validate(a, b) -> bool:
  if a <= 0:
    return {'a': 'should be positive'}
  if b <= 0:
    return {'b': 'should be positive'}
  return True

Or raise va.ValidationError with error message or dict:

@vaa.simple
def validate(a, b) -> bool:
  if a > 0 and b > 0:
      return True
  raise vaa.ValidationError('should be positive')

Also, if you want to get the original dict without unpacking it into keyword arguments, do a function that accepts only one _ argument:

@vaa.simple
def validate(_):
  return _['a'] > 0 and _['b'] > 0

In that dict keys can be accessed as attributes:

@vaa.simple
def validate(_):
  return _.a > 0 and _.b > 0

Choose the best way and follow it. Avoid mixing them in one project.

Unknown scheme

If you're making a library that should accept any validator without explicit vaa usage, use vaa.wrap:

class Scheme(marshmallow.Schema):
  id = marshmallow.fields.Int(required=True)
  name = marshmallow.fields.Str(required=True)

validator = vaa.wrap(Scheme)({'id': 'no', 'name': 'Oleg'})
validator = Scheme({'id': 'no', 'name': 'Oleg'})
validator.is_valid()    # False
validator.errors        # [Error(message='Not a valid integer.', field='id')]

Metadata

Release files for vaa 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for vaa 0.2.1
File Size Uploaded Provenance
vaa-0.2.1.tar.gz 8.1 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for vaa 0.2.1
File Interpreter ABI Platform
vaa-0.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 16.3 kB

Release files / vaa-0.2.1.tar.gz

Download URL vaa-0.2.1.tar.gz
Size 8.1 kB
Tags Source
SHA-256 checksum
How to use checksums
55a4419d8b094aacffb82d748b09abe5ca35fe603675ebdab7571373e7d3bf8a
BLAKE2b-256 checksum
How to use checksums
e274369907e565282db1952aa70c244f425d6d158c1c096306e0552afaab5bfd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via DepHell/0.8.2

Release files / vaa-0.2.1-py3-none-any.whl

Download URL vaa-0.2.1-py3-none-any.whl
Size 8.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8f638e47e633739f5fb2912d36c5c01f7d757ce9f9508745dcae1eb0b8f1778f
BLAKE2b-256 checksum
How to use checksums
78902008188c9427f118587e038e2a00f4247c07acec09fc934b2addeda668f2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via DepHell/0.8.2

Security for vaa 0.2.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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