<linkrel="index"title="Index"href="../../genindex/"/><linkrel="search"title="Search"href="../../search/"/><linkrel="next"title="Make and register"href="../registry/"/><linkrel="prev"title="Gym Migration Guide"href="../../introduction/migration_guide/"/>
<liclass="toctree-l1 has-children"><aclass="reference internal"href="../../environments/toy_text/">Toy Text</a><inputclass="toctree-checkbox"id="toctree-checkbox-6"name="toctree-checkbox-6"role="switch"type="checkbox"/><labelfor="toctree-checkbox-6"><divclass="visually-hidden">Toggle navigation of Toy Text</div><iclass="icon"><svg><usehref="#svg-arrow-right"></use></svg></i></label><ul>
<liclass="toctree-l1 has-children"><aclass="reference internal"href="../../tutorials/gymnasium_basics/">Gymnasium Basics</a><inputclass="toctree-checkbox"id="toctree-checkbox-8"name="toctree-checkbox-8"role="switch"type="checkbox"/><labelfor="toctree-checkbox-8"><divclass="visually-hidden">Toggle navigation of Gymnasium Basics</div><iclass="icon"><svg><usehref="#svg-arrow-right"></use></svg></i></label><ul>
<liclass="toctree-l2"><aclass="reference internal"href="../../tutorials/gymnasium_basics/environment_creation/">Make your own custom environment</a></li>
<liclass="toctree-l1 has-children"><aclass="reference internal"href="../../tutorials/training_agents/">Training Agents</a><inputclass="toctree-checkbox"id="toctree-checkbox-9"name="toctree-checkbox-9"role="switch"type="checkbox"/><labelfor="toctree-checkbox-9"><divclass="visually-hidden">Toggle navigation of Training Agents</div><iclass="icon"><svg><usehref="#svg-arrow-right"></use></svg></i></label><ul>
<liclass="toctree-l2"><aclass="reference internal"href="../../tutorials/training_agents/action_masking_taxi/">Action Masking in the Taxi Environment</a></li>
<liclass="toctree-l2"><aclass="reference internal"href="../../tutorials/training_agents/action_masking_taxi/#running-the-experiment">Running the Experiment</a></li>
<liclass="toctree-l2"><aclass="reference internal"href="../../tutorials/training_agents/blackjack_q_learning/">Solving Blackjack with Tabular Q-Learning</a></li>
<liclass="toctree-l2"><aclass="reference internal"href="../../tutorials/training_agents/frozenlake_q_learning/">Solving Frozenlake with Tabular Q-Learning</a></li>
<liclass="toctree-l2"><aclass="reference internal"href="../../tutorials/training_agents/mujoco_reinforce/">Training using REINFORCE for Mujoco</a></li>
<liclass="toctree-l2"><aclass="reference internal"href="../../tutorials/training_agents/vector_a2c/">Speeding up A2C Training with Vector Envs</a></li>
<liclass="toctree-l1"><aclass="reference external"href="https://github.com/Farama-Foundation/Gymnasium/blob/main/docs/README.md">Contribute to the Docs</a></li>
<emclass="property"><spanclass="pre">class</span><spanclass="w"></span></em><spanclass="sig-prename descclassname"><spanclass="pre">gymnasium.</span></span><spanclass="sig-name descname"><spanclass="pre">Env</span></span><aclass="reference internal"href="../../_modules/gymnasium/core/#Env"><spanclass="viewcode-link"><spanclass="pre">[source]</span></span></a><aclass="headerlink"href="#gymnasium.Env"title="Link to this definition">¶</a></dt>
<dd><p>The main Gymnasium class for implementing Reinforcement Learning Agents environments.</p>
<p>The class encapsulates an environment with arbitrary behind-the-scenes dynamics through the <aclass="reference internal"href="#gymnasium.Env.step"title="gymnasium.Env.step"><codeclass="xref py py-meth docutils literal notranslate"><spanclass="pre">step()</span></code></a> and <aclass="reference internal"href="#gymnasium.Env.reset"title="gymnasium.Env.reset"><codeclass="xref py py-meth docutils literal notranslate"><spanclass="pre">reset()</span></code></a> functions.
An environment can be partially or fully observed by single agents. For multi-agent environments, see PettingZoo.</p>
<p>The main API methods that users of this class need to know are:</p>
<ulclass="simple">
<li><p><aclass="reference internal"href="#gymnasium.Env.step"title="gymnasium.Env.step"><codeclass="xref py py-meth docutils literal notranslate"><spanclass="pre">step()</span></code></a> - Updates an environment with actions returning the next agent observation, the reward for taking that actions,
if the environment has terminated or truncated due to the latest action and information from the environment about the step, i.e. metrics, debug info.</p></li>
<li><p><aclass="reference internal"href="#gymnasium.Env.reset"title="gymnasium.Env.reset"><codeclass="xref py py-meth docutils literal notranslate"><spanclass="pre">reset()</span></code></a> - Resets the environment to an initial state, required before calling step.
Returns the first agent observation for an episode and information, i.e. metrics, debug info.</p></li>
<li><p><aclass="reference internal"href="#gymnasium.Env.render"title="gymnasium.Env.render"><codeclass="xref py py-meth docutils literal notranslate"><spanclass="pre">render()</span></code></a> - Renders the environments to help visualise what the agent see, examples modes are “human”, “rgb_array”, “ansi” for text.</p></li>
<li><p><aclass="reference internal"href="#gymnasium.Env.close"title="gymnasium.Env.close"><codeclass="xref py py-meth docutils literal notranslate"><spanclass="pre">close()</span></code></a> - Closes the environment, important when external software is used, i.e. pygame for rendering, databases</p></li>
</ul>
<p>Environments have additional attributes for users to understand the implementation</p>
<li><p><aclass="reference internal"href="#gymnasium.Env.action_space"title="gymnasium.Env.action_space"><codeclass="xref py py-attr docutils literal notranslate"><spanclass="pre">action_space</span></code></a> - The Space object corresponding to valid actions, all valid actions should be contained within the space.</p></li>
<li><p><aclass="reference internal"href="#gymnasium.Env.observation_space"title="gymnasium.Env.observation_space"><codeclass="xref py py-attr docutils literal notranslate"><spanclass="pre">observation_space</span></code></a> - The Space object corresponding to valid observations, all valid observations should be contained within the space.</p></li>
<li><p><aclass="reference internal"href="../registry/#gymnasium.spec"title="gymnasium.spec"><codeclass="xref py py-attr docutils literal notranslate"><spanclass="pre">spec</span></code></a> - An environment spec that contains the information used to initialize the environment from <aclass="reference internal"href="../registry/#gymnasium.make"title="gymnasium.make"><codeclass="xref py py-meth docutils literal notranslate"><spanclass="pre">gymnasium.make()</span></code></a></p></li>
<li><p><aclass="reference internal"href="#gymnasium.Env.metadata"title="gymnasium.Env.metadata"><codeclass="xref py py-attr docutils literal notranslate"><spanclass="pre">metadata</span></code></a> - The metadata of the environment, e.g. <cite>{“render_modes”: [“rgb_array”, “human”], “render_fps”: 30}</cite>. For Jax or Torch, this can be indicated to users with <cite>“jax”=True</cite> or <cite>“torch”=True</cite>.</p></li>
<li><p><aclass="reference internal"href="#gymnasium.Env.np_random"title="gymnasium.Env.np_random"><codeclass="xref py py-attr docutils literal notranslate"><spanclass="pre">np_random</span></code></a> - The random number generator for the environment. This is automatically assigned during
<p>For modifying or extending environments use the <aclass="reference internal"href="../wrappers/#gymnasium.Wrapper"title="gymnasium.Wrapper"><codeclass="xref py py-class docutils literal notranslate"><spanclass="pre">gymnasium.Wrapper</span></code></a> class</p>
<p>To get reproducible sampling of actions, a seed can be set with <codeclass="docutils literal notranslate"><spanclass="pre">env.action_space.seed(123)</span></code>.</p>
<p>For strict type checking (e.g. mypy or pyright), <aclass="reference internal"href="#gymnasium.Env"title="gymnasium.Env"><codeclass="xref py py-class docutils literal notranslate"><spanclass="pre">Env</span></code></a> is a generic class with two parameterized types: <codeclass="docutils literal notranslate"><spanclass="pre">ObsType</span></code> and <codeclass="docutils literal notranslate"><spanclass="pre">ActType</span></code>.
The <codeclass="docutils literal notranslate"><spanclass="pre">ObsType</span></code> and <codeclass="docutils literal notranslate"><spanclass="pre">ActType</span></code> are the expected types of the observations and actions used in <aclass="reference internal"href="#gymnasium.Env.reset"title="gymnasium.Env.reset"><codeclass="xref py py-meth docutils literal notranslate"><spanclass="pre">reset()</span></code></a> and <aclass="reference internal"href="#gymnasium.Env.step"title="gymnasium.Env.step"><codeclass="xref py py-meth docutils literal notranslate"><spanclass="pre">step()</span></code></a>.
The environment’s <aclass="reference internal"href="#gymnasium.Env.observation_space"title="gymnasium.Env.observation_space"><codeclass="xref py py-attr docutils literal notranslate"><spanclass="pre">observation_space</span></code></a> and <aclass="reference internal"href="#gymnasium.Env.action_space"title="gymnasium.Env.action_space"><codeclass="xref py py-attr docutils literal notranslate"><spanclass="pre">action_space</span></code></a> should have type <codeclass="docutils literal notranslate"><spanclass="pre">Space[ObsType]</span></code> and <codeclass="docutils literal notranslate"><spanclass="pre">Space[ActType]</span></code>,
see a space’s implementation to find its parameterized type.</p>
<spanclass="sig-prename descclassname"><spanclass="pre">Env.</span></span><spanclass="sig-name descname"><spanclass="pre">step</span></span><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n"><spanclass="pre">action</span></span><spanclass="p"><spanclass="pre">:</span></span><spanclass="w"></span><spanclass="n"><spanclass="pre">ActType</span></span></em><spanclass="sig-paren">)</span><spanclass="sig-return"><spanclass="sig-return-icon">→</span><spanclass="sig-return-typehint"><spanclass="pre">tuple</span><spanclass="p"><spanclass="pre">[</span></span><spanclass="pre">ObsType</span><spanclass="p"><spanclass="pre">,</span></span><spanclass="w"></span><spanclass="pre">SupportsFloat</span><spanclass="p"><spanclass="pre">,</span></span><spanclass="w"></span><spanclass="pre">bool</span><spanclass="p"><spanclass="pre">,</span></span><spanclass="w"></span><spanclass="pre">bool</span><spanclass="p"><spanclass="pre">,</span></span><spanclass="w"></span><spanclass="pre">dict</span><spanclass="p"><spanclass="pre">[</span></span><spanclass="pre">str</span><spanclass="p"><spanclass="pre">,</span></span><spanclass="w"></span><spanclass="pre">Any</span><spanclass="p"><spanclass="pre">]</span></span><spanclass="p"><spanclass="pre">]</span></span></span></span><aclass="reference internal"href="../../_modules/gymnasium/core/#Env.step"><spanclass="viewcode-link"><spanclass="pre">[source]</span></span></a><aclass="headerlink"href="#gymnasium.Env.step"title="Link to this definition">¶</a></dt>
<dd><p>Run one timestep of the environment’s dynamics using the agent actions.</p>
<p>When the end of an episode is reached (<codeclass="docutils literal notranslate"><spanclass="pre">terminated</span><spanclass="pre">or</span><spanclass="pre">truncated</span></code>), it is necessary to call <aclass="reference internal"href="#gymnasium.Env.reset"title="gymnasium.Env.reset"><codeclass="xref py py-meth docutils literal notranslate"><spanclass="pre">reset()</span></code></a> to
reset this environment’s state for the next episode.</p>
<divclass="versionchanged">
<p><spanclass="versionmodified changed">Changed in version 0.26: </span>The Step API was changed removing <codeclass="docutils literal notranslate"><spanclass="pre">done</span></code> in favor of <codeclass="docutils literal notranslate"><spanclass="pre">terminated</span></code> and <codeclass="docutils literal notranslate"><spanclass="pre">truncated</span></code> to make it clearer
to users when the environment had terminated or truncated which is critical for reinforcement learning
<li><p><strong>observation</strong> (<em>ObsType</em>) – An element of the environment’s <aclass="reference internal"href="#gymnasium.Env.observation_space"title="gymnasium.Env.observation_space"><codeclass="xref py py-attr docutils literal notranslate"><spanclass="pre">observation_space</span></code></a> as the next observation due to the agent actions.
the Sutton and Barto Gridworld. If true, the user needs to call <aclass="reference internal"href="#gymnasium.Env.reset"title="gymnasium.Env.reset"><codeclass="xref py py-meth docutils literal notranslate"><spanclass="pre">reset()</span></code></a>.</p></li>
<li><p><strong>truncated</strong> (<em>bool</em>) – Whether the truncation condition outside the scope of the MDP is satisfied.
Typically, this is a timelimit, but could also be used to indicate an agent physically going out of bounds.
Can be used to end the episode prematurely before a terminal state is reached.
If true, the user needs to call <aclass="reference internal"href="#gymnasium.Env.reset"title="gymnasium.Env.reset"><codeclass="xref py py-meth docutils literal notranslate"><spanclass="pre">reset()</span></code></a>.</p></li>
<li><p><strong>info</strong> (<em>dict</em>) – Contains auxiliary diagnostic information (helpful for debugging, learning, and logging).
In OpenAI Gym <v26, it contains “TimeLimit.truncated” to distinguish truncation and termination,
however this is deprecated in favour of returning terminated and truncated variables.</p></li>
<li><p><strong>done</strong> (<em>bool</em>) – (Deprecated) A boolean value for if the episode has ended, in which case further <aclass="reference internal"href="#gymnasium.Env.step"title="gymnasium.Env.step"><codeclass="xref py py-meth docutils literal notranslate"><spanclass="pre">step()</span></code></a> calls will
return undefined results. This was removed in OpenAI Gym v26 in favor of terminated and truncated attributes.
A done signal may be emitted for different reasons: Maybe the task underlying the environment was solved successfully,
a certain timelimit was exceeded, or the physics simulation has entered an invalid state.</p></li>
<spanclass="sig-prename descclassname"><spanclass="pre">Env.</span></span><spanclass="sig-name descname"><spanclass="pre">reset</span></span><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="o"><spanclass="pre">*</span></span></em>, <emclass="sig-param"><spanclass="n"><spanclass="pre">seed</span></span><spanclass="p"><spanclass="pre">:</span></span><spanclass="w"></span><spanclass="n"><spanclass="pre">int</span><spanclass="w"></span><spanclass="p"><spanclass="pre">|</span></span><spanclass="w"></span><spanclass="pre">None</span></span><spanclass="w"></span><spanclass="o"><spanclass="pre">=</span></span><spanclass="w"></span><spanclass="default_value"><spanclass="pre">None</span></span></em>, <emclass="sig-param"><spanclass="n"><spanclass="pre">options</span></span><spanclass="p"><spanclass="pre">:</span></span><spanclass="w"></span><spanclass="n"><spanclass="pre">dict</span><spanclass="p"><spanclass="pre">[</span></span><spanclass="pre">str</span><spanclass="p"><spanclass="pre">,</span></span><spanclass="w"></span><spanclass="pre">Any</span><spanclass="p"><spanclass="pre">]</span></span><spanclass="w"></span><spanclass="p"><spanclass="pre">|</span></span><spanclass="w"></span><spanclass="pre">None</span></span><spanclass="w"></span><spanclass="o"><spanclass="pre">=</span></span><spanclass="w"></span><spanclass="default_value"><spanclass="pre">None</span></span></em><spanclass="sig-paren">)</span><spanclass="sig-return"><spanclass="sig-return-icon">→</span><spanclass="sig-return-typehint"><spanclass="pre">tuple</span><spanclass="p"><spanclass="pre">[</span></span><spanclass="pre">ObsType</span><spanclass="p"><spanclass="pre">,</span></span><spanclass="w"></span><spanclass="pre">dict</span><spanclass="p"><spanclass="pre">[</span></span><spanclass="pre">str</span><spanclass="p"><spanclass="pre">,</span></span><spanclass="w"></span><spanclass="pre">Any</span><spanclass="p"><spanclass="pre">]</span></span><spanclass="p"><spanclass="pre">]</span></span></span></span><aclass="reference internal"href="../../_modules/gymnasium/core/#Env.reset"><spanclass="viewcode-link"><spanclass="pre">[source]</span></span></a><aclass="headerlink"href="#gymnasium.Env.reset"title="Link to this definition">¶</a></dt>
<dd><p>Resets the environment to an initial internal state, returning an initial observation and info.</p>
<p>This method generates a new starting state often with some randomness to ensure that the agent explores the
state space and learns a generalised policy about the environment. This randomness can be controlled
with the <codeclass="docutils literal notranslate"><spanclass="pre">seed</span></code> parameter otherwise if the environment already has a random number generator and
<aclass="reference internal"href="#gymnasium.Env.reset"title="gymnasium.Env.reset"><codeclass="xref py py-meth docutils literal notranslate"><spanclass="pre">reset()</span></code></a> is called with <codeclass="docutils literal notranslate"><spanclass="pre">seed=None</span></code>, the RNG is not reset.</p>
<p>Therefore, <aclass="reference internal"href="#gymnasium.Env.reset"title="gymnasium.Env.reset"><codeclass="xref py py-meth docutils literal notranslate"><spanclass="pre">reset()</span></code></a> should (in the typical use case) be called with a seed right after initialization and then never again.</p>
<p>For Custom environments, the first line of <aclass="reference internal"href="#gymnasium.Env.reset"title="gymnasium.Env.reset"><codeclass="xref py py-meth docutils literal notranslate"><spanclass="pre">reset()</span></code></a> should be <codeclass="docutils literal notranslate"><spanclass="pre">super().reset(seed=seed)</span></code> which implements
the seeding correctly.</p>
<divclass="versionchanged">
<p><spanclass="versionmodified changed">Changed in version v0.25: </span>The <codeclass="docutils literal notranslate"><spanclass="pre">return_info</span></code> parameter was removed and now info is expected to be returned.</p>
If the environment does not already have a PRNG and <codeclass="docutils literal notranslate"><spanclass="pre">seed=None</span></code> (the default option) is passed,
a seed will be chosen from some source of entropy (e.g. timestamp or /dev/urandom).
However, if the environment already has a PRNG and <codeclass="docutils literal notranslate"><spanclass="pre">seed=None</span></code> is passed, the PRNG will <em>not</em> be reset
and the env’s <aclass="reference internal"href="#gymnasium.Env.np_random_seed"title="gymnasium.Env.np_random_seed"><codeclass="xref py py-attr docutils literal notranslate"><spanclass="pre">np_random_seed</span></code></a> will <em>not</em> be altered.
<li><p><strong>observation</strong> (<em>ObsType</em>) – Observation of the initial state. This will be an element of <aclass="reference internal"href="#gymnasium.Env.observation_space"title="gymnasium.Env.observation_space"><codeclass="xref py py-attr docutils literal notranslate"><spanclass="pre">observation_space</span></code></a>
(typically a numpy array) and is analogous to the observation returned by <aclass="reference internal"href="#gymnasium.Env.step"title="gymnasium.Env.step"><codeclass="xref py py-meth docutils literal notranslate"><spanclass="pre">step()</span></code></a>.</p></li>
<li><p><strong>info</strong> (<em>dictionary</em>) – This dictionary contains auxiliary information complementing <codeclass="docutils literal notranslate"><spanclass="pre">observation</span></code>. It should be analogous to
the <codeclass="docutils literal notranslate"><spanclass="pre">info</span></code> returned by <aclass="reference internal"href="#gymnasium.Env.step"title="gymnasium.Env.step"><codeclass="xref py py-meth docutils literal notranslate"><spanclass="pre">step()</span></code></a>.</p></li>
<spanclass="sig-prename descclassname"><spanclass="pre">Env.</span></span><spanclass="sig-name descname"><spanclass="pre">render</span></span><spanclass="sig-paren">(</span><spanclass="sig-paren">)</span><spanclass="sig-return"><spanclass="sig-return-icon">→</span><spanclass="sig-return-typehint"><spanclass="pre">RenderFrame</span><spanclass="w"></span><spanclass="p"><spanclass="pre">|</span></span><spanclass="w"></span><spanclass="pre">list</span><spanclass="p"><spanclass="pre">[</span></span><spanclass="pre">RenderFrame</span><spanclass="p"><spanclass="pre">]</span></span><spanclass="w"></span><spanclass="p"><spanclass="pre">|</span></span><spanclass="w"></span><spanclass="pre">None</span></span></span><aclass="reference internal"href="../../_modules/gymnasium/core/#Env.render"><spanclass="viewcode-link"><spanclass="pre">[source]</span></span></a><aclass="headerlink"href="#gymnasium.Env.render"title="Link to this definition">¶</a></dt>
<dd><p>Compute the render frames as specified by <aclass="reference internal"href="#gymnasium.Env.render_mode"title="gymnasium.Env.render_mode"><codeclass="xref py py-attr docutils literal notranslate"><spanclass="pre">render_mode</span></code></a> during the initialization of the environment.</p>
<p>The environment’s <aclass="reference internal"href="#gymnasium.Env.metadata"title="gymnasium.Env.metadata"><codeclass="xref py py-attr docutils literal notranslate"><spanclass="pre">metadata</span></code></a> render modes (<cite>env.metadata[“render_modes”]</cite>) should contain the possible
ways to implement the render modes. In addition, list versions for most render modes is achieved through
<cite>gymnasium.make</cite> which automatically applies a wrapper to collect rendered frames.</p>
<divclass="admonition note">
<pclass="admonition-title">Note</p>
<p>As the <aclass="reference internal"href="#gymnasium.Env.render_mode"title="gymnasium.Env.render_mode"><codeclass="xref py py-attr docutils literal notranslate"><spanclass="pre">render_mode</span></code></a> is known during <codeclass="docutils literal notranslate"><spanclass="pre">__init__</span></code>, the objects used to render the environment state
should be initialised in <codeclass="docutils literal notranslate"><spanclass="pre">__init__</span></code>.</p>
</div>
<p>By convention, if the <aclass="reference internal"href="#gymnasium.Env.render_mode"title="gymnasium.Env.render_mode"><codeclass="xref py py-attr docutils literal notranslate"><spanclass="pre">render_mode</span></code></a> is:</p>
<li><p>“human”: The environment is continuously rendered in the current display or terminal, usually for human consumption.
This rendering should occur during <aclass="reference internal"href="#gymnasium.Env.step"title="gymnasium.Env.step"><codeclass="xref py py-meth docutils literal notranslate"><spanclass="pre">step()</span></code></a> and <aclass="reference internal"href="#gymnasium.Env.render"title="gymnasium.Env.render"><codeclass="xref py py-meth docutils literal notranslate"><spanclass="pre">render()</span></code></a> doesn’t need to be called. Returns <codeclass="docutils literal notranslate"><spanclass="pre">None</span></code>.</p></li>
<li><p>“rgb_array”: Return a single frame representing the current state of the environment.
A frame is a <codeclass="docutils literal notranslate"><spanclass="pre">np.ndarray</span></code> with shape <codeclass="docutils literal notranslate"><spanclass="pre">(x,</span><spanclass="pre">y,</span><spanclass="pre">3)</span></code> representing RGB values for an x-by-y pixel image.</p></li>
<li><p>“ansi”: Return a strings (<codeclass="docutils literal notranslate"><spanclass="pre">str</span></code>) or <codeclass="docutils literal notranslate"><spanclass="pre">StringIO.StringIO</span></code> containing a terminal-style text representation
for each time step. The text can include newlines and ANSI escape sequences (e.g. for colors).</p></li>
<li><p>“rgb_array_list” and “ansi_list”: List based version of render modes are possible (except Human) through the
wrapper, <aclass="reference internal"href="../wrappers/misc_wrappers/#gymnasium.wrappers.RenderCollection"title="gymnasium.wrappers.RenderCollection"><codeclass="xref py py-class docutils literal notranslate"><spanclass="pre">gymnasium.wrappers.RenderCollection</span></code></a> that is automatically applied during <codeclass="docutils literal notranslate"><spanclass="pre">gymnasium.make(...,</span><spanclass="pre">render_mode="rgb_array_list")</span></code>.
The frames collected are popped after <aclass="reference internal"href="#gymnasium.Env.render"title="gymnasium.Env.render"><codeclass="xref py py-meth docutils literal notranslate"><spanclass="pre">render()</span></code></a> is called or <aclass="reference internal"href="#gymnasium.Env.reset"title="gymnasium.Env.reset"><codeclass="xref py py-meth docutils literal notranslate"><spanclass="pre">reset()</span></code></a>.</p></li>
<p>Make sure that your class’s <aclass="reference internal"href="#gymnasium.Env.metadata"title="gymnasium.Env.metadata"><codeclass="xref py py-attr docutils literal notranslate"><spanclass="pre">metadata</span></code></a><codeclass="docutils literal notranslate"><spanclass="pre">"render_modes"</span></code> key includes the list of supported modes.</p>
</div>
<divclass="versionchanged">
<p><spanclass="versionmodified changed">Changed in version 0.25.0: </span>The render function was changed to no longer accept parameters, rather these parameters should be specified
in the environment initialised, i.e., <codeclass="docutils literal notranslate"><spanclass="pre">gymnasium.make("CartPole-v1",</span><spanclass="pre">render_mode="human")</span></code></p>
<spanclass="sig-prename descclassname"><spanclass="pre">Env.</span></span><spanclass="sig-name descname"><spanclass="pre">close</span></span><spanclass="sig-paren">(</span><spanclass="sig-paren">)</span><aclass="reference internal"href="../../_modules/gymnasium/core/#Env.close"><spanclass="viewcode-link"><spanclass="pre">[source]</span></span></a><aclass="headerlink"href="#gymnasium.Env.close"title="Link to this definition">¶</a></dt>
<dd><p>After the user has finished using the environment, close contains the code necessary to “clean up” the environment.</p>
<p>This is critical for closing rendering windows, database or HTTP connections.
Calling <codeclass="docutils literal notranslate"><spanclass="pre">close</span></code> on an already closed environment has no effect and won’t raise an error.</p>
<spanclass="sig-prename descclassname"><spanclass="pre">Env.</span></span><spanclass="sig-name descname"><spanclass="pre">action_space</span></span><emclass="property"><spanclass="p"><spanclass="pre">:</span></span><spanclass="w"></span><aclass="reference internal"href="../spaces/#gymnasium.spaces.Space"title="gymnasium.spaces.Space"><spanclass="pre">spaces.Space</span></a><spanclass="p"><spanclass="pre">[</span></span><spanclass="pre">ActType</span><spanclass="p"><spanclass="pre">]</span></span></em><aclass="headerlink"href="#gymnasium.Env.action_space"title="Link to this definition">¶</a></dt>
<dd><p>The Space object corresponding to valid actions, all valid actions should be contained with the space. For example, if the action space is of type <cite>Discrete</cite> and gives the value <cite>Discrete(2)</cite>, this means there are two valid discrete actions: <cite>0</cite>&<cite>1</cite>.</p>
<spanclass="sig-prename descclassname"><spanclass="pre">Env.</span></span><spanclass="sig-name descname"><spanclass="pre">observation_space</span></span><emclass="property"><spanclass="p"><spanclass="pre">:</span></span><spanclass="w"></span><aclass="reference internal"href="../spaces/#gymnasium.spaces.Space"title="gymnasium.spaces.Space"><spanclass="pre">spaces.Space</span></a><spanclass="p"><spanclass="pre">[</span></span><spanclass="pre">ObsType</span><spanclass="p"><spanclass="pre">]</span></span></em><aclass="headerlink"href="#gymnasium.Env.observation_space"title="Link to this definition">¶</a></dt>
<dd><p>The Space object corresponding to valid observations, all valid observations should be contained with the space. For example, if the observation space is of type <codeclass="xref py py-class docutils literal notranslate"><spanclass="pre">Box</span></code> and the shape of the object is <codeclass="docutils literal notranslate"><spanclass="pre">(4,)</span></code>, this denotes a valid observation will be an array of 4 numbers. We can check the box bounds as well with attributes.</p>
<spanclass="sig-prename descclassname"><spanclass="pre">Env.</span></span><spanclass="sig-name descname"><spanclass="pre">metadata</span></span><emclass="property"><spanclass="p"><spanclass="pre">:</span></span><spanclass="w"></span><spanclass="pre">dict</span><spanclass="p"><spanclass="pre">[</span></span><spanclass="pre">str</span><spanclass="p"><spanclass="pre">,</span></span><spanclass="w"></span><spanclass="pre">Any</span><spanclass="p"><spanclass="pre">]</span></span></em><emclass="property"><spanclass="w"></span><spanclass="p"><spanclass="pre">=</span></span><spanclass="w"></span><spanclass="pre">{'render_modes':</span><spanclass="pre">[]}</span></em><aclass="headerlink"href="#gymnasium.Env.metadata"title="Link to this definition">¶</a></dt>
<spanclass="sig-prename descclassname"><spanclass="pre">Env.</span></span><spanclass="sig-name descname"><spanclass="pre">render_mode</span></span><emclass="property"><spanclass="p"><spanclass="pre">:</span></span><spanclass="w"></span><spanclass="pre">str</span><spanclass="w"></span><spanclass="p"><spanclass="pre">|</span></span><spanclass="w"></span><spanclass="pre">None</span></em><emclass="property"><spanclass="w"></span><spanclass="p"><spanclass="pre">=</span></span><spanclass="w"></span><spanclass="pre">None</span></em><aclass="headerlink"href="#gymnasium.Env.render_mode"title="Link to this definition">¶</a></dt>
<spanclass="sig-prename descclassname"><spanclass="pre">Env.</span></span><spanclass="sig-name descname"><spanclass="pre">spec</span></span><emclass="property"><spanclass="p"><spanclass="pre">:</span></span><spanclass="w"></span><aclass="reference internal"href="../registry/#gymnasium.envs.registration.EnvSpec"title="gymnasium.envs.registration.EnvSpec"><spanclass="pre">EnvSpec</span></a><spanclass="w"></span><spanclass="p"><spanclass="pre">|</span></span><spanclass="w"></span><spanclass="pre">None</span></em><emclass="property"><spanclass="w"></span><spanclass="p"><spanclass="pre">=</span></span><spanclass="w"></span><spanclass="pre">None</span></em><aclass="headerlink"href="#gymnasium.Env.spec"title="Link to this definition">¶</a></dt>
<dd><p>The <codeclass="xref py py-class docutils literal notranslate"><spanclass="pre">EnvSpec</span></code> of the environment normally set during <aclass="reference internal"href="../registry/#gymnasium.make"title="gymnasium.make"><codeclass="xref py py-meth docutils literal notranslate"><spanclass="pre">gymnasium.make()</span></code></a></p>
<emclass="property"><spanclass="pre">property</span><spanclass="w"></span></em><spanclass="sig-prename descclassname"><spanclass="pre">Env.</span></span><spanclass="sig-name descname"><spanclass="pre">unwrapped</span></span><emclass="property"><spanclass="p"><spanclass="pre">:</span></span><spanclass="w"></span><aclass="reference internal"href="#gymnasium.Env"title="gymnasium.core.Env"><spanclass="pre">Env</span></a><spanclass="p"><spanclass="pre">[</span></span><spanclass="pre">ObsType</span><spanclass="p"><spanclass="pre">,</span></span><spanclass="w"></span><spanclass="pre">ActType</span><spanclass="p"><spanclass="pre">]</span></span></em><aclass="headerlink"href="#gymnasium.Env.unwrapped"title="Link to this definition">¶</a></dt>
<emclass="property"><spanclass="pre">property</span><spanclass="w"></span></em><spanclass="sig-prename descclassname"><spanclass="pre">Env.</span></span><spanclass="sig-name descname"><spanclass="pre">np_random</span></span><emclass="property"><spanclass="p"><spanclass="pre">:</span></span><spanclass="w"></span><spanclass="pre">Generator</span></em><aclass="headerlink"href="#gymnasium.Env.np_random"title="Link to this definition">¶</a></dt>
<dd><p>Returns the environment’s internal <codeclass="xref py py-attr docutils literal notranslate"><spanclass="pre">_np_random</span></code> that if not set will initialise with a random seed.</p>
<emclass="property"><spanclass="pre">property</span><spanclass="w"></span></em><spanclass="sig-prename descclassname"><spanclass="pre">Env.</span></span><spanclass="sig-name descname"><spanclass="pre">np_random_seed</span></span><emclass="property"><spanclass="p"><spanclass="pre">:</span></span><spanclass="w"></span><spanclass="pre">int</span></em><aclass="headerlink"href="#gymnasium.Env.np_random_seed"title="Link to this definition">¶</a></dt>
<dd><p>Returns the environment’s internal <codeclass="xref py py-attr docutils literal notranslate"><spanclass="pre">_np_random_seed</span></code> that if not set will first initialise with a random int as seed.</p>
<p>If <aclass="reference internal"href="#gymnasium.Env.np_random_seed"title="gymnasium.Env.np_random_seed"><codeclass="xref py py-attr docutils literal notranslate"><spanclass="pre">np_random_seed</span></code></a> was set directly instead of through <aclass="reference internal"href="#gymnasium.Env.reset"title="gymnasium.Env.reset"><codeclass="xref py py-meth docutils literal notranslate"><spanclass="pre">reset()</span></code></a> or <codeclass="xref py py-meth docutils literal notranslate"><spanclass="pre">set_np_random_through_seed()</span></code>,
<h2>Implementing environments<aclass="headerlink"href="#implementing-environments"title="Link to this heading">¶</a></h2>
<p>When implementing an environment, the <aclass="reference internal"href="#gymnasium.Env.reset"title="gymnasium.Env.reset"><codeclass="xref py py-meth docutils literal notranslate"><spanclass="pre">Env.reset()</span></code></a> and <aclass="reference internal"href="#gymnasium.Env.step"title="gymnasium.Env.step"><codeclass="xref py py-meth docutils literal notranslate"><spanclass="pre">Env.step()</span></code></a> functions must be created to describe the dynamics of the environment. For more information, see the environment creation tutorial.</p>
<h2>Creating environments<aclass="headerlink"href="#creating-environments"title="Link to this heading">¶</a></h2>
<p>To create an environment, gymnasium provides <aclass="reference internal"href="../registry/#gymnasium.make"title="gymnasium.make"><codeclass="xref py py-meth docutils literal notranslate"><spanclass="pre">make()</span></code></a> to initialise the environment along with several important wrappers. Furthermore, gymnasium provides <aclass="reference internal"href="../registry/#gymnasium.make_vec"title="gymnasium.make_vec"><codeclass="xref py py-meth docutils literal notranslate"><spanclass="pre">make_vec()</span></code></a> for creating vector environments and to view all the environment that can be created use <aclass="reference internal"href="../registry/#gymnasium.pprint_registry"title="gymnasium.pprint_registry"><codeclass="xref py py-meth docutils literal notranslate"><spanclass="pre">pprint_registry()</span></code></a>.</p>