Norma
Norma is a data validation framework designed for Pandas and PySpark DataFrames, leveraging JSON Schema or a Python API to enforce data integrity. Unlike traditional validation libraries that halt execution on errors, Norma introduces a resilient, non-intrusive approach that captures validation details in a dedicated errors column while resetting erroneous values to null.
Install
Install with pip:
pip install vitalibo.norma
Quick Start
First, create a validation schema from JSON Schema:
{
"$id": "https://example.com/address.schema.json",
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"name": {
"type": "string",
"minLength": 2
},
"age": {
"type": "integer",
"minimum": 0,
"maximum": 120
},
"sex": {
"type": "string",
"enum": [
"M",
"F"
]
},
"email": {
"type": "string",
"pattern": "^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\\.[a-zA-Z0-9-.]+$"
}
},
"required": [
"name",
"age",
"email"
]
}
from norma.schema import Schema
schema = Schema.from_json_schema({... see above ...})
alternatively, build the schema with the Python API:
from norma.schema import Column, Schema
from norma import rules
schema = Schema({
'name': Column(str, min_length=2),
'age': Column(int, ge=0, le=120),
'sex': Column(str, rules=rules.isin(['M', 'F'])),
'email': Column(str, pattern=r'^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$')
})
Now, we are ready to validate our data. Let's create a Pandas DataFrame with some invalid data.
import pandas as pd
df = pd.DataFrame({
'name': ['John', 'Rian', 'Alice'],
'age': [42, 130, 25],
'sex': ['M', 'F', 'X'],
'email': ['john@spring.ep', 'ryna@spring.ep', 'alice.spring@ep']
})
or, you can create the same example as a PySpark DataFrame:
from pyspark.sql import SparkSession
spark_session = SparkSession.builder.getOrCreate()
df = spark_session.createDataFrame([
('John', 42, 'M', 'john@spring.ep'),
('Rian', 130, 'F', 'ryna@spring.ep'),
('Alice', 25, 'X', 'alice.spring@ep')
], ['name', 'age', 'sex', 'email'])
Finally, validate the dataframe:
actual = schema.validate(df)
Output:
For Pandas DataFrame we have:
name age sex email errors
0 John 42 M john@spring.ep {}
1 Rian <NA> F ryna@spring.ep {'age': {'details': [{'type': 'less_than_equal', 'msg': 'Input should be less than or equal to 120'}], 'original': '130'}}
2 Alice 25 <NA> <NA> {'sex': {'details': [{'type': 'enum', 'msg': 'Input should be "M" or "F"'}], 'original': '"X"'}, 'email': {'details': [{'type': 'string_pattern_mismatch', 'msg': 'String should match pattern "^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\\.[a-zA-Z0-9-.]+$"'}], 'original': '"alice.spring@ep"'}}
and dtypes:
name string[python]
age Int64
sex string[python]
email string[python]
errors object
dtype: object
Similarly, for PySpark DataFrame:
+-----+----+----+--------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|name |age |sex |email |errors |
+-----+----+----+--------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|John |42 |M |john@spring.ep|{} |
|Rian |NULL|F |ryna@spring.ep|{age -> {[{less_than_equal, Input should be less than or equal to 120}], 130}} |
|Alice|25 |NULL|NULL |{email -> {[{string_pattern_mismatch, String should match pattern "^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$"}], "alice.spring@ep"}, sex -> {[{enum, Input should be "M" or "F"}], "X"}}|
+-----+----+----+--------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
and schema:
root
|-- name: string (nullable = true)
|-- age: integer (nullable = true)
|-- sex: string (nullable = true)
|-- email: string (nullable = true)
|-- errors: map (nullable = false)
| |-- key: string
| |-- value: struct (valueContainsNull = true)
| | |-- details: array (nullable = false)
| | | |-- element: struct (containsNull = true)
| | | | |-- type: string (nullable = true)
| | | | |-- msg: string (nullable = true)
| | |-- original: string (nullable = true)
Supported validation rules
Norma supports a variety of validation rules, including:
| rule | pandas | pandas[object] | pandas[array] | pyspark | pyspark[object] | pyspark[array] |
|---|---|---|---|---|---|---|
required |
✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
equal_to |
✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
not_equal_to |
✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
greater_than |
✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
greater_than_equal |
✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
less_than |
✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
less_than_equal |
✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
multiple_of |
✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
min_length |
✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
max_length |
✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
pattern |
✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
isin |
✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
notin |
✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
extra_forbidden |
✅ | ✅ | ➖ | ✅ | ✅ | ➖ |
unique_items |
✅ | ➖ | ✅ | ✅ | ➖ | ✅ |
max_items |
✅ | ➖ | ✅ | ✅ | ➖ | ✅ |
min_items |
✅ | ➖ | ✅ | ✅ | ➖ | ✅ |
int_parsing |
✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
float_parsing |
✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
str_parsing |
✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
bool_parsing |
✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
date_parsing |
✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
time_parsing |
✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
datetime_parsing |
✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
duration_parsing |
✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
uuid_parsing |
✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
ipv4_address |
✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
ipv6_address |
✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
uri_parsing |
✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
object_parsing |
✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
array_parsing |
✅ | ✅ | ❌ | ✅ | ✅ | ❌ |
✅ - supported ❌ - not supported ➖ - not applicable
Errors
The error format is a dictionary where the key is the column name, and value is a structure with two fields: details
and original. The details field is a list of details about the error, and the original field is the original value
that caused the error.
{
"name": "Alice",
"age": 25,
"sex": null,
"email": null,
"errors": {
"sex": {
"details": [
{
"type": "enum",
"msg": "Input should be \"M\" or \"F\""
}
],
"original": "\"X\""
},
"email": {
"details": [
{
"type": "string_pattern_mismatch",
"msg": "String should match pattern \"^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\\.[a-zA-Z0-9-.]+$\""
}
],
"original": "\"alice.spring@ep\""
}
}
}
Special case, when DataFrame has array validation rules, the error format is slightly different.
In this case, the details array has an additional loc field that indicates the indexes of the array elements that
failed validation and incorrect values are replaced with null in an array.
{
"tags": [
null,
"tag1",
null
],
"errors": {
"tags[]": {
"details": [
{
"loc": [
0,
2
],
"type": "enum",
"msg": "Input should be \"tag1\", \"tag2\" or \"tag3\""
}
],
"original": "[\"tag0\",\"tag1\",\"tag4\"]"
}
}
}
Metadata
Release files for vitalibo.norma 0.3.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| vitalibo_norma-0.3.1.tar.gz | 190.0 kB | With provenance | Details for vitalibo_norma-0.3.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| vitalibo_norma-0.3.1-py3-none-any.whl | Python 3 | none | any | Details for vitalibo_norma-0.3.1-py3-none-any.whl |
Total release size: 224.5 kB
Release files / vitalibo_norma-0.3.1.tar.gz
| Download URL | vitalibo_norma-0.3.1.tar.gz |
|---|---|
| Size | 190.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f19a0855ab7f415313145f528f48e00647b7e3ec2c7d49a8beae13708d7e88b9
|
|
BLAKE2b-256 checksum How to use checksums |
4b266d35afa429cd9aa12b923f47dde415c26c8194785cc6f3d18569b8abe4d4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 18, 2026.
Transparency logRelease files / vitalibo_norma-0.3.1-py3-none-any.whl
| Download URL | vitalibo_norma-0.3.1-py3-none-any.whl |
|---|---|
| Size | 34.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7b986c3eb4b0c96756317c51e9e50d395efe8df1d451da9bda47c2d1d6919ad0
|
|
BLAKE2b-256 checksum How to use checksums |
47514646a1ab70ec6787079a7a141e8f05c3b50090aa78af78ca281b0443fbc7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 18, 2026.
Transparency logSecurity for vitalibo.norma 0.3.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.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for vitalibo_norma-0.3.1.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 18, 2026.
Transparency logA 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.