PettingZoo is a Python library for conducting research in multi-agent reinforcement learning, akin to a multi-agent version of Gymnasium.
The documentation website is at pettingzoo.farama.org and we have a public discord server (which we also use to coordinate development work) that you can join here: https://discord.gg/nhvKkYa6qX
PettingZoo includes the following families of environments:
- Atari: Multi-player Atari 2600 games (cooperative, competitive and mixed sum)
- Butterfly: Cooperative graphical games developed by us, requiring a high degree of coordination
- Classic: Classical games including card games, board games, etc.
- MPE: A set of simple nongraphical communication tasks, originally from https://github.com/openai/multiagent-particle-envs
- SISL: 3 cooperative environments, originally from https://github.com/sisl/MADRL
To install the pettingzoo base library, use pip install pettingzoo
This does not include dependencies for all families of environments (there's a massive number, and some can be problematic to install on certain systems). You can install these dependencies for one family like pip install pettingzoo[atari]
or use pip install pettingzoo[all]
to install all dependencies.
We support Python 3.7, 3.8, 3.9 and 3.10 on Linux and macOS. We will accept PRs related to Windows, but do not officially support it.
Get started with PettingZoo by following the PettingZoo tutorial, where you'll train multiple PPO agents in the Pistonball environment using PettingZoo.
PettingZoo model environments as Agent Environment Cycle (AEC) games, in order to be able to cleanly support all types of multi-agent RL environments under one API and to minimize the potential for certain classes of common bugs.
Using environments in PettingZoo is very similar to Gymnasium, i.e. you initialize an environment via:
from pettingzoo.butterfly import pistonball_v6
env = pistonball_v6.env()
Environments can be interacted with in a manner very similar to Gymnasium:
env.reset()
for agent in env.agent_iter():
observation, reward, termination, truncation, info = env.last()
action = None if termination or truncation else env.action_space(agent).sample() # this is where you would insert your policy
env.step(action)
For the complete API documentation, please see https://pettingzoo.farama.org/api/aec/
In certain environments, it's a valid to assume that agents take their actions at the same time. For these games, we offer a secondary API to allow for parallel actions, documented at https://pettingzoo.farama.org/api/parallel/
SuperSuit is a library that includes all commonly used wrappers in RL (frame stacking, observation, normalization, etc.) for PettingZoo and Gymnasium environments with a nice API. We developed it in lieu of wrappers built into PettingZoo. https://github.com/Farama-Foundation/SuperSuit
PettingZoo keeps strict versioning for reproducibility reasons. All environments end in a suffix like "_v0". When changes are made to environments that might impact learning results, the number is increased by one to prevent potential confusion.
To cite this project in publication, please use
@article{terry2020pettingzoo,
Title = {PettingZoo: Gym for Multi-Agent Reinforcement Learning},
Author = {Terry, J. K and Black, Benjamin and Grammel, Nathaniel and Jayakumar, Mario and Hari, Ananth and Sulivan, Ryan and Santos, Luis and Perez, Rodrigo and Horsch, Caroline and Dieffendahl, Clemens and Williams, Niall L and Lokesh, Yashas and Sullivan, Ryan and Ravi, Praveen},
journal={arXiv preprint arXiv:2009.14471},
year={2020}
}