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
constrainedand up-to-date (08/2023);pip install annotated-types) - Constrained Types
Metadata
Release files for constrained 0.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| constrained-0.0.0.tar.gz | 3.2 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| constrained-0.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 7.4 kB
Release files / constrained-0.0.0.tar.gz
| Download URL | constrained-0.0.0.tar.gz |
|---|---|
| Size | 3.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
120e00a6e90c85d0f446e6922709a2c5606558c32f81afc90444b6c5e39316b6
|
|
BLAKE2b-256 checksum How to use checksums |
937d252397c0f1c2b3f9f3db2552b0a1c3373293f8aa708c88556737b6abe0e2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.4.1 CPython/3.10.9 Linux/5.15.0-76-lowlatency
|
Release files / constrained-0.0.0-py3-none-any.whl
| Download URL | constrained-0.0.0-py3-none-any.whl |
|---|---|
| Size | 4.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a048cda74a979be60b048fce1c67a6b70b0ccdabbc1a7bfe2930fafc7d68d07e
|
|
BLAKE2b-256 checksum How to use checksums |
bf7295bcdf1ffe1d1e9e9dfa94d34b70d54844260e3d8ad28f75a16b494a42fd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.4.1 CPython/3.10.9 Linux/5.15.0-76-lowlatency
|
Security for constrained 0.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.