Skip to main content

Seed all common RNGs in one call for reproducible experiments.

Project description

seedall

Seed all common RNGs in one call for reproducible experiments.

import seedall

seedall.seed(42)  # seeds random, numpy, torch, tensorflow, jax, cupy — whatever is installed

Supported backends

Backend What gets seeded
random Python stdlib random
hashseed PYTHONHASHSEED env var
numpy np.random.seed()
torch torch.manual_seed() + cuda.manual_seed_all()
tensorflow tf.random.set_seed()
jax Creates a jax.random.PRNGKey (retrieve via states API)
cupy cp.random.seed()

Missing libraries are silently skipped — install only what you need.

API

seedall.seed(value, *, backends=None, deterministic=False, warn_missing=False)

Seed all (or selected) backends. Returns dict[str, bool] showing what was seeded.

# Seed everything
seedall.seed(42)

# Seed only specific backends
seedall.seed(42, backends=["numpy", "torch"])

# Also enable PyTorch deterministic mode (slower but fully reproducible)
seedall.seed(42, deterministic=True)

seedall.temp_seed(value, *, deterministic=False)

Context manager — seeds on entry, restores previous RNG states on exit.

with seedall.temp_seed(0):
    x = np.random.rand(100)   # reproducible
y = np.random.rand(100)       # back to original sequence

seedall.available()

List detected backends:

>>> seedall.available()
['random', 'hashseed', 'numpy', 'torch']

seedall.get_states() / seedall.set_states(states)

Snapshot and restore RNG states manually:

states = seedall.get_states()
# ... do stuff ...
seedall.set_states(states)  # rewind

seedall.SeedContext(value)

Class-based alternative when a context manager isn't convenient:

ctx = seedall.SeedContext(42)
ctx.enter()   # seed
# ... run experiment ...
ctx.exit()    # restore

Install

pip install seedall                # core (stdlib random only)
pip install seedall[numpy]         # + numpy
pip install seedall[torch]         # + pytorch
pip install seedall[all]           # everything

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

seedall-0.2.1.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

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

seedall-0.2.1-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

Details for the file seedall-0.2.1.tar.gz.

File metadata

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

File hashes

Hashes for seedall-0.2.1.tar.gz
Algorithm Hash digest
SHA256 7d36a0abf9bcb5e64c77b3f63ea41d3629f5248047cb809c32cf52fb903c8750
MD5 cc7d7d3ea697223ada50d858bdb70622
BLAKE2b-256 4d175c0f15a3fa1a6ae28069b5ceb51a4fbbceaf1a211f1ac203dfd9ecdb12ce

See more details on using hashes here.

Provenance

The following attestation bundles were made for seedall-0.2.1.tar.gz:

Publisher: python-publish.yml on jdhouseholder/seedall

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

File details

Details for the file seedall-0.2.1-py3-none-any.whl.

File metadata

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

File hashes

Hashes for seedall-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 44790e015f6869ec69231ba4e2f452a8ff0c261fc106f390760ffff098247cad
MD5 50b2ff5599b7a6664cc276b731a111bd
BLAKE2b-256 deca088e00fe6855e4d2ade8790d61242f5bc768c54a19e6d798bffa5c34349e

See more details on using hashes here.

Provenance

The following attestation bundles were made for seedall-0.2.1-py3-none-any.whl:

Publisher: python-publish.yml on jdhouseholder/seedall

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