Skip to main content

gym_classics2

PyPI package version number 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

Importing gym_classics2 automatically registers its environments with Gymnasium. Create one and use the standard reset/step interface:

import gymnasium as gym
import numpy as np
import gym_classics2

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

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.4
File Size Uploaded Provenance Actions
gym_classics2-1.0.4.tar.gz 70.0 kB With provenance Details for gym_classics2-1.0.4.tar.gz

Built distribution (wheel)

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

Total release size: 138.5 kB

Release files / gym_classics2-1.0.4.tar.gz

Download URL gym_classics2-1.0.4.tar.gz
Size 70.0 kB
Tags Source
SHA-256 checksum
How to use checksums
cef354566cfc13838d9e83b2d46fc7db42e5e357f68d518bb442624726cd5051
BLAKE2b-256 checksum
How to use checksums
ed8fadeae388248bd60684d34fe237d738264ab4824a4391a354aabf42caf212
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 27, 2026.

Transparency log

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

Download URL gym_classics2-1.0.4-py3-none-any.whl
Size 68.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e1c4ea8c52e6831997a3f688b858272ba7885aa830ee0919521ad8a02ee3928b
BLAKE2b-256 checksum
How to use checksums
f58f1dcf5db9ddfb8314c12f4de9b60239005ed6e0a524801456788c1efad20c
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 27, 2026.

Transparency log

Security for gym-classics2 1.0.4

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

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for gym_classics2-1.0.4.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 27, 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.4 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