tianshou
A Library for Deep Reinforcement Learning
What it is and what it does
Tianshou is a modular reinforcement learning framework built on PyTorch and Gymnasium that provides both researcher-friendly low-level procedural APIs and practitioner-friendly high-level training interfaces. It implements a broad range of RL algorithms spanning on-policy methods (PG, A2C, PPO, TRPO), off-policy methods (DQN variants, DDPG, TD3, SAC), offline RL (BCQ, CQL), and imitation learning (GAIL, behavioral cloning). Version 2 introduces a cleaner architecture with explicit separation between Algorithm and Policy abstractions, reorganized class hierarchies, and improved parameter naming.
The library emphasizes modularity and performance: it supports vectorized environments (synchronous, asynchronous, and EnvPool-based), recurrent policies for POMDPs, arbitrary state/action representations, multi-GPU training, and TensorBoard/W&B logging. Core components like n-step returns, prioritized experience replay, and the Generalized Advantage Estimator are optimized with Numba JIT compilation. Experimental support for multi-agent RL and model-based methods is included. With 10926 GitHub stars and active maintenance, it is a mature choice for both research and production RL applications.
Use it for:
- Train DQN or Rainbow agents on Atari-style discrete action environments with prioritized experience replay and n-step returns
- Implement continuous control policies (DDPG, TD3, SAC) for robotics or MuJoCo benchmarks with vectorized parallel sampling
- Build offline RL agents (BCQ, CQL) from logged interaction data without online environment interaction
- Develop multi-agent RL systems using Tianshou's experimental MARL support with PettingZoo environments
- Prototype imitation learning pipelines (GAIL, behavioral cloning) from expert demonstrations
- Customize training loops and algorithm implementations using the low-level procedural API for research
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Tianshou is a PyTorch-based reinforcement learning library that implements a wide range of RL algorithms (DQN, PPO, SAC, and others) with both high-level and low-level APIs for training agents on Gymnasium environments.
Yes, if you are building or researching deep reinforcement learning agents. Tianshou offers a mature, well-maintained framework with broad algorithm coverage, clean APIs, and strong performance. Version 2 is a breaking redesign that improves usability and type safety; migration from v1 requires code changes. The 15-dependency stack (torch, numpy, gymnasium, etc.) is standard for ML work. No known vulnerabilities. Suitable for both academic research and production RL applications.
Install
tianshou on PyPI
pip
pip install tianshouuv
uv add tianshoupoetry
poetry add tianshouInstalling tianshou
Before you install
Low install friction with a pure-Python wheel. Active maintenance with recent releases; last commit 2026-04-03. Requires Python 3.11 or later and brings in 15 runtime dependencies including torch, numpy, and gymnasium—a substantial but standard ML stack.
License in practice
MIT license (permissive) allows commercial and private use with minimal restrictions; you must include a copy of the license and copyright notice in distributions.
Quickstart
pip install tianshou
import torch
from tianshou.policy import DQNPolicy
from tianshou.trainer import OffpolicyTrainer
# Define policy, collector, and trainer; call trainer.run()
Requires Python >= 3.11. PyTorch and Gymnasium must be installed; torch typically requires a compatible CUDA toolkit or CPU-only build.
Verify before relying
- Whether version 2's breaking changes from version 1 affect existing codebases that depend on Tianshou
- Performance characteristics and scalability limits for multi-agent RL and model-based algorithms marked as experimental
- Specific hardware requirements or GPU memory recommendations for typical training workloads
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (<4.0,>=3.11) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 15 — deepdiff, gymnasium, h5py, matplotlib, numba, numpy, overrides, packaging, pandas, pettingzoo, sensai-utils, tensorboard, torch, tqdm, virtualenv |
| Maintenance | actively maintained — 134 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 114,112/month — #12,310 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: tianshou-2.0.1-py3-none-any.whl
Tags
More Python Modules packages
Converts domain names between Unicode and…
permissive · top 100 on PyPI
setuptoolsSetuptools is a Python build backend and…
permissive · top 100 on PyPI
PyYAMLPyYAML parses and emits YAML 1.1 data format,…
permissive · top 100 on PyPI
pydanticPydantic validates Python data structures…
permissive · top 100 on PyPI
annotated-typesProvides reusable metadata objects for use with…
permissive · top 100 on PyPI
typing-inspectionProvides runtime tools to inspect and…
permissive · top 100 on PyPI
dopamine-rlDopamine is a research framework for…
permissive · top 15,000 on PyPI
rsl-rl-libRSL-RL is a GPU-accelerated reinforcement…
permissive · top 15,000 on PyPI
stable-baselines3Stable Baselines3 provides PyTorch…
permissive · top 5,000 on PyPI
gymnasiumGymnasium provides a standard Python API for…
permissive · top 5,000 on PyPI
pettingzooPettingZoo provides multi-agent reinforcement…
permissive · top 15,000 on PyPI
sb3-contribProvides experimental reinforcement learning…
permissive · top 15,000 on PyPI
skrlskrl is a modular reinforcement learning…
permissive · top 15,000 on PyPI
torchrlTorchRL is a PyTorch-native toolkit for…
unclear · top 5,000 on PyPI
gem-llmGEM is a reinforcement learning environment…
permissive · top 15,000 on PyPI
open-spielOpenSpiel provides game environments and…
permissive · top 15,000 on PyPI