or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

tessl/pypi-gymnasium

A standard API for reinforcement learning and a diverse set of reference environments (formerly Gym).

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/gymnasium@1.2.x

To install, run

npx @tessl/cli install tessl/pypi-gymnasium@1.2.0

0

# Gymnasium

1

2

Gymnasium is a comprehensive Python library that provides a standardized API for developing and comparing reinforcement learning algorithms, serving as the maintained fork of OpenAI's Gym. It offers a diverse collection of environments including Classic Control (physics-based problems), Box2D (physics simulations), Toy Text (simple discrete environments), MuJoCo (complex multi-joint physics control), and Atari (game emulation environments).

3

4

## Package Information

5

6

- **Package Name**: gymnasium

7

- **Language**: Python

8

- **Installation**: `pip install gymnasium`

9

10

## Core Imports

11

12

```python

13

import gymnasium as gym

14

```

15

16

For working with specific components:

17

18

```python

19

from gymnasium import Env, Wrapper, Space

20

from gymnasium import make, register, spaces, wrappers

21

```

22

23

## Basic Usage

24

25

```python

26

import gymnasium as gym

27

28

# Create an environment

29

env = gym.make('CartPole-v1', render_mode='human')

30

31

# Reset environment to get initial observation

32

observation, info = env.reset(seed=42)

33

34

for _ in range(1000):

35

# Take a random action

36

action = env.action_space.sample()

37

38

# Execute the action

39

observation, reward, terminated, truncated, info = env.step(action)

40

41

# Check if episode is done

42

if terminated or truncated:

43

observation, info = env.reset()

44

45

env.close()

46

```

47

48

## Architecture

49

50

Gymnasium's architecture is built around several core concepts:

51

52

- **Environment (Env)**: The main interface that defines the reinforcement learning task through step, reset, render, and close methods

53

- **Space**: Defines the structure and constraints of action and observation spaces

54

- **Wrapper**: Modifies environment behavior without changing the underlying environment

55

- **Registration System**: Manages environment discovery and instantiation through string IDs

56

- **Vector Environments**: Enables parallel execution of multiple environment instances

57

58

This design provides a flexible, extensible framework that serves as the standard interface for reinforcement learning in Python.

59

60

## Capabilities

61

62

### Core API

63

64

The fundamental classes and interfaces that form the foundation of all Gymnasium environments and wrappers.

65

66

```python { .api }

67

class Env:

68

def step(self, action): ...

69

def reset(self, *, seed=None, options=None): ...

70

def render(self): ...

71

def close(self): ...

72

73

class Wrapper(Env):

74

def __init__(self, env): ...

75

```

76

77

[Core API](./core-api.md)

78

79

### Environment Registration

80

81

Functions for discovering, creating, and managing environments through the global registry system.

82

83

```python { .api }

84

def make(id: str | EnvSpec, max_episode_steps: int | None = None, **kwargs) -> Env: ...

85

def register(id: str, entry_point: str, **kwargs) -> None: ...

86

def spec(id: str) -> EnvSpec: ...

87

```

88

89

[Environment Registration](./registration.md)

90

91

### Spaces

92

93

Defines action and observation spaces with various types including continuous, discrete, composite, and structured spaces.

94

95

```python { .api }

96

class Box(Space): ...

97

class Discrete(Space): ...

98

class Dict(Space): ...

99

class Tuple(Space): ...

100

```

101

102

[Spaces](./spaces.md)

103

104

### Environment Wrappers

105

106

Pre-built wrappers for modifying environment behavior including observation transformation, action modification, reward shaping, and rendering enhancements.

107

108

```python { .api }

109

class TimeLimit(Wrapper): ...

110

class FlattenObservation(ObservationWrapper): ...

111

class ClipAction(ActionWrapper): ...

112

class NormalizeReward(RewardWrapper): ...

113

```

114

115

[Environment Wrappers](./wrappers.md)

116

117

### Vector Environments

118

119

Batched environment execution for improved performance when training with multiple parallel environments.

120

121

```python { .api }

122

class VectorEnv: ...

123

class SyncVectorEnv(VectorEnv): ...

124

class AsyncVectorEnv(VectorEnv): ...

125

```

126

127

[Vector Environments](./vector-environments.md)