A Python library for enforcing type, range, and lexical constraints.
Project description
Constrained
:caution: Not working; not maintained. Use annotated-types instead. :caution:
A Python library for enforcing type and range constraints.
Features
- Float and Int types with range constraints
- Regex type for string matching
- CFG type for context-free grammar matching
- enforce_annotation_constraints decorator to enforce constraints
Installation
pip install constrained
Usage
First, import the necessary types and the decorator from the constrained
module:
from constrained import Float, Int, Regex, CFG, enforce_annotation_constraints
Then, define your function with type annotations:
@enforce_annotation_constraints
def P(x: Float[0, 'inf']) -> Float[0, 'inf']:
return x / 2
The decorator will enforce the constraints at runtime and raise a ValueError if any argument or the return value does not match the constraints defined in the function's signature.
Alternatives
- annotated-types (much better than
constrained
and up-to-date (08/2023);pip install annotated-types
) - Constrained Types
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
constrained-0.0.0.tar.gz
(3.2 kB
view details)
Built Distribution
File details
Details for the file constrained-0.0.0.tar.gz
.
File metadata
- Download URL: constrained-0.0.0.tar.gz
- Upload date:
- Size: 3.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.4.1 CPython/3.10.9 Linux/5.15.0-76-lowlatency
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 120e00a6e90c85d0f446e6922709a2c5606558c32f81afc90444b6c5e39316b6 |
|
MD5 | 24c1dee55f97a8342c2a2dfb68b5299c |
|
BLAKE2b-256 | 937d252397c0f1c2b3f9f3db2552b0a1c3373293f8aa708c88556737b6abe0e2 |
File details
Details for the file constrained-0.0.0-py3-none-any.whl
.
File metadata
- Download URL: constrained-0.0.0-py3-none-any.whl
- Upload date:
- Size: 4.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.4.1 CPython/3.10.9 Linux/5.15.0-76-lowlatency
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a048cda74a979be60b048fce1c67a6b70b0ccdabbc1a7bfe2930fafc7d68d07e |
|
MD5 | ec80ac4d03c6191cecc43baf316ff523 |
|
BLAKE2b-256 | bf7295bcdf1ffe1d1e9e9dfa94d34b70d54844260e3d8ad28f75a16b494a42fd |