A Python library for creating type-safe, self-validating value objects using a powerful transformation and validation pipeline.
Project description
Constrained Values
A lightweight Python library for creating type-safe, self-validating value objects — transforming primitive data into meaningful, domain-aware objects with rich validation and transformation pipelines.
🧭 Philosophy: Beyond Primitive Types
In most codebases, we pass around raw values without context:
- Is
temperature = 25Celsius or Fahrenheit? - Is
spi_mode = 2valid for this device? - What does
-32768mean again?
Primitive values lack meaning, constraints, and domain intent.
This is Primitive Obsession — a subtle but pervasive design smell.
Constrained Values replaces primitives with expressive, validated objects that make validity explicit.
Each object carries its status (OK or EXCEPTION) and associated errors.
By default, invalid values can exist safely and report their state — but if you want to enforce strict invariants, you can enable exception mode to raise immediately on invalid input.
✨ Features
- 🧩 Rich Value Objects – Replace primitives with expressive, validated domain objects.
- 🔗 Composable Pipelines – Chain multiple validation and transformation strategies.
- 🧠 Built-in Validators – Range checks, enums, type coercion, and more.
- ⚙️ Custom Logic – Easily extend with your own domain-specific rules.
- 🚦 Clear Error Handling – Track validation status and descriptive messages.
- 🧯 Strict/Exception Mode (optional) – By default, invalid values are reported non-destructively; enable strict mode to raise exceptions and enforce invariants at creation.
- 🧾 Type-Safety – Each value enforces its canonical type at runtime.
🚀 Installation
pip install constrained-values
💡 Quick Example
from constrained_values import ConstrainedValue, Range, CoerceType
class Temperature(ConstrainedValue[int]):
__validators__ = [
CoerceType(int),
Range(min=0, max=100, message="Temperature must be between 0°C and 100°C")
]
t = Temperature(42)
print(t.value) # ✅ 42
print(t.status) # OK
t_invalid = Temperature(120)
print(t_invalid.status) # EXCEPTION
print(t_invalid.errors) # ['Temperature must be between 0°C and 100°C']
# Enable strict mode
t_strict = Temperature(120, throw=True) # Raises ValueError
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 constrained_values-0.1.5.tar.gz.
File metadata
- Download URL: constrained_values-0.1.5.tar.gz
- Upload date:
- Size: 25.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a719d84f3264f7500722228846a7d476c6e55f2b4244c4ce5cd44106b2553c34
|
|
| MD5 |
ab76c3d3fbb09cec4b0c1004461dba88
|
|
| BLAKE2b-256 |
7d80eae15a9df0ea71429c0ad9b6ebf38c5dfa5d4ca6ede2dad122ce138087f5
|
Provenance
The following attestation bundles were made for constrained_values-0.1.5.tar.gz:
Publisher:
publish-pypi.yml on OODesigns/constrained-values
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
constrained_values-0.1.5.tar.gz -
Subject digest:
a719d84f3264f7500722228846a7d476c6e55f2b4244c4ce5cd44106b2553c34 - Sigstore transparency entry: 641879722
- Sigstore integration time:
-
Permalink:
OODesigns/constrained-values@f70d0b4476f3c93e2de8fa7037679c0403e173f4 -
Branch / Tag:
refs/heads/master - Owner: https://github.com/OODesigns
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@f70d0b4476f3c93e2de8fa7037679c0403e173f4 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file constrained_values-0.1.5-py3-none-any.whl.
File metadata
- Download URL: constrained_values-0.1.5-py3-none-any.whl
- Upload date:
- Size: 15.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cfd558a0bb3a035d0f63ee109c951a9617c0e9abd7288bc32c9089749b37efe1
|
|
| MD5 |
68b677c731918f170a6550ed008de4eb
|
|
| BLAKE2b-256 |
fd687f6574bc9fae4aae05cd2a2170eaf5e2dbd0b2a70fbd61a465ee5e2e6b7e
|
Provenance
The following attestation bundles were made for constrained_values-0.1.5-py3-none-any.whl:
Publisher:
publish-pypi.yml on OODesigns/constrained-values
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
constrained_values-0.1.5-py3-none-any.whl -
Subject digest:
cfd558a0bb3a035d0f63ee109c951a9617c0e9abd7288bc32c9089749b37efe1 - Sigstore transparency entry: 641879723
- Sigstore integration time:
-
Permalink:
OODesigns/constrained-values@f70d0b4476f3c93e2de8fa7037679c0403e173f4 -
Branch / Tag:
refs/heads/master - Owner: https://github.com/OODesigns
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@f70d0b4476f3c93e2de8fa7037679c0403e173f4 -
Trigger Event:
workflow_dispatch
-
Statement type: