Skip to main content

Programmatic parameter sweeps for pydantic.

Project description

pydantic-sweep

pydantic_sweep is a library to programmatically, safely and flexibly define complex parameter sweeps over pydantic models in Python.

PyPI - Version Static Badge GitHub branch check runs GitHub License

Highlights:

  • Specify parameter sweeps in Python
  • Flexibility: specify complex parameter combinations by chaining simple operations
  • Safety checks for parameter combinations (get meaningful errors early)
  • pydantic field validation

For example, the following code will instantiate models with (x=5, y=1) and (x=6, y=2) and try each of those with seed values of seed=43 and seed=44, leading to four different configurations:

import pydantic_sweep as ps

class Model(ps.BaseModel):
    seed: int = 42
    x: int = 5
    y: int

models = ps.initialize(
    Model, 
    ps.config_product(
        ps.field("seed", [43, 44]),
        ps.config_zip(
            ps.field("x", [ps.DefaultValue, 6]),
            ps.field("y", [1, 2]),
        )
    )
)

# The code above is equivalent to
models = [
    Model(seed=43, x=5, y=1), 
    Model(seed=43, x=6, y=2), 
    Model(seed=44, x=5, y=1), 
    Model(seed=44, x=6, y=2),
]

# check that we didn't accidentally duplicate a setting
ps.check_unique(models)

To learn mode about the full capabilities of the library visit the documentation page.

Installation

You can install the library by checking out the repo and running

pip install 'pydantic-sweep'

License

The main code-base is licensed under MPL-2.0 a weak copy-left license that allows commercial use. See the license file for the exact clauses and this FAQ for a high-level description.

An exception from this are the documentation in the docs and example folders as well as this README file, which are licensed under the 0BSD: a highly permissive license that does not require attribution. That way, you are free to copy & paste example code into your use-case. See here for a high-level description.

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

pydantic_sweep-0.3.2.tar.gz (116.4 kB view details)

Uploaded Source

Built Distribution

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

pydantic_sweep-0.3.2-py3-none-any.whl (17.7 kB view details)

Uploaded Python 3

File details

Details for the file pydantic_sweep-0.3.2.tar.gz.

File metadata

  • Download URL: pydantic_sweep-0.3.2.tar.gz
  • Upload date:
  • Size: 116.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for pydantic_sweep-0.3.2.tar.gz
Algorithm Hash digest
SHA256 e319a8810413568e2e1d531a88953b11dd5a71a01d5b52d494f6defa8d389f0b
MD5 629b5c5d0a7bcafa8dbe8a0ee36e75cf
BLAKE2b-256 5980791bdbc3b8ff228bed3dc7e2de9c6e39e15080e9b318aefe049e191289c4

See more details on using hashes here.

Provenance

The following attestation bundles were made for pydantic_sweep-0.3.2.tar.gz:

Publisher: release.yml on befelix/pydantic_sweep

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

File details

Details for the file pydantic_sweep-0.3.2-py3-none-any.whl.

File metadata

  • Download URL: pydantic_sweep-0.3.2-py3-none-any.whl
  • Upload date:
  • Size: 17.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for pydantic_sweep-0.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 9c4e7879c06e0c2a60a0660901ad5aace0fd6e8535ed04789ac33289c9c62c60
MD5 d9009744a601478488cccd3c464de01e
BLAKE2b-256 77197236f4ba1b9b732d2c97ce64cb5a15748dc992b44a6a2d7bedd827c1b344

See more details on using hashes here.

Provenance

The following attestation bundles were made for pydantic_sweep-0.3.2-py3-none-any.whl:

Publisher: release.yml on befelix/pydantic_sweep

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