Skip to main content

ReLePy

PyPI Python CI License: MIT

ReLePy is a modular reinforcement learning library for Python with a small, consistent API: build an agent, fit it, predict with it, evaluate it, save / load it. Every algorithm has a typed, validated configuration object, so hyperparameters are explicit and experiments are reproducible, from tabular Q-learning to SAC.

from relepy import DQN

agent = DQN("CartPole-v1", learning_rate=1e-3, double_dqn=True, seed=42)
agent.fit(total_timesteps=30_000)

mean_reward, std_reward = agent.evaluate(n_episodes=10)
action = agent.predict(observation)          # single observation in, action out
agent.save("cartpole.relepy")

Installation

pip install relepy            # tabular methods (NumPy + Gymnasium)
pip install "relepy[torch]"   # + deep RL algorithms (PyTorch)

From source: pip install -e ".[torch,dev]".

Algorithms

Family Algorithms Observations Actions
Tabular QLearning, SARSA, ExpectedSARSA Discrete Discrete
Value-based DQN, DoubleDQN, DuelingDQN Box / Discrete Discrete
Policy gradient REINFORCE, A2C, PPO Box / Discrete Discrete / Box
Off-policy actor-critic DDPG, TD3, SAC Box / Discrete Box (bounded)

All algorithms support several parallel environments (n_envs).

Parallel environments

from relepy import PPO

agent = PPO("CartPole-v1", n_envs=8, n_steps=128, batch_size=256, seed=0)
agent.fit(100_000)

Pass an env id or a factory (lambda: gym.make("CartPole-v1")) when n_envs > 1. Timestep budgets always count steps summed over all environments.

Building agents by name

import relepy

relepy.list_algorithms()                   # ['a2c', 'ddpg', 'double_dqn', 'dqn', ...]
agent = relepy.make("sac", "Pendulum-v1", seed=0)
agent = relepy.load("model.relepy", "Pendulum-v1")   # algorithm is read from the file

Your own agents can join the registry with @relepy.register("my_algo"); see examples/custom_algorithm.py.

Hyperparameters

Pass them as keyword arguments or as a config object (validated on creation, serializable to JSON):

from relepy import PPO, PPOConfig

config = PPOConfig(n_steps=1024, batch_size=64, clip_range=0.2, hidden_sizes=(128, 128))
config.to_json("ppo.json")                       # reproducible experiments
agent = PPO("Pendulum-v1", config, seed=0)
agent = PPO("Pendulum-v1", config, seed=0, n_epochs=5)  # keyword arguments override the config

Callbacks

from relepy import DQN, CheckpointCallback, EvalCallback

agent.fit(
    50_000,
    callbacks=[
        EvalCallback("CartPole-v1", eval_freq=5_000, best_model_path="best.relepy",
                     reward_threshold=475),
        CheckpointCallback(save_freq=10_000, save_dir="checkpoints"),
    ],
)

Write your own by subclassing relepy.Callback; return False from on_step to stop training. Training statistics are kept in agent.logger.history (a list of dicts).

Design

  • Components: a Collector does all environment interaction; shared training-loop templates (StepwiseAgent, OffPolicyAgent, OnPolicyAgent) and loss functions (relepy.core.losses) keep each algorithm short. See docs/index.md.
  • Works with any Gymnasium environment (id, factory or instance).
  • Discrete observations are one-hot encoded for neural agents; Box observations are flattened.
  • Time-limit truncation is handled correctly: value targets still bootstrap when an episode is truncated, and only true termination zeroes the bootstrap.
  • Safe model files: .relepy files are ZIP archives of JSON and NumPy arrays; loading never executes code. Files from 0.1.x need allow_legacy_pickle=True once.

Benchmarks

pip install -e ".[torch,benchmark]"
python benchmarks/run_benchmarks.py --suite quick --seeds 0 1 2

Results (CSV, learning curves, Markdown summary) are written to benchmark_results/.

Development

pip install -e ".[torch,dev]"
ruff check src tests examples benchmarks
mypy src
pytest                    # fast tests
pytest -m slow            # learning tests (minutes)

See CONTRIBUTING.md for adding algorithms and making releases, and CHANGELOG.md for what changed between versions.

Roadmap

Prioritized replay and n-step returns, observation/reward normalization, CNN and recurrent policies, more algorithms (classic DP/Monte-Carlo/bandits, Rainbow, TRPO, TQC, offline RL).

License

MIT

Metadata

Release files for relepy 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for relepy 0.2.0
File Size Uploaded Provenance Actions
relepy-0.2.0.tar.gz 55.2 kB With provenance Details for relepy-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for relepy 0.2.0
File Interpreter ABI Platform Actions
relepy-0.2.0-py3-none-any.whl Python 3 none any Details for relepy-0.2.0-py3-none-any.whl

Total release size: 113.1 kB

Release files / relepy-0.2.0.tar.gz

Download URL relepy-0.2.0.tar.gz
Size 55.2 kB
Tags Source
SHA-256 checksum
How to use checksums
8ee85bccb838eecc1d5e18fc76004281d7bf87eb2e6aefceab2f982ba226d218
BLAKE2b-256 checksum
How to use checksums
8c0877a513e350a66b4faea86e2a330fe5cf3dd1ca520da29b5ff0bbb37ea607
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 10, 2026.

Transparency log

Release files / relepy-0.2.0-py3-none-any.whl

Download URL relepy-0.2.0-py3-none-any.whl
Size 57.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ae5fc37663199e53176a3fb6db1542279803203b9846fc9299e9ce3bc82d1ee7
BLAKE2b-256 checksum
How to use checksums
dcd77da24a62f29c65a2638286b56de90b2842e0356e00eee24d08ae57c165c1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 10, 2026.

Transparency log

Security for relepy 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for relepy-0.2.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 10, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page