<a id="sphx-glr-tutorials-gymnasium-basics"></a>

# Gymnasium Basics

<a id="gallery-section-name"></a>

The aim of these tutorials is to showcase the fundamental API of Gymnasium to help users implement it.

Each tutorial is a self-contained Python script: its page shows the code next to the output, and the
script can be downloaded from the same page to run and modify locally.

## What the tutorials cover

- **Make your own custom environment** - generate a new environment from the Farama
  `gymnasium-env-template` with Copier, then implement its spaces, transitions, rendering,
  registration and tests.
- **Implementing custom wrappers** - subclass `ObservationWrapper`, `ActionWrapper`,
  `RewardWrapper` and `Wrapper` to change the observations, actions or rewards of an existing
  environment, and where to find the function-based and vector wrappers.
- **Handling time limits** - the difference between `terminated` and `truncated`, why
  bootstrapping should stop only on `terminated`, and how this works with vector environments.
- **Load custom quadruped robot environments** - pass an MJCF or URDF model to a MuJoCo environment
  with the `xml_file` argument, then tune its simulation, termination, reward and observation
  parameters.

## Requirements

The tutorials require Python 3.11 or newer with `gymnasium` installed:

```console
pip install gymnasium
```

Three of the tutorials also use optional dependencies:

- `pip install copier "gymnasium[classic-control]"` for *Make your own custom environment*, which
  walks through the Copier template and renders the example environment with `pygame`.
- `pip install "gymnasium[box2d,mujoco]"` for *Implementing custom wrappers*, which wraps
  `LunarLanderContinuous-v3` and `Reacher-v5`.
- `pip install "gymnasium[mujoco]"` for *Load custom quadruped robot environments*, which wraps
  `Ant-v5`.

## Running a tutorial locally

Every tutorial page ends with a *Download Python source code* link. Save the file and run it from a
terminal, for example:

```console
python implementing_custom_wrappers.py
```

The tutorials are written to be read as much as run: the printed output and figures are part of the
explanation, so the rendered page is the primary reference and the script is there to experiment
with.

## Where to go next

- [Basic usage](https://gymnasium.farama.org/introduction/basic_usage/) introduces the
  `reset` / `step` loop, spaces and wrappers that every tutorial builds on.
- The [API reference](https://gymnasium.farama.org/api/env/) documents the environment API in
  full.

<div class="sphx-glr-thumbnails"><div class="sphx-glr-thumbcontainer" tooltip="This tutorial shows how to create new environment and links to relevant useful wrappers, utilit...">  <div class="sphx-glr-thumbnail-title">Make your own custom environment</div>
</div><div class="sphx-glr-thumbcontainer" tooltip="This tutorial explains how time limits should be correctly handled with termination and truncat...">  <div class="sphx-glr-thumbnail-title">Handling Time Limits</div>
</div><div class="sphx-glr-thumbcontainer" tooltip="In this tutorial we will describe how to implement your own custom wrappers.">  <div class="sphx-glr-thumbnail-title">Implementing Custom Wrappers</div>
</div><div class="sphx-glr-thumbcontainer" tooltip="In this tutorial we create a MuJoCo quadruped walking environment using a model file (ending in...">  <div class="sphx-glr-thumbnail-title">Load custom quadruped robot environments</div>
</div></div>
