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.2.tar.gz (4.6 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.2-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: seedall-0.2.2.tar.gz
  • Upload date:
  • Size: 4.6 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.2.tar.gz
Algorithm Hash digest
SHA256 bf73105d9d4784456a1793e6c3cb9fbe0a3999cdb349c4243f2f96aefb003a8a
MD5 b55c977af50a4a539095a59047b53447
BLAKE2b-256 89d8d0eb3e8d5677bd79ed5fd9941e9897c08d20f0cbc179dbfe359f2bb7717d

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: seedall-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 5.7 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b0427c375ba26868d20791057fba19bff0dde784cb5fb9aacf782d722ac87a06
MD5 8f54d4851c34dd549563bc12a446d62e
BLAKE2b-256 5b80fd404ef39e5b3dfd1a767df88a86a232ed392eda5ce488dba4c72c0254a6

See more details on using hashes here.

Provenance

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