Status: Archive (code is provided as-is, no updates expected)
This project provides a local REST API to the gym open-source library, allowing development in languages other than python.
A python client is included, to demonstrate how to interact with the server.
Contributions of clients in other languages are welcomed!
To download the code and install the requirements, you can run the following shell commands:
git clone https://github.com/openai/gym-http-api
cd gym-http-api
pip install -r requirements.txt
This code is intended to be run locally by a single user. The server runs in python. You can implement your own HTTP clients using any language; a demo client written in python is provided to demonstrate the idea.
To start the server from the command line, run this:
python gym_http_server.py
In a separate terminal, you can then try running the example python agent and see what happens:
python example_agent.py
The example lua agent behaves very similarly:
cd binding-lua
lua example_agent.lua
You can also write code like this to create your own client, and test it out by creating a new environment. For example, in python:
remote_base = 'http://127.0.0.1:5000'
client = Client(remote_base)
env_id = 'CartPole-v0'
instance_id = client.env_create(env_id)
client.env_step(instance_id, 0)
This repository contains integration tests, using the python client implementation to send requests to the local server. They can be run using the nose2
framework. From a shell (such as bash) you can run nose2 directly:
cd gym-http-api
nose2
POST /v1/envs/
env_id
-- gym environment ID string, such as 'CartPole-v0'instance_id
-- a short identifier (such as '3c657dbc')
for the created environment instance. The instance_id is
used in future API calls to identify the environment to be
manipulatedGET /v1/envs/
envs
-- dict mapping instance_id
to env_id
(e.g. {'3c657dbc': 'CartPole-v0'}
) for every env on the serverPOST /v1/envs/<instance_id>/reset/
instance_id
-- a short identifier (such as '3c657dbc')
for the environment instanceobservation
-- the initial observation of the spacePOST /v1/envs/<instance_id>/step/
instance_id
-- a short identifier (such as '3c657dbc')
for the environment instanceaction
-- an action to take in the environmentobservation
-- agent's observation of the current
environmentreward
-- amount of reward returned after previous actiondone
-- whether the episode has endedinfo
-- a dict containing auxiliary diagnostic informationGET /v1/envs/<instance_id>/action_space/
action_space
instance_id
-- a short identifier (such as '3c657dbc')
for the environment instanceinfo
-- a dict containing 'name' (such as 'Discrete'), and
additional dimensional info (such as 'n') which varies from
space to spaceGET /v1/envs/<instance_id>/observation_space/
observation_space
instance_id
-- a short identifier (such as '3c657dbc')
for the environment instanceinfo
-- a dict containing 'name' (such as 'Discrete'), and
additional dimensional info (such as 'n') which varies from
space to spacePOST /v1/envs/<instance_id>/monitor/start/
instance_id
-- a short identifier (such as '3c657dbc')
for the environment instanceforce
(default=False) -- Clear out existing training
data from this directory (by deleting every file
prefixed with "openaigym.")resume
(default=False) -- Retain the training data
already in this directory, which will be merged with
our new datavideo_callable
parameter from the native
env.monitor.start
function is NOT implemented)POST /v1/envs/<instance_id>/monitor/close/
instance_id
-- a short identifier (such as '3c657dbc')
for the environment instancePOST /v1/upload/
training_dir
-- A directory containing the results of a
training run.api_key
-- Your OpenAI API keyalgorithm_id
(default=None) -- An arbitrary string
indicating the paricular version of the algorithm
(including choices of parameters) you are running.POST /v1/shutdown/
See the [contributors page] (https://github.com/openai/gym-http-api/graphs/contributors)