Skip to main content

Data parsing and validation library for Python

Project description

modelity

Data parsing and validation library for Python.

About

Modelity is a data parsing and validation library allowing to declare mutable data models using Python's type hinting mechanism. Modelity design was based on following assumptions:

  • Use of recursive type parser providers, allowing to create parsers for both built-in types, and user-defined ones.

  • Use of cache mechanism, so type parser created once can be reused by other models, or other fields.

  • Clean separation between data parsing and model validation steps, with automatic data parsing whenever model is created or modified, and validation phase being executed on user's demand.

  • Separation between model-scoped validators (executed always) and field-scoped validators (executed for selected fields and only if the field has value set).

  • Ability to inspect entire model when validating it, even from a nested model.

  • Use of separate Unset type to differentiate between fields set to None and fields that are unset.

  • Easily customized with user-defined parsing and/or validation hooks provided by decorators.

  • Models are mutable, so modifying a field after model is created, appending a value to typed list field etc. invokes parsing mechanism, keeping integrity of the entire model.

Rationale

Why I have created this toolkit?

Well, for fun, that's for sure :-)

I also wanted to resurrect some ideas from my over 10-year old and abandoned project Formify (which you can still find on my GH profile), as it was already supplied with data parsing and validation separation mechanism. Unfortunately, the name Formify was already in use (as I have never released it), so I've decided to go with a completely new project name.

And last but not least - the separation of concerns (parsing and validation) is the feature that I needed in several projects, both private and commercial, and that I did not find in any toolkit I've been using, forcing me to subclassing and/or creating separate project-specific tools to make validation being separate from data parsing. I needed this especially for large models, with lots of nested submodels, that could not be easily validated without being able to inspect entire model tree (f.e. when validity of nested model depends on a value of particular parent model field).

Usage

I will create a separate guide in the future, but for now please check out the examples directly in the source code:

https://github.com/mwiatrzyk/modelity/tree/main/tests/examples

License

This project is released under the terms of the MIT license.

Author

Maciej Wiatrzyk maciej.wiatrzyk@gmail.com

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

modelity-0.7.0.tar.gz (22.8 kB view details)

Uploaded Source

Built Distribution

modelity-0.7.0-py3-none-any.whl (33.1 kB view details)

Uploaded Python 3

File details

Details for the file modelity-0.7.0.tar.gz.

File metadata

  • Download URL: modelity-0.7.0.tar.gz
  • Upload date:
  • Size: 22.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.7 Linux/6.8.0-1018-aws

File hashes

Hashes for modelity-0.7.0.tar.gz
Algorithm Hash digest
SHA256 21f320cc37c7dc7d17abed9e74b2a8a1994717ff09243d099a05376a0701360e
MD5 6362071b243613226ef61c51f0aa9509
BLAKE2b-256 29a2f0a68d38c1be14a333480cad5c3bdb5f9218031e7492f7e37eca081654dc

See more details on using hashes here.

File details

Details for the file modelity-0.7.0-py3-none-any.whl.

File metadata

  • Download URL: modelity-0.7.0-py3-none-any.whl
  • Upload date:
  • Size: 33.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.7 Linux/6.8.0-1018-aws

File hashes

Hashes for modelity-0.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 21e172028a0f0c9701182293938cee5affbeab154c9c88da643cd26956081242
MD5 a66cc419a6aaf0512d2eadcb6cd4f56e
BLAKE2b-256 62e9fde9d2f27be6408aaab8042ee1c85ab94d15ee50102998a7799ec598fa4d

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page