Skip to content

Validator

Validator class for document-level validation on Stores. Attach an instance of a Validator subclass to a Store .schema variable to enable validation on that Store.

Validator

Bases: MSONable

A generic class to perform document-level validation on Stores. Attach a Validator to a Store during initialization, any all documents added to the Store will call .validate_doc() before being added.

Source code in src/maggma/core/validator.py
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
class Validator(MSONable, metaclass=ABCMeta):
    """
    A generic class to perform document-level validation on Stores.
    Attach a Validator to a Store during initialization, any all documents
    added to the Store will call .validate_doc() before being added.
    """

    @abstractmethod
    def is_valid(self, doc: dict) -> bool:
        """
        Determines if the document is valid.

        Args:
            doc: document to check
        """

    @abstractmethod
    def validation_errors(self, doc: dict) -> list[str]:
        """
        If document is not valid, provides a list of
        strings to display for why validation has failed.

        Returns empty list if the document is valid

        Args:
            doc:  document to check
        """

is_valid(doc) abstractmethod

Determines if the document is valid.

Parameters:

Name Type Description Default
doc dict

document to check

required
Source code in src/maggma/core/validator.py
19
20
21
22
23
24
25
26
@abstractmethod
def is_valid(self, doc: dict) -> bool:
    """
    Determines if the document is valid.

    Args:
        doc: document to check
    """

validation_errors(doc) abstractmethod

If document is not valid, provides a list of strings to display for why validation has failed.

Returns empty list if the document is valid

Parameters:

Name Type Description Default
doc dict

document to check

required
Source code in src/maggma/core/validator.py
28
29
30
31
32
33
34
35
36
37
38
@abstractmethod
def validation_errors(self, doc: dict) -> list[str]:
    """
    If document is not valid, provides a list of
    strings to display for why validation has failed.

    Returns empty list if the document is valid

    Args:
        doc:  document to check
    """