Gymnasium Reinforcement Learning Library

1.2.3 · active · verified Thu Apr 09

Gymnasium provides a standard API for reinforcement learning environments, offering a diverse set of reference environments for research and development. It is the spiritual successor to OpenAI Gym, maintained by the Farama Foundation, and receives frequent minor releases with bug fixes, new features, and API improvements. The current version is 1.2.3.

Warnings

Install

Imports

Quickstart

Initializes a CartPole-v1 environment, steps through it for 100 timesteps using random actions, and resets when the episode terminates or truncates. Demonstrates the modern `render_mode` parameter, the `seed` argument for `reset()`, and the split `terminated`/`truncated` flags from `step()`.

import gymnasium as gym

env = gym.make("CartPole-v1", render_mode="rgb_array")
observation, info = env.reset(seed=42) # seed is optional, for reproducibility

for _ in range(100):
    action = env.action_space.sample()  # agent policy that takes an observation and returns an action
    observation, reward, terminated, truncated, info = env.step(action)

    if terminated or truncated:
        observation, info = env.reset(seed=42)
env.close()

view raw JSON →