Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

Certum

A dictionary validation library based on partial, composable and expressive rules.

Why use it

In case you need to assert some propeties from a particular dictionary in a DSL manner without comparing the entire structure or asserting fields.

Certum comes with the following features:

  • Easy to use
  • English friendly declaration
  • Error accumulation
  • Customizable
  • Anti KeyError

Using Certum

You can't use certum package for the moment, coming soon.

How it works

Basic usage

Imagine you have a very long json and you want to verify that it contains the following informations:

  • He should contains a key named 'name' containing a string.
  • He should contains a key named 'entities' being a list containing unique elements.
  • He should contains a key named 'nested' containing a key 'value' equals to 4.
from certum import ensure, that

my_obj = {
    "name": "hello",
    "entities": [1, 3, 5],
    "nested": {
        "value": 4
    }
}

validator = ensure(my_obj).respects(
    that("name").is_instance_of(str),
    that("entities").has_unique_elements(),
    that("nested", "value").equals(4)
)

validator.check()

Error handling

If there is errors, certum will accumulate and return errors elegantly:

from certum import ensure, that

my_obj = {
    "name": 2,
    "entities": [1, 3, 3],
    "nested": {
        "value": 2
    }
}

validator = (
    ensure(my_obj)
    .respects(
        that("name").is_instance_of(str),
        that("name").equals("Hello"),
        that("entities").foreach(this.equals(1)),
        that("nested", "value").equals(4),
    )
)

validator.check()

# certum.exception.CertumException: 

# [name] => The value is instance of int, expected str.
# [name] => The value is 2, expected Hello.
# [entities -> 2] => The value is 3, expected 1.
# [entities -> 1] => The value is 3, expected 1.
# [nested -> value] => The value is 2, expected 4.

Strategies

Erros can be sorted, filtered and printed using different strategies.

As an example, you may want to try the GroupedPrinting strategy with the AlphabeticalSorting strategy, this will give you a list of errors like this:

from certum import ensure, that, this
from certum.strategy.printing.grouped import GroupedPrinting
from certum.strategy.sorting.alphabetical import AlphabeticalSorting


my_obj = {
    "name": 2,
    "entities": [1, 3, 3],
    "nested": {
        "value": 2
    }
}

validator = (
    ensure(my_obj)
    .respects(
        that("name").is_instance_of(str),
        that("name").equals("Hello"),
        that("entities").foreach(this.equals(1)),
        that("nested", "value").equals(4),
    )
    .using(GroupedPrinting(), AlphabeticalSorting())
)

validator.check()

# certum.exception.CertumException: 

# entities -> 1   => The value is 3, expected 1.
# entities -> 2   => The value is 3, expected 1.
# name            => The value is 2, expected Hello.
#                    The value is instance of int, expected str.
# nested -> value => The value is 2, expected 4.

Release files for certum 1.0a1

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

Source distribution (sdist)

Source distribution for certum 1.0a1
File Size Uploaded
certum-1.0a1.tar.gz 10.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for certum 1.0a1
File Interpreter ABI Platform
certum-1.0a1-py3-none-any.whl Python 3 none any Details

Total release size: 31.3 kB

Release files / certum-1.0a1.tar.gz

Download URL certum-1.0a1.tar.gz
Size 10.9 kB
Tags Source
SHA-256 checksum
How to use checksums
31a61475d51774fed96ea3939b7935f8ef5a1dbba1222a113e6fb73d3f1d5dcc
BLAKE2b-256 checksum
How to use checksums
fc93a7863e850709efc6dc7ea5227a31cf5fd37a5972d35e2e70fca8d5954a64
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.4 CPython/3.8.7 Linux/5.10.8-100.fc32.x86_64

Release files / certum-1.0a1-py3-none-any.whl

Download URL certum-1.0a1-py3-none-any.whl
Size 20.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7c01f8a1bd3ca940617a70858976b55f3aed7337351152599d3f55f6a9fbb420
BLAKE2b-256 checksum
How to use checksums
2060bf511343e9bb046b4b5f2a40bb47a9532331ccb6921fad54f195fe137c0e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.4 CPython/3.8.7 Linux/5.10.8-100.fc32.x86_64

Release history Release notifications | RSS feed

This release

1.0a1 This release

2 release files

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