Skip to main content

Type validation in labrea with pydantic.

Project description

Labrea Type Validation

Type validation for labrea using pydantic

lifecycle PyPI Downloads pre-commit Coverage docs

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 Email
Austin Warner austin.warner@8451.com
Michael Stoepel michael.stoepel@8451.com

Links

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

labrea_type_validation-0.0.1.tar.gz (201.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

labrea_type_validation-0.0.1-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

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

Hashes for labrea_type_validation-0.0.1.tar.gz
Algorithm Hash digest
SHA256 f9229be64c3ed02e875e23c5ad7ed46a993a1ba7fb61ed527272629ca8f8b62f
MD5 1992528d3da46b3285c0c1893e882512
BLAKE2b-256 6318da0e4916e31ae7217e4d526c5d80950cbcc3927e1ad972677ad14dcc60b3

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file labrea_type_validation-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for labrea_type_validation-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 86a861d0a957aef0e2324b05d6a1a325520b47eb9071ce36480a4d4b7f82739a
MD5 e1b33ac76e3ee370ff0f35ef28b9116e
BLAKE2b-256 b8678d1080b5aa972019d647f4000eed862333f60793f02f0d44e775ce0f7998

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page