
Security News
Another Round of TEA Protocol Spam Floods npm, But It’s Not a Worm
Recent coverage mislabels the latest TEA protocol spam as a worm. Here’s what’s actually happening.
Data parsing and validation library for Python.
Modelity is a data parsing and validation library, written purely in Python, and based on the idea that data parsing and validation should be separated from each other, but being a part of single toolkit for ease of use.
In Modelity, data parsing is executed automatically once data model is instantiated or modified, while model validation needs to be explicitly called by the user. Thanks to this approach, models can be feed with data progressively (f.e. in response to user’s input), while still being able to validate at any time (f.e. in reaction to button click).
Unset sentinel) and
optional fields set to None__modelity_type_descriptor__ static method in user-defined type, or by
using type_descriptor_factory hook for registering 3rd party types.Why I have created this library?
First reason is that I didn’t find such clean separation in known data parsing tools, and found myself needing such freedom in several projects - both private, and commercial ones. Separation between parsing and validation steps simplifies validators, as validators in models can assume that they are called when model is successfully instantiated, with all fields parsed to their allowed types, therefore they can access all model’s fields without any extra checks.
Second reason is that I often found myself writing validation logic from the scratch for various reasons, especially for large models with lots of dependencies. Each time I had to validate some complex logic manually I was asking myself, why don’t merge all these ideas and make a library that already has these kind of helpers? For example, I sometimes needed to access parent model when validating field that itself is another, nested model. With Modelity, it is easy, as root model (the one that is validated) is populated to all nested models' validators recursively.
Third reason is that I wanted to finish my over 10 years old, abandoned project Formify (the name is already in use, so I have chosen new name for new project) which I was developing in free time at the beginning of my professional work as a Python developer. That project was originally made to handle form parsing and validation to be used along with web framework. Although the project was never finished, I’ve resurrected some ideas from it, especially parsing and validation separation. You can still find source code on my GitHub profile: https://github.com/mwiatrzyk.
And last but not least, I don’t intend to compete with any of the existing alternatives — and there are plenty of them. I simply created this project for fun and decided to release it once it became reasonably usable, hoping that maybe someone else will find it helpful.😊
Here's a condensed example of how to use Modelity:
import json
import datetime
import typing
from modelity.api import Model, ValidationError, ModelError, validate, dump, load
# 1. Define models
class Address(Model):
address_line1: str
address_line2: typing.Optional[str]
city: str
state_province: typing.Optional[str]
postal_code: str
country_code: str
class Person(Model):
name: str
second_name: typing.Optional[str]
surname: str
dob: datetime.date
address: Address
# 2. Create instances (parsing runs automatically)
addr = Address(
address_line1="221B Baker Street",
address_line2=None,
city="London",
state_province=None,
postal_code="NW1 6XE",
country_code="GB"
)
person = Person(
name="Sherlock",
second_name=None,
surname="Holmes",
dob=datetime.date(1854, 1, 6),
address=addr
)
#: 3. Validate instances (on demand)
try:
validate(person)
except ValidationError as e:
print("Model is not valid: ", e)
raise
# 4. Dump to JSON-serializable dict
person_dict = dump(person)
person_json = json.dumps(person_dict) # Dump to JSON; use any lib you like to do that
# 5. Parse from dict
person_dict = json.loads(person_json)
try:
same_person = load(Person, person_dict) # Parsing + validation made by helper
except ModelError as e: # Base for: ValidationError, ParsingError
print("Model parsing or validation failed: ", e)
raise
# 6. Accessing fields (just like using normal dataclasses).
print(same_person.address.country_code)
Please visit project's ReadTheDocs site: https://modelity.readthedocs.io/en/latest/.
Modelity is an independent open-source project for the Python ecosystem. It is not affiliated with, sponsored by, or endorsed by any company, organization, or product of the same or similar name. Any similarity in names is purely coincidental and does not imply any association.
This project is released under the terms of the MIT license.
Maciej Wiatrzyk maciej.wiatrzyk@gmail.com
FAQs
Data parsing and validation library for Python
We found that modelity demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Recent coverage mislabels the latest TEA protocol spam as a worm. Here’s what’s actually happening.

Security News
PyPI adds Trusted Publishing support for GitLab Self-Managed as adoption reaches 25% of uploads

Research
/Security News
A malicious Chrome extension posing as an Ethereum wallet steals seed phrases by encoding them into Sui transactions, enabling full wallet takeover.