Validator Registry¶
The registry holds the parsers and checks a schema resolves by name.
Registry¶
Registry is the public entry point. It groups four ValidatorRegistry instances,
one per validator kind.
nyctea.validators.registry.Registry
¶
Bases: BaseModel
Registry containing all validator types.
Attributes:
| Name | Type | Description |
|---|---|---|
column_parsers |
ValidatorRegistry[ColumnParser]
|
Registry for column parser validators. |
column_checks |
ValidatorRegistry[ColumnCheck]
|
Registry for column check validators. |
frame_parsers |
ValidatorRegistry[FrameParser]
|
Registry for frame parser validators. |
frame_checks |
ValidatorRegistry[FrameCheck]
|
Registry for frame check validators. |
Source code in src/nyctea/validators/registry.py
__repr__()
¶
Return string representation of registry.
Source code in src/nyctea/validators/registry.py
get_validator_counts()
¶
Get count of validators in each registry.
Returns:
| Type | Description |
|---|---|
dict[str, int]
|
Dictionary mapping registry name to validator count. |
Source code in src/nyctea/validators/registry.py
register_column_check(validator)
¶
Register a column check validator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
validator
|
ColumnCheck
|
Column check to register. |
required |
register_column_parser(validator)
¶
Register a column parser validator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
validator
|
ColumnParser
|
Column parser to register. |
required |
register_frame_check(validator)
¶
Register a frame check validator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
validator
|
FrameCheck
|
Frame check to register. |
required |
register_frame_parser(validator)
¶
Register a frame parser validator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
validator
|
FrameParser
|
Frame parser to register. |
required |
ValidatorRegistry¶
nyctea.validators.registry.ValidatorRegistry
¶
Bases: Generic[T]
Type-safe registry for a specific validator type.
Attributes:
| Name | Type | Description |
|---|---|---|
validator_type |
The class of validators this registry accepts. |
Source code in src/nyctea/validators/registry.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 | |
__init__(validator_type)
¶
Initialize a validator registry for a specific type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
validator_type
|
type[T]
|
The class of validators this registry will accept. |
required |
Source code in src/nyctea/validators/registry.py
__len__()
¶
__repr__()
¶
get(name)
¶
Get a validator by name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Validator name to lookup. |
required |
Returns:
| Type | Description |
|---|---|
T
|
The validator instance. |
Raises:
| Type | Description |
|---|---|
KeyError
|
If no validator with that name is registered. |
Source code in src/nyctea/validators/registry.py
get_by_tag(tag)
¶
Get all validators with a specific tag.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tag
|
str
|
Tag to search for. |
required |
Returns:
| Type | Description |
|---|---|
list[T]
|
A copy of the validators with that tag, empty if none found. A copy so a |
list[T]
|
caller cannot reach into the registry's own index, the way |
list[T]
|
|
Source code in src/nyctea/validators/registry.py
has(name)
¶
list_all()
¶
list_names()
¶
register(validator)
¶
Register a validator instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
validator
|
T
|
The validator to register. |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
If validator is not of the correct type. |
RegistrationError
|
If a validator with the same name is already registered. |
Source code in src/nyctea/validators/registry.py
Decorators¶
nyctea.validators.decorators.checker(func=None, *, name=None, description='', version='1.0.0', tags=None, author='', registry=None)
¶
Declare a function as a column check.
Works bare (@checker), which infers the check's name from the function, or
parameterized (@checker(...)) for an explicit name or the rest of the
contract. Arguments after name are keyword-only and are checked against a
schema's arguments before any data is read.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
_ColumnFn | None
|
The decorated function. Only present for the bare form; leave it out and call with keyword arguments for the parameterized form. |
None
|
name
|
str | None
|
Check name. Bare form infers it from the function's |
None
|
description
|
str
|
Human-readable description. Defaults to the function's docstring. |
''
|
version
|
str
|
Validator version. |
'1.0.0'
|
tags
|
Sequence[str] | None
|
Optional tags for discovery. |
None
|
author
|
str
|
Validator author. |
''
|
registry
|
Registry | None
|
Register immediately into this registry. Without it the check is
declared into |
None
|
Returns:
| Type | Description |
|---|---|
Any
|
The function unchanged (bare form), or a decorator that returns it unchanged |
Any
|
(parameterized form). |
Source code in src/nyctea/validators/decorators.py
nyctea.validators.decorators.parser(func=None, *, name=None, description='', version='1.0.0', tags=None, author='', registry=None)
¶
Declare a function as a column parser.
Works bare (@parser), which infers the parser's name from the function, or
parameterized (@parser(...)) for an explicit name or the rest of the contract.
Arguments after name are keyword-only and are checked against a schema's
arguments before any data is read.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
_ColumnFn | None
|
The decorated function. Only present for the bare form; leave it out and call with keyword arguments for the parameterized form. |
None
|
name
|
str | None
|
Parser name. Bare form infers it from the function's |
None
|
description
|
str
|
Human-readable description. Defaults to the function's docstring. |
''
|
version
|
str
|
Validator version. |
'1.0.0'
|
tags
|
Sequence[str] | None
|
Optional tags for discovery. |
None
|
author
|
str
|
Validator author. |
''
|
registry
|
Registry | None
|
Register immediately into this registry. Without it the parser is
declared into |
None
|
Returns:
| Type | Description |
|---|---|
Any
|
The function unchanged (bare form), or a decorator that returns it unchanged |
Any
|
(parameterized form). |
Source code in src/nyctea/validators/decorators.py
nyctea.validators.decorators.frame_checker(func=None, *, name=None, description='', version='1.0.0', tags=None, author='', registry=None)
¶
Declare a function as a frame check.
Works bare (@frame_checker), which infers the check's name from the function,
or parameterized (@frame_checker(...)) for an explicit name or the rest of the
contract. Arguments after name are keyword-only and are checked against a
schema's arguments before any data is read.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
_FrameFn | None
|
The decorated function. Only present for the bare form; leave it out and call with keyword arguments for the parameterized form. |
None
|
name
|
str | None
|
Check name. Bare form infers it from the function's |
None
|
description
|
str
|
Human-readable description. Defaults to the function's docstring. |
''
|
version
|
str
|
Validator version. |
'1.0.0'
|
tags
|
Sequence[str] | None
|
Optional tags for discovery. |
None
|
author
|
str
|
Validator author. |
''
|
registry
|
Registry | None
|
Register immediately into this registry. Without it the check is
declared into |
None
|
Returns:
| Type | Description |
|---|---|
Any
|
The function unchanged (bare form), or a decorator that returns it unchanged |
Any
|
(parameterized form). |
Source code in src/nyctea/validators/decorators.py
nyctea.validators.decorators.frame_parser(func=None, *, name=None, description='', version='1.0.0', tags=None, author='', registry=None)
¶
Declare a function as a frame parser.
Works bare (@frame_parser), which infers the parser's name from the function,
or parameterized (@frame_parser(...)) for an explicit name or the rest of the
contract. Arguments after name are keyword-only and are checked against a
schema's arguments before any data is read.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
_FrameFn | None
|
The decorated function. Only present for the bare form; leave it out and call with keyword arguments for the parameterized form. |
None
|
name
|
str | None
|
Parser name. Bare form infers it from the function's |
None
|
description
|
str
|
Human-readable description. Defaults to the function's docstring. |
''
|
version
|
str
|
Validator version. |
'1.0.0'
|
tags
|
Sequence[str] | None
|
Optional tags for discovery. |
None
|
author
|
str
|
Validator author. |
''
|
registry
|
Registry | None
|
Register immediately into this registry. Without it the parser is
declared into |
None
|
Returns:
| Type | Description |
|---|---|
Any
|
The function unchanged (bare form), or a decorator that returns it unchanged |
Any
|
(parameterized form). |