Type validation in labrea with pydantic.
Project description
Labrea Type Validation
Type validation for labrea using pydantic
Installation
labrea-type-validation is available for install via pip.
pip install labrea-type-validation
Alternatively, you can install the latest development version from GitHub.
pip install git+https://github.com/8451/labrea-type-validation@develop
Usage
When creating an Option with labrea, specify the expected type using either of the following syntaxes:
from labrea import Option
X = Option("X", type=int)
Y = Option[int]("Y")
Either literal types or type hints can be used, such as List[int] or Union[str, List[str]].
To enable type validation, simply import labrea_type_validation and call the enable function:
import labrea_type_validation
X({"X": "1"}) # No error
labrea_type_validation.enable()
X({"X": "1"})
# ...
# TypeError: Expected type <class 'int'> but got <class 'str'> ('1')
#
# The above exception was the direct cause of the following exception:
#
# Traceback (most recent call last):
# ...
# labrea.exceptions.EvaluationError: Originating in Option('X') | Error during evaluation
Type validation can also be used in a with statement as a context manager using enabled.
with labrea_type_validation.enabled():
X({"X": "1"})
# ...
# TypeError: Expected type <class 'int'> but got <class 'str'> ('1')
#
# The above exception was the direct cause of the following exception:
#
# Traceback (most recent call last):
# ...
# labrea.exceptions.EvaluationError: Originating in Option('X') | Error during evaluation
Alternatively, the LABREA_TYPE_VALIDATION_ENABLED environment variable can be set to TRUE.
Multithreaded Applications
Type validation is based on the labrea.runtime module. For this reason, type validation is
enabled for the current thread and any threads spawned from it. If you are using a multithreaded
application, ensure that type validation is enabled in the main thread before spawning any new
threads.
Contributing
If you would like to contribute to labrea-type-validation, please read the Contributing Guide.
Changelog
A summary of recent updates to labrea-type-validation can be found in the Changelog.
Maintainers
| Maintainer | |
|---|---|
| Austin Warner | austin.warner@8451.com |
| Michael Stoepel | michael.stoepel@8451.com |
Links
- Report a bug or request a feature: https://github.com/8451/labrea-type-validation/issues/new/choose
- Documentation: https://8451.github.io/labrea-type-validation
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file labrea_type_validation-0.0.1.tar.gz.
File metadata
- Download URL: labrea_type_validation-0.0.1.tar.gz
- Upload date:
- Size: 201.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f9229be64c3ed02e875e23c5ad7ed46a993a1ba7fb61ed527272629ca8f8b62f
|
|
| MD5 |
1992528d3da46b3285c0c1893e882512
|
|
| BLAKE2b-256 |
6318da0e4916e31ae7217e4d526c5d80950cbcc3927e1ad972677ad14dcc60b3
|
Provenance
The following attestation bundles were made for labrea_type_validation-0.0.1.tar.gz:
Publisher:
build-and-deploy.yml on 8451/labrea-type-validation
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
labrea_type_validation-0.0.1.tar.gz -
Subject digest:
f9229be64c3ed02e875e23c5ad7ed46a993a1ba7fb61ed527272629ca8f8b62f - Sigstore transparency entry: 208563519
- Sigstore integration time:
-
Permalink:
8451/labrea-type-validation@9d98967fb06368b4bdd4b46adfd0e344108a6626 -
Branch / Tag:
refs/tags/v0.0.1 - Owner: https://github.com/8451
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build-and-deploy.yml@9d98967fb06368b4bdd4b46adfd0e344108a6626 -
Trigger Event:
release
-
Statement type:
File details
Details for the file labrea_type_validation-0.0.1-py3-none-any.whl.
File metadata
- Download URL: labrea_type_validation-0.0.1-py3-none-any.whl
- Upload date:
- Size: 6.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
86a861d0a957aef0e2324b05d6a1a325520b47eb9071ce36480a4d4b7f82739a
|
|
| MD5 |
e1b33ac76e3ee370ff0f35ef28b9116e
|
|
| BLAKE2b-256 |
b8678d1080b5aa972019d647f4000eed862333f60793f02f0d44e775ce0f7998
|
Provenance
The following attestation bundles were made for labrea_type_validation-0.0.1-py3-none-any.whl:
Publisher:
build-and-deploy.yml on 8451/labrea-type-validation
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
labrea_type_validation-0.0.1-py3-none-any.whl -
Subject digest:
86a861d0a957aef0e2324b05d6a1a325520b47eb9071ce36480a4d4b7f82739a - Sigstore transparency entry: 208563520
- Sigstore integration time:
-
Permalink:
8451/labrea-type-validation@9d98967fb06368b4bdd4b46adfd0e344108a6626 -
Branch / Tag:
refs/tags/v0.0.1 - Owner: https://github.com/8451
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build-and-deploy.yml@9d98967fb06368b4bdd4b46adfd0e344108a6626 -
Trigger Event:
release
-
Statement type: