Skip to main content

Validobj gives you valid objects

Project description


Validobj is library that takes semistructured data (for example JSON and YAML configuration files) and converts it to more structured Python objects. It places the emphasis on:

  • Good error messages (rather than avoiding extra work in the error handling code).
  • Schema defined in terms of dataclasses and other high level objects such as enums, as well as a subset of the typing module.
  • Simplicity of implementation (rather than full generality).

Validobj requires Python 3.7 and has no other dependencies.



import dataclasses
import enum
from typing import Mapping, Set, Tuple, List

from validobj import parse_input

inp = {
    'global_environment': {'CI_ACTIVE': '1'},
    'stages': [
            'name': 'compile',
            'os': ['linux', 'mac'],
            'script_path': '',
            'disk_permissions': ['READ', 'WRITE', 'EXECUTE'],
            'name': 'test',
            'os': ['linux', 'mac'],
            'script_path': '',
            'framework_version': [4, 0],

class DiskPermissions(enum.Flag):
    READ =
    WRITE =

class OS(enum.Enum):
    mac =
    windows =
    linux =

class Job:
    name: str
    os: Set[OS]
    script_path: str
    framework_version: Tuple[int, int] = (1, 0)
    disk_permissions: DiskPermissions = DiskPermissions.READ

class CIConf:
    stages: List[Job]
    global_environment: Mapping[str, str] = dataclasses.field(default_factory=dict)

print(parse_input(inp, CIConf))
# This results in a dataclass instance with the correct types:
#    stages=[
#        Job(
#            name='compile',
#            os={<OS.linux: 3>, <OS.mac:1>},
#            script_path='',
#            framework_version=(1, 0),
#            disk_permissions=<DiskPermissions.EXECUTE|WRITE|READ: 7>,
#        ),
#        Job(
#            name='test',
#            os={<OS.linux: 3>, <OS.mac: 1>},
#            script_path='',
#            framework_version=(4, 0),
#            disk_permissions='<DiskPermissions.READ: 1>',
#        ),
#    ],
#    global_environment={'CI_ACTIVE': '1'},


The package can be installed with pip:

python3 -m pip install validobj

The code is hosted at

Project details

Download files

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

Files for validobj, version 0.3.2
Filename, size File type Python version Upload date Hashes
Filename, size validobj-0.3.2-py2.py3-none-any.whl (9.6 kB) File type Wheel Python version py2.py3 Upload date Hashes View hashes
Filename, size validobj-0.3.2.tar.gz (17.4 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page