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.8.0.tar.gz (21.9 kB view details)

Uploaded Source

Built Distribution

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

modelity-0.8.0-py3-none-any.whl (27.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: modelity-0.8.0.tar.gz
  • Upload date:
  • Size: 21.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.2 CPython/3.12.10 Linux/6.8.0-1024-aws

File hashes

Hashes for modelity-0.8.0.tar.gz
Algorithm Hash digest
SHA256 7ae921232f8cdb584b82d8227ccb4d969e102442ad35df7eb4bf3accd3679745
MD5 5b55db8148521a8ccc9785a77b1726e9
BLAKE2b-256 c258b33b3f142813841812891d3c183b42bb38fb7b0298f5e6bb277268fad621

See more details on using hashes here.

File details

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

File metadata

  • Download URL: modelity-0.8.0-py3-none-any.whl
  • Upload date:
  • Size: 27.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.2 CPython/3.12.10 Linux/6.8.0-1024-aws

File hashes

Hashes for modelity-0.8.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0571c083e212e5f7e058297730dc16544aaf7234f09caf0fa9819d202f75aa73
MD5 56caf78c52d09c8c394b225dc8908527
BLAKE2b-256 6c4b8049b42a7eda7824d5492c9be1dcd3727d5f30fe4affd25d807c55ee71a6

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