Skip to main content

Norma

status

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.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for vitalibo.norma 0.3.0
File Size Uploaded Provenance Actions
vitalibo_norma-0.3.0.tar.gz 192.8 kB With provenance Details for vitalibo_norma-0.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for vitalibo.norma 0.3.0
File Interpreter ABI Platform Actions
vitalibo_norma-0.3.0-py3-none-any.whl Python 3 none any Details for vitalibo_norma-0.3.0-py3-none-any.whl

Total release size: 227.9 kB

Release files / vitalibo_norma-0.3.0.tar.gz

Download URL vitalibo_norma-0.3.0.tar.gz
Size 192.8 kB
Tags Source
SHA-256 checksum
How to use checksums
a1dae18c2697ccdb09a1a8bab86d222a1ef7b2e7775fc5372341cc1da44868fb
BLAKE2b-256 checksum
How to use checksums
6e1a192abe3240c6fd88cd9f268947bfded3e1a579aa235db81f6cc21ed2eb69
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 12, 2026.

Transparency log

Release files / vitalibo_norma-0.3.0-py3-none-any.whl

Download URL vitalibo_norma-0.3.0-py3-none-any.whl
Size 35.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1c3a7835809cc1a5b2194c4db5382d3ad2f491a26f4f6b5dec8f78a5ca5db84e
BLAKE2b-256 checksum
How to use checksums
578c987ba3cc839e18b22af7ec76afb1b466e597cfc60867634143b6d1454b3f
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 12, 2026.

Transparency log

Security for vitalibo.norma 0.3.0

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.

Select from 2 files

Attestation for vitalibo_norma-0.3.0.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 12, 2026.

Transparency log

A 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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page