Skip to main content

gym_classics2

PyPI package version number Actions Status documentation license

gym_classics2 provides classic finite Markov decision processes and readable reinforcement-learning algorithms for teaching with Gymnasium. It is based on Brett Daley's gym-classics and follows examples from Sutton and Barto's Reinforcement Learning: An Introduction. The package is intended for educational use. Example course material (slides, implementation examples and exercises) can be found here: Introduction Course to Reinforcement Learning.

The package includes:

  • Gymnasium environments for gridworlds, random walks, mazes, and cliff walking.
  • Direct access to the transition and reward model, $p(s',r\mid s,a)$.
  • Textbook-oriented implementations of dynamic programming, Monte Carlo, temporal-difference, function-approximation, eligibility-trace, and policy-gradient algorithms.
  • Gridworld plotting and animation helpers.

Installation

Python 3.10 or newer is required. Once published on PyPI, install the release with:

python -m pip install gym-classics2

To install the current development version:

python -m pip install "gym-classics2 @ git+https://github.com/mhahsler/gym-classics2.git"

Pygame rendering is optional. Install the render extra to use human or rgb_array rendering modes:

python -m pip install "gym-classics2[render]"

Quick start

Register the environments, create one with Gymnasium, and use the standard reset/step Gymnasium interface:

import gymnasium as gym
import numpy as np
import gym_classics2
gym_classics2.register()

seed = 42
rng = np.random.default_rng(seed)

env = gym.make("ClassicGridworld-v1", tabular=True)

state, info = env.reset(seed=seed)
for t in range(100):
    action = rng.integers(env.action_space.n)
    next_state, reward, terminated, truncated, info = env.step(action)
    done = terminated or truncated
    print(t, state, action, reward, next_state, done)
    state = next_state
    if done:
        state, info = env.reset()

env.close()

Model access

The unwrapped environments expose the full finite-MDP model. In tabular mode, states and next states are integer IDs:

gym_env = gym.make("ClassicGridworld-v1", tabular=True)
env = gym_env.unwrapped  # expose the gym_classics2-specific API

print("Starts:", env.start_states)
print("Goals:", env.goal_states)

state = env.state2id((0, 0))
action = env.action2id("up")
next_states, rewards, terminals, probabilities = env.model(state, action)

For this transition, the result is equivalent to:

next_states   = [0, 1, 3]
rewards       = [-0.04, -0.04, -0.04]
terminals     = [False, False, False]
probabilities = [0.1, 0.8, 0.1]

See the model-access guide for details.

Included gridworld environments

Gymnasium ID Task Dynamics Default state representation
5Walk-v0 Five-state random walk Deterministic Tabular
19Walk-v0 Nineteen-state random walk Deterministic Tabular
ClassicGridworld-v1 4×3 gridworld Stochastic (80–10–10) Tabular
LMaze-v0 L-shaped maze Deterministic Tabular
CliffWalk-v1 Cliff walking Deterministic Tabular
DynaMaze-v0 Dyna maze Deterministic Tabular
FourRooms-v0 Four rooms Deterministic Tabular
SparseGridworld-v0 Sparse-reward gridworld Stochastic (80–10–10) Tabular
WindyGridworld-v0 Windy gridworld Deterministic Tabular

Included algorithms

Family Implementations Requires model access?
Dynamic programming value iteration, policy iteration Yes
Monte Carlo prediction, exploring-starts control No
Temporal difference Sarsa(0), Q-learning No
Linear approximation semi-gradient TD(0), Sarsa(0), Fourier features No
Eligibility traces semi-gradient Sarsa($\lambda$) No
Policy gradient REINFORCE, actor-critic No

All model-free algorithms can also be used with standard Gymnasium environments outside this package. See the algorithm guide for input requirements and return values.

Documentation and examples

To build the documentation locally:

python -m pip install -e ".[docs]"
mkdocs serve

Maintainers: see the release instructions for distribution checks and PyPI publishing.

References

Metadata

Release files for gym-classics2 1.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for gym-classics2 1.0.3
File Size Uploaded Provenance
gym_classics2-1.0.3.tar.gz 66.2 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for gym-classics2 1.0.3
File Interpreter ABI Platform
gym_classics2-1.0.3-py3-none-any.whl Python 3 none any Details

Total release size: 132.0 kB

Release files / gym_classics2-1.0.3.tar.gz

Download URL gym_classics2-1.0.3.tar.gz
Size 66.2 kB
Tags Source
SHA-256 checksum
How to use checksums
0b65d26a674959d14009321d3ea81fee650a11c454f3a422bd23f1bff0f0225f
BLAKE2b-256 checksum
How to use checksums
9381ed20e0062e59d4ee45e8f9516f5cd34756caf34c52172b6eeaf82b21c780
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 23, 2026.

Transparency log

Release files / gym_classics2-1.0.3-py3-none-any.whl

Download URL gym_classics2-1.0.3-py3-none-any.whl
Size 65.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
40f0d62fe356877f53006f668d6b03910d161158f41d3c3efeeff54fe4b5d1fd
BLAKE2b-256 checksum
How to use checksums
7ce3880a7c77437b5a69a3af337c5286e60ddbc7d5fa1d690ef9e4eafc743b52
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 23, 2026.

Transparency log

Security for gym-classics2 1.0.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for gym_classics2-1.0.3.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 23, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0.3 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page