Python reinforcement learning libraries

Updated Nov 2026

Python reinforcement learning libraries train agents that learn a policy by acting in an environment and receiving rewards. A library supplies algorithms such as PPO, a training loop that collects rollouts, and wrappers that connect it to simulated environments. These libraries let robotics teams and researchers train control policies in simulation.

Popularity

RLlib has the most monthly downloads in this comparison, at 15.7M, a count that covers all of Ray.

LibraryMonthly downloadsStarsLast releaseLicense
RLlib
15.7M
44.3KNov 2026Apache-2.0
stable-baselines3
782.1K
14.0KOct 2026MIT
RSL-RL
506.4K
3.1KOct 2026BSD-3-Clause
SB3-Contrib
154.7K
746Oct 2026MIT
TorchRL
134.5K
3.6KNov 2026MIT
skrl
111.5K
1.1KNov 2026MIT
RLax
106.1K
1.5KJun 2026Apache-2.0
Tianshou
41.7K
11.1KApr 2026MIT
Downloads: PyPI, last thirty days. Stars and releases: GitHub. Amber: no release in over a year.

Libraries and code examples

Builds distributed applications through the Ray API.

Downloads / mo
15.7M
Stars
44.3K
Last release
2.60.0
License
Apache-2.0

Quickstart

From index.rst
$ pip install "ray[rllib]==2.60.0" torch
from ray.rllib.algorithms.ppo import PPOConfig
algo = PPOConfig().environment("CartPole-v1").env_runners(num_env_runners=0).build_algo()
try:
    print(algo.train())
finally:
    algo.stop()

stable-baselines3

Provides PyTorch reinforcement-learning algorithms with a shared training and prediction interface.

Downloads / mo
782.1K
Stars
14.0K
Last release
2.9.2
License
MIT

Strengths

  • Offers a compact training API. Create a policy, train it, then predict actions from observations.
  • Batches independent environments. Train against multiple environments in each step.

Limitations

  • Recurrent PPO needs another package. Use sb3-contrib for the recurrent PPO implementation.
  • Vector API differs from Gym. Handle automatic resets and the vector API’s different return values.

Quickstart

From README.md
$ pip install stable-baselines3==2.9.2
from stable_baselines3 import PPO
model = PPO("MlpPolicy", "CartPole-v1").learn(10_000)

Provides robot-learning runners, policy models, and student-teacher distillation.

Downloads / mo
506.4K
Stars
3.1K
Last release
5.5.2
License
BSD-3-Clause

Strengths

  • Trains student policies from teachers. Transfer privileged training observations into a deployable student policy.
  • Accepts custom component classes. Supply custom algorithms, models, or loggers through configuration.

Limitations

  • Custom environments need an adapter. Implement VecEnv before connecting a custom environment.
  • Observation buffers must stay unchanged. Keep returned tensors unchanged until rollout storage copies the transition.

Quickstart

From mlp.py
$ pip install rsl-rl-lib==5.5.2 torch==2.6.0
import torch
from rsl_rl.modules import MLP
network = MLP(input_dim=4, output_dim=2, hidden_dims=[8]).cpu()
observations = torch.zeros((1, 4), device="cpu")
print(network(observations).shape)

Adds experimental code to Stable Baselines3.

Downloads / mo
154.7K
Stars
746
Last release
2.9.2
License
MIT

Quickstart

From ppo_mask.rst
$ pip install sb3-contrib==2.9.2
from sb3_contrib import MaskablePPO
from sb3_contrib.common.envs import InvalidActionEnvDiscrete
env = InvalidActionEnvDiscrete(dim=80, n_invalid_actions=60)
model = MaskablePPO("MlpPolicy", env, verbose=1)
model.learn(5000)

SB3-Contrib examples

From open-source projects on GitHub

Provides modular PyTorch building blocks for reinforcement learning.

Downloads / mo
134.5K
Stars
3.6K
Last release
0.15.0
License
MIT
$ pip install torchrl==0.15.0 gymnasium
from torchrl.envs import GymEnv
env = GymEnv("CartPole-v1", device="cpu")
try:
    print(env.rollout(3))
finally:
    env.close()

Provides modular reinforcement-learning components with PyTorch, JAX, and Warp implementations.

Downloads / mo
111.5K
Stars
1.1K
Last release
2.1.2
License
MIT

Strengths

  • Supports multiple tensor frameworks. Choose PyTorch, JAX, or Warp for supported components.
  • Exposes model construction. Define policy and value networks with the supplied mixins.

Limitations

  • Models need explicit definitions. Define the approximation functions used by the agent’s models.
  • Parallel trainer keeps memory local. Agents in ParallelTrainer cannot share their memory buffers.
$ pip install skrl==2.1.2 gymnasium
from skrl.envs.wrappers.torch import wrap_env
import gymnasium as gym
env = gym.make("Pendulum-v1")
env = wrap_env(env)

Provides reinforcement learning building blocks in JAX.

Downloads / mo
106.1K
Stars
1.5K
Last release
0.1.9
License
Apache-2.0

Quickstart

From api.rst
$ pip install rlax==0.1.9
import jax.numpy as jnp
import rlax
error = rlax.q_learning(jnp.array([1.0, 2.0]), jnp.array(0), jnp.array(1.0), jnp.array(0.99), jnp.array([2.0, 3.0]))
print(error)

Provides tools for deep reinforcement learning.

Downloads / mo
41.7K
Stars
11.1K
Last release
2.0.1
License
MIT

Quickstart

From README.md
$ pip install tianshou==2.0.1
from tianshou.highlevel.config import OffPolicyTrainingConfig
from tianshou.highlevel.env import EnvFactoryRegistered, VectorEnvType
from tianshou.highlevel.experiment import DQNExperimentBuilder, ExperimentConfig
from tianshou.highlevel.params.algorithm_params import DQNParams
experiment = (
    DQNExperimentBuilder(
        EnvFactoryRegistered(task="CartPole-v1", venv_type=VectorEnvType.DUMMY, training_seed=0, test_seed=10),
        ExperimentConfig(persistence_enabled=False, watch=False),
        OffPolicyTrainingConfig(max_epochs=1, epoch_num_steps=100, batch_size=64, num_training_envs=1, num_test_envs=1, buffer_size=20000, collection_step_num_env_steps=10, update_step_num_gradient_steps_per_sample=0.1),
    )
    .with_dqn_params(DQNParams(lr=1e-3, gamma=0.9, n_step_return_horizon=3, target_update_freq=320, eps_training=0.3, eps_inference=0.0))
    .with_model_factory_default(hidden_sizes=(64, 64))
    .build()
)
experiment.run()

FAQ

stable-baselines3 suits training with maintained PyTorch algorithms behind one training and prediction interface. RLlib suits distributed and multi-agent training on Ray. TorchRL suits researchers who assemble their own PyTorch training loop.

stable-baselines3 is a set of PyTorch reinforcement learning algorithms with a shared training and prediction interface. Experimental algorithms live in the separate SB3-Contrib package.

Tianshou is a deep reinforcement learning library built on PyTorch and Gymnasium, with high-level experiment builders and a lower-level algorithm API.

RLax is a library of reinforcement learning building blocks in JAX. It supplies operations for building agents rather than complete algorithms.

TorchRL is a modular PyTorch library for reinforcement learning with replay buffers, data collectors, environments, and loss functions.

For coding agents

Found your reinforcement learning library? Help your agent use it.

Connect Exa so your coding agent can find the library’s documentation, check its API, and look up implementations while you build.

Run in your terminal

claude plugin install exa@claude-plugins-official