Skip to main content

A framework to check if Pydantic models are bounded

Project description

Bounded Models

PyPI PyPI - License PyPI - Python Version Test Status Documentation uv Ruff

[!WARNING] This project is in early development. The API may change significantly.

A framework to check if Pydantic models are "bounded" and enable uniform sampling from constrained spaces.

Installation

pip install bounded-models
# or
uv add bounded-models

Quick Start

from typing import Literal
from bounded_models import FieldHandlerRegistry
from pydantic import BaseModel, Field

class Config(BaseModel):
    mode: Literal["fast", "slow"]
    threshold: float = Field(ge=0.0, le=1.0)
    count: int = Field(ge=1, le=10)

registry = FieldHandlerRegistry.default()

registry.check_model_boundedness(Config)  # True
registry.model_dimensions(Config)  # 3

# Sample from unit hypercube [0, 1]^dim
registry.sample_model([0.5, 0.5, 0.5], Config)
# Config(mode='slow', threshold=0.5, count=5)

Supported Field Types

Type Example
Numeric (int, float) Field(ge=0, le=10)
Literal Literal["a", "b", "c"]
Enum class Color(Enum): ...
Nested BaseModel BoundedModel subclasses

Documentation

For detailed usage, see the documentation.

License

MIT

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

bounded_models-0.0.5.tar.gz (10.8 kB view details)

Uploaded Source

Built Distribution

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

bounded_models-0.0.5-py3-none-any.whl (12.6 kB view details)

Uploaded Python 3

File details

Details for the file bounded_models-0.0.5.tar.gz.

File metadata

  • Download URL: bounded_models-0.0.5.tar.gz
  • Upload date:
  • Size: 10.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for bounded_models-0.0.5.tar.gz
Algorithm Hash digest
SHA256 2d548faaf8f0cf0710bcb321eb5f53bb814fdc24a6a64dc6fc6a392820d8201c
MD5 36dd9c43e1d610b88c00e7719a44357a
BLAKE2b-256 bfd9488c593ea927f01cfdf8ff8724ae17d41abbe0d3a11c6d90cfe4c4907a4c

See more details on using hashes here.

Provenance

The following attestation bundles were made for bounded_models-0.0.5.tar.gz:

Publisher: release.yaml on shunichironomura/bounded-models

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

File details

Details for the file bounded_models-0.0.5-py3-none-any.whl.

File metadata

  • Download URL: bounded_models-0.0.5-py3-none-any.whl
  • Upload date:
  • Size: 12.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for bounded_models-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 219823e57ee9797ebafc301eac218ecd44888914d6f74c9a3e81c77913a1de48
MD5 4cc9df7e78a25ce2e33e113a0d45c7ef
BLAKE2b-256 54063358b28569d43fd63374cd492b4372f1c5caa140aab894a245062b92c433

See more details on using hashes here.

Provenance

The following attestation bundles were made for bounded_models-0.0.5-py3-none-any.whl:

Publisher: release.yaml on shunichironomura/bounded-models

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