openai /gym

A toolkit for developing and comparing reinforcement learning algorithms.

★ 37,234⑂ 8,664👁 47⑃ 1,468● 1,839▤ 19◈ 0
PythonNOASSERTIONCreated 2016-04-27www.gymlibrary.dev
37,234
stars
+1+3+-14
8,664
forks
47
watchers
1,468
prs
1,839
issues
19
releases
0
discussions

README

Important Notice

 The team that has been maintaining Gym since 2021 has moved all future development to Gymnasium, a drop in replacement for Gym (import gymnasium as gym), and Gym will not be receiving any future updates. Please switch over to Gymnasium as soon as you're able to do so. If you'd like to read more about the story behind this switch, please check out this blog post.

 Gym

Gym is an open source Python library for developing and comparing reinforcement learning algorithms by providing a standard API to communicate between learning algorithms and environments, as well as a standard set of environments compliant with that API. Since its release, Gym's API has become the field standard for doing this.

Gym documentation website is at https://www.gymlibrary.dev/, and you can propose fixes and changes to it here.

Gym also has a discord server for development purposes that you can join here: https://discord.gg/nHg2JRN489

 Installation

To install the base Gym library, use pip install gym.

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 gym[atari] or use pip install gym[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.

 API

The Gym API's API models environments as simple Python env classes. Creating environment instances and interacting with them is very simple- here's an example using the "CartPole-v1" environment:

python
import gym
env = gym.make("CartPole-v1")
observation, info = env.reset(seed=42)

for _ in range(1000):
    action = env.action_space.sample()
    observation, reward, terminated, truncated, info = env.step(action)

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


 Notable Related Libraries

Please note that this is an incomplete list, and just includes libraries that the maintainers most commonly point newcommers to when asked for recommendations.

 CleanRL is a learning library based on the Gym API. It is designed to cater to newer people in the field and provides very good reference implementations.
 Tianshou is a learning library that's geared towards very experienced users and is design to allow for ease in complex algorithm modifications.
 RLlib is a learning library that allows for distributed training and inferencing and supports an extraordinarily large number of features throughout the reinforcement learning space.
 PettingZoo is like Gym, but for environments with multiple agents.

 Environment Versioning

Gym 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.

 MuJoCo Environments

The latest "\_v4

Top issues

Latest release

0.26.2 0.26.2 2022-10-04
Release notes

This is another very minor bug release.

 Bugs Fixes 
 As reset now returns (obs, info) then in the vector environments, this caused the final step's info to be overwritten. Now, the final observation and info are contained within the info as "final_observation" and "final_info" @pseudo-rnd-thoughts 
 Adds warnings when trying to render without specifying the render_mode @younik 
 Updates Atari Preprocessing such that the wrapper can be pickled @vermouth1992 
 Github CI was hardened to such that the CI just has read permissions @sashashura 
 Clarify and fix typo in Grap

Snapshot: 2026-11-10T09:35:25Z · Data license Apache-2.0 · JSON