# Python reinforcement learning libraries

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

| Library | Monthly downloads | Stars | Last release | License |
| --- | --- | --- | --- | --- |
| [RLlib](#ray) | 15.7M | 44.3K | Nov 2026 | Apache-2.0 |
| [stable-baselines3](#stable-baselines) | 782.1K | 14.0K | Oct 2026 | MIT |
| [RSL-RL](#rsl-rl) | 506.4K | 3.1K | Oct 2026 | BSD-3-Clause |
| [SB3-Contrib](#sbthree-contrib) | 154.7K | 746 | Oct 2026 | MIT |
| [TorchRL](#torchrl) | 134.5K | 3.6K | Nov 2026 | MIT |
| [skrl](#skrl) | 111.5K | 1.1K | Nov 2026 | MIT |
| [RLax](#rlax) | 106.1K | 1.5K | Jun 2026 | Apache-2.0 |
| [Tianshou](#tianshou) | 41.7K | 11.1K | Apr 2026 | MIT |

Downloads: PyPI, last thirty days. Stars and releases: GitHub. Amber: no release in over a year.

[RLlib](#ray) has the most monthly downloads in this comparison, at 15.7M, a count that covers all of Ray.

## Capabilities

| Library | Built-in agent training loop | JAX-native learning |
| --- | --- | --- |
| [RLlib](#ray) | Yes | No |
| [stable-baselines3](#stable-baselines) | Yes | No |
| [RSL-RL](#rsl-rl) | Yes | No |
| [SB3-Contrib](#sbthree-contrib) | Yes | No |
| [TorchRL](#torchrl) | Yes | No |
| [skrl](#skrl) | Yes | Yes |
| [RLax](#rlax) | No | Yes |
| [Tianshou](#tianshou) | Yes | No |

## Libraries

### RLlib

[GitHub](https://github.com/ray-project/ray) · [PyPI](https://pypi.org/project/ray) · [Docs](https://docs.ray.io/en/latest/rllib/index.html)

Builds distributed applications through the Ray API.

- Downloads / mo: 15.7M
- Stars: 44.3K
- Last release: 2.60.0
- License: Apache-2.0
- Capabilities: [From the RLlib docs](https://docs.ray.io/en/latest/rllib/index.html)

```sh
pip install "ray[rllib]==2.60.0" torch
```

**Quickstart**

```python
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()

```

From [index.rst](https://docs.ray.io/en/latest/rllib/index.html) · [Find projects using RLlib →](https://dashboard.exa.ai/playground/search?q=ray%20GitHub%20projects)

### stable-baselines3

[GitHub](https://github.com/DLR-RM/stable-baselines3) · [PyPI](https://pypi.org/project/stable-baselines3) · [Docs](https://stable-baselines3.readthedocs.io/en/master/modules/ppo.html)

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
- Capabilities: [From the stable-baselines3 docs](https://stable-baselines3.readthedocs.io/en/master/modules/ppo.html)

**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.

**Watch out for**

- **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.

```sh
pip install stable-baselines3==2.9.2
```

**Quickstart**

```python
from stable_baselines3 import PPO
model = PPO("MlpPolicy", "CartPole-v1").learn(10_000)

```

From [README.md](https://stable-baselines3.readthedocs.io/en/master/modules/ppo.html) · [Find projects using stable-baselines3 →](https://dashboard.exa.ai/playground/search?q=Python%20applications%20using%20stable-baselines3%20for%20training%20policies%20with%20vectorized%20environments%20and%20checkpoint%20handling&filters=%7B%22type%22%3A%20%22auto%22%2C%20%22numResults%22%3A%2010%2C%20%22includeDomains%22%3A%20%5B%22github.com%22%5D%7D)

### RSL-RL

[GitHub](https://github.com/leggedrobotics/rsl_rl) · [PyPI](https://pypi.org/project/rsl-rl-lib) · [Docs](https://github.com/leggedrobotics/rsl_rl/blob/v5.5.2/rsl_rl/runners/on_policy_runner.py)

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
- Capabilities: [From the RSL-RL docs](https://github.com/leggedrobotics/rsl_rl/blob/v5.5.2/rsl_rl/runners/on_policy_runner.py)

**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.

**Watch out for**

- **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.

```sh
pip install rsl-rl-lib==5.5.2 torch==2.6.0
```

**Quickstart**

```python
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)

```

From [mlp.py](https://github.com/leggedrobotics/rsl_rl/blob/11563319134f987f70fb034410496fe3cc7327a9/rsl_rl/modules/__init__.py) · [Find projects using RSL-RL →](https://dashboard.exa.ai/playground/search?q=Python%20applications%20using%20rsl-rl-lib%20for%20training%20policies%20with%20vectorized%20environments%20and%20checkpoint%20handling&filters=%7B%22type%22%3A%20%22auto%22%2C%20%22numResults%22%3A%2010%2C%20%22includeDomains%22%3A%20%5B%22github.com%22%5D%7D)

### SB3-Contrib

[GitHub](https://github.com/Stable-Baselines-Team/stable-baselines3-contrib) · [PyPI](https://pypi.org/project/sb3-contrib) · [Docs](https://sb3-contrib.readthedocs.io/en/master/modules/ars.html)

Adds experimental code to Stable Baselines3.

- Downloads / mo: 154.7K
- Stars: 746
- Last release: 2.9.2
- License: MIT
- Capabilities: [From the SB3-Contrib docs](https://sb3-contrib.readthedocs.io/en/master/modules/ars.html)

```sh
pip install sb3-contrib==2.9.2
```

**DLR-RM/rl-baselines3-zoo** (2.9K stars)

[DLR-RM/rl-baselines3-zoo](https://github.com/DLR-RM/rl-baselines3-zoo) 

```python
def learn(self, model: BaseAlgorithm) -> None:
    """
    :param model: an initialized RL model
    """
    kwargs: dict[str, Any] = {}
    # log_interval == -1 -> default
    # < -2 -> no auto-logging
    if self.log_interval > -1:
        kwargs = {"log_interval": self.log_interval}
    elif self.log_interval < -1:
        # Deactivate auto-logging, helpful when using callback like LogEveryNTimesteps
        kwargs = {"log_interval": None}

    if len(self.callbacks) > 0:
        kwargs["callback"] = self.callbacks

    # Special case for ARS
    if self.algo == "ars" and self.n_envs > 1:
        kwargs["async_eval"] = AsyncEval(
            [lambda: self.create_envs(n_envs=1, no_log=True) for _ in range(self.n_envs)], model.policy
        )

    try:
        model.learn(self.n_timesteps, **kwargs)
    except KeyboardInterrupt:
        # this allows to save the model when interrupting training
        pass
    finally:
        # Clean progress bar
        if len(self.callbacks) > 0:
            self.callbacks[0].on_training_end()
        # Release resources
        try:
            assert model.env is not None
            model.env.close()
        except EOFError:
            pass
```

[rl_zoo3/exp_manager.py](https://github.com/DLR-RM/rl-baselines3-zoo/blob/d802099afb5ad62f75a0336e922416316162c07c/rl_zoo3/exp_manager.py) · [More projects using SB3-Contrib →](https://dashboard.exa.ai/playground/search?q=sb3-contrib%20GitHub%20projects)

**Quickstart**

```python
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)

```

From [ppo_mask.rst](https://sb3-contrib.readthedocs.io/en/master/modules/ppo_mask.html)

### TorchRL

[GitHub](https://github.com/pytorch/rl) · [PyPI](https://pypi.org/project/torchrl) · [Docs](https://pytorch.org/rl/stable/index.html)

Provides modular PyTorch building blocks for reinforcement learning.

- Downloads / mo: 134.5K
- Stars: 3.6K
- Last release: 0.15.0
- License: MIT
- Capabilities: [From the TorchRL docs](https://pytorch.org/rl/stable/index.html)

```sh
pip install torchrl==0.15.0 gymnasium
```

**Quickstart**

```python
from torchrl.envs import GymEnv
env = GymEnv("CartPole-v1", device="cpu")
try:
    print(env.rollout(3))
finally:
    env.close()

```

From [torchrl.envs.GymEnv.html](https://pytorch.org/rl/stable/reference/generated/torchrl.envs.GymEnv.html) · [Find projects using TorchRL →](https://dashboard.exa.ai/playground/search?q=torchrl%20GitHub%20projects)

### skrl

[GitHub](https://github.com/Toni-SM/skrl) · [PyPI](https://pypi.org/project/skrl) · [Docs](https://skrl.readthedocs.io/en/latest/api/utils/runner.html)

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
- Capabilities: [From the skrl docs](https://skrl.readthedocs.io/en/latest/api/utils/runner.html)

**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.

**Watch out for**

- **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.

```sh
pip install skrl==2.1.2 gymnasium
```

**Quickstart**

```python
from skrl.envs.wrappers.torch import wrap_env
import gymnasium as gym
env = gym.make("Pendulum-v1")
env = wrap_env(env)

```

From [torch_gymnasium_pendulum_ppo.py](https://skrl.readthedocs.io/en/latest/api/envs/wrapping.html) · [Find projects using skrl →](https://dashboard.exa.ai/playground/search?q=Python%20applications%20using%20skrl%20for%20training%20policies%20with%20vectorized%20environments%20and%20checkpoint%20handling&filters=%7B%22type%22%3A%20%22auto%22%2C%20%22numResults%22%3A%2010%2C%20%22includeDomains%22%3A%20%5B%22github.com%22%5D%7D)

### RLax

[GitHub](https://github.com/google-deepmind/rlax) · [PyPI](https://pypi.org/project/rlax) · [Docs](https://rlax.readthedocs.io/en/latest/api.html)

Provides reinforcement learning building blocks in JAX.

- Downloads / mo: 106.1K
- Stars: 1.5K
- Last release: 0.1.9
- License: Apache-2.0
- Capabilities: [From the RLax docs](https://rlax.readthedocs.io/en/latest/api.html)

```sh
pip install rlax==0.1.9
```

**Quickstart**

```python
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)

```

From [api.rst](https://rlax.readthedocs.io/en/latest/api.html) · [Find projects using RLax →](https://dashboard.exa.ai/playground/search?q=rlax%20GitHub%20projects)

### Tianshou

[GitHub](https://github.com/thu-ml/tianshou) · [PyPI](https://pypi.org/project/tianshou) · [Docs](https://api.github.com/repos/thu-ml/tianshou/contents/tianshou/highlevel/experiment.py?ref=v2.0.1)

Provides tools for deep reinforcement learning.

- Downloads / mo: 41.7K
- Stars: 11.1K
- Last release: 2.0.1
- License: MIT
- Capabilities: [From the Tianshou docs](https://api.github.com/repos/thu-ml/tianshou/contents/tianshou/highlevel/experiment.py?ref=v2.0.1)

```sh
pip install tianshou==2.0.1
```

**Quickstart**

```python
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()

```

From [README.md](https://api.github.com/repos/thu-ml/tianshou/contents/tianshou/highlevel/experiment.py?ref=v2.0.1) · [Find projects using Tianshou →](https://dashboard.exa.ai/playground/search?q=tianshou%20GitHub%20projects)

## FAQ

### Which Python reinforcement learning library should I use?

[stable-baselines3](#stable-baselines) suits training with maintained PyTorch algorithms behind one training and prediction interface. [RLlib](#ray) suits distributed and multi-agent training on Ray. [TorchRL](#torchrl) suits researchers who assemble their own PyTorch training loop.

### What is stable-baselines3?

[stable-baselines3](#stable-baselines) is a set of PyTorch reinforcement learning algorithms with a shared training and prediction interface. Experimental algorithms live in the separate [SB3-Contrib](#sbthree-contrib) package.

### What is Tianshou?

[Tianshou](#tianshou) is a deep reinforcement learning library built on PyTorch and Gymnasium, with high-level experiment builders and a lower-level algorithm API.

### What is RLax?

[RLax](#rlax) is a library of reinforcement learning building blocks in JAX. It supplies operations for building agents rather than complete algorithms.

### What is TorchRL?

[TorchRL](#torchrl) is a modular PyTorch library for reinforcement learning with replay buffers, data collectors, environments, and loss functions.

## How this page was built

Data checked Nov 20, 2026.

Reproduce it with the Exa API:

```json
{
  "endpoint": "/search",
  "body": {
    "query": "Best Python reinforcement learning libraries Stable Baselines3 skrl RL Games RSL RL code examples",
    "numResults": 5
  }
}
```

Docs: https://exa.ai/docs/reference/search
