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.0.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.0-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: seedall-0.2.0.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.0.tar.gz
Algorithm Hash digest
SHA256 e5ce94e9ef7585cadc89d760976465760d98193fe7028a1bc322348e1f17e131
MD5 75109e450cf9174fe52d1010e59fed42
BLAKE2b-256 ba6e695e34a310e27c5c9fb58ccd12f104cf49456f6e363c37ffd6f1cfe5d289

See more details on using hashes here.

Provenance

The following attestation bundles were made for seedall-0.2.0.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.0-py3-none-any.whl.

File metadata

  • Download URL: seedall-0.2.0-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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7246c5f8687b60ea9d9232eae5bcddc6c9206ad5ed0fb1d2d80a2b9c5abaea4c
MD5 dccdb03b04dee389e5a82123b476e2bf
BLAKE2b-256 bc820fc25223b336c51f03215a7050ba7a1b29a6bacbdaf955ff9c4b79af3136

See more details on using hashes here.

Provenance

The following attestation bundles were made for seedall-0.2.0-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