MCPcopy
hub / github.com/Farama-Foundation/PettingZoo

github.com/Farama-Foundation/PettingZoo @1.26.1 sqlite

repository ↗ · DeepWiki ↗ · release 1.26.1 ↗
1,029 symbols 3,936 edges 226 files 241 documented · 23%
README

pre-commit Code style: black

<a href = "https://pettingzoo.farama.org/" target = "_blank"><img src="https://raw.githubusercontent.com/Farama-Foundation/PettingZoo/master/pettingzoo-text.png" width="500px"/> </a>

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

Environments

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.
  • SISL: 2 cooperative environments, originally from https://github.com/sisl/MADRL

Installation

To install the base PettingZoo library: pip install pettingzoo.

This does not include dependencies for all families of environments (some environments can be problematic to install on certain systems).

To install the dependencies for one family, use pip install 'pettingzoo[atari]', or use pip install 'pettingzoo[all]' to install all dependencies.

We support and maintain PettingZoo for Python 3.9, 3.10, 3.11, 3.12, 3.13, and 3.14 on Linux and macOS. We will accept PRs related to Windows, but do not officially support it.

Note: Some Linux distributions may require manual installation of cmake, swig, or zlib1g-dev (e.g., sudo apt install cmake swig zlib1g-dev)

Getting started

For an introduction to PettingZoo, see Basic Usage. To create a new environment, see our Environment Creation Tutorial and Custom Environment Examples. For examples of training RL models using PettingZoo see our tutorials: * CleanRL: Implementing PPO: train multiple PPO agents in the Pistonball environment. * Tianshou: Training Agents: train DQN agents in the Tic-Tac-Toe environment. * AgileRL: Training, Curriculums and Self-play: train agents with curriculum learning and self-play in the Connect Four environment.

API

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/

Parallel API

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

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

Environment Versioning

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.

Citation

To cite this project in publication, please use

@article{terry2021pettingzoo,
  title={Pettingzoo: Gym for multi-agent reinforcement learning},
  author={Terry, J and Black, Benjamin and Grammel, Nathaniel and Jayakumar, Mario and Hari, Ananth and Sullivan, Ryan and Santos, Luis S and Dieffendahl, Clemens and Horsch, Caroline and Perez-Vicente, Rodrigo and others},
  journal={Advances in Neural Information Processing Systems},
  volume={34},
  pages={15032--15043},
  year={2021}
}

Project Maintainers

  • Project Manager: Travis Virgil - travis@farama.org
  • Maintainer: Albert Han - yjhan96@gmail.com.
  • Maintenance for this project is also contributed by the broader Farama team: farama.org/team.

Core symbols most depended-on inside this repo

env
called by 45
pettingzoo/utils/deprecated_module.py
parallel_wrapper_fn
called by 30
pettingzoo/utils/conversions.py
agent_iter
called by 30
pettingzoo/utils/env.py
calculate_height
called by 27
pettingzoo/classic/rlcard_envs/rlcard_utils.py
close
called by 26
pettingzoo/utils/env.py
next
called by 25
pettingzoo/utils/agent_selector.py
last
called by 24
pettingzoo/utils/env.py
base_env_wrapper_fn
called by 24
pettingzoo/atari/base_atari_env.py

Shape

Method 660
Function 272
Class 97

Languages

Python100%

Modules by API surface

pettingzoo/utils/conversions.py49 symbols
pettingzoo/utils/env.py39 symbols
pettingzoo/sisl/multiwalker/multiwalker_base.py35 symbols
pettingzoo/classic/go/go_base.py35 symbols
pettingzoo/sisl/pursuit/pursuit_base.py28 symbols
pettingzoo/butterfly/knights_archers_zombies/knights_archers_zombies.py27 symbols
pettingzoo/butterfly/pistonball/pistonball.py23 symbols
pettingzoo/butterfly/cooperative_pong/cooperative_pong.py23 symbols
pettingzoo/classic/go/go.py20 symbols
pettingzoo/utils/env_logger.py19 symbols
tutorials/AgileRL/agilerl_dqn_curriculum.py18 symbols
pettingzoo/classic/chess/chess_utils.py18 symbols

Used by 2 indexed graphs manifest dependencies, hub-wide

Dependencies from manifests, versioned

AutoROM0.6.1 · 1×
Pillow9.4.0 · 1×
PyYAML5.4.1 · 1×
SuperSuit3.9.0 · 1×
agilerl2.2.1 · 1×
fastrand1.3.0 · 1×
gymnasium1.0.0 · 1×
imageio2.31.1 · 1×
mpe21.0.0 · 1×
numpy1.21.0 · 1×
packaging21.3 · 1×
pettingzoo1.24.0 · 1×

For agents

$ claude mcp add PettingZoo \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact