PettingZoo

1.25.0 · active · verified Thu Apr 16

PettingZoo is a Python library providing a standardized API for multi-agent reinforcement learning (MARL) environments, analogous to Gymnasium for single-agent RL. It offers a wide variety of reference environments and utilities, supporting both sequential (AEC) and simultaneous (Parallel) action paradigms. Currently at version 1.25.0, the library is actively maintained with frequent updates to ensure compatibility with recent Python and Gymnasium versions.

Common errors

Warnings

Install

Imports

Quickstart

This example demonstrates how to initialize and interact with a PettingZoo environment using the Agent-Environment Cycle (AEC) API, which is suitable for turn-based or sequentially acting multi-agent systems. It uses the `pistonball_v6` environment, renders it to a human-readable window, resets it with a fixed seed for reproducibility, and then steps through agents until the episode terminates or truncates.

from pettingzoo.butterfly import pistonball_v6

env = pistonball_v6.env(render_mode="human")
env.reset(seed=42)

for agent in env.agent_iter():
    observation, reward, terminated, truncated, info = env.last()
    if terminated or truncated:
        action = None
    else:
        # In a real scenario, this would be your policy's action
        action = env.action_space(agent).sample() 
    env.step(action)

env.close()

view raw JSON →