exception textworld.render.render.WebdriverNotFoundError[source]

Bases: Exception

class textworld.render.render.GraphItem(type, name)[source]

Bases: object


Returns the maximum nest depth of this plus all children. A container with no items has 1 depth, a container containing one item has 2 depth, a container containing a container which contains an item has 3 depth, and so on. :return: maximum nest depth

property infos
class textworld.render.render.GraphRoom(name, base_room)[source]

Bases: object

Return type


Return type



Get the driver and options objects. :param path: path to browser binary. :return: driver

textworld.render.render.load_state(world, game_infos=None, action=None, format='png', limit_player_view=False)[source]

Generates serialization of game state.

  • world (World) – The current state of the world to visualize.

  • game_infos (Optional[Dict[str, EntityInfo]]) – The mapping needed to get objects names.

  • action (Optional[Action]) – If provided, highlight the world changes made by that action.

  • format (str) – The graph output format (gv, svg, png…)

  • limit_player_view (bool) – Whether to limit the player’s view (defaults to false)

Return type



The graph generated from this World

textworld.render.render.load_state_from_game_state(game_state, format='png', limit_player_view=False)[source]

Generates serialization of game state.

  • game_state (GameState) – The current game state to visualize.

  • format (str) – The graph output format (png, svg, pdf, …)

  • limit_player_view (bool) – Whether to limit the player’s view. Default: False.

Return type



The graph generated from this World

textworld.render.render.take_screenshot(url, id='world')[source]

Takes a screenshot of DOM element given its id. :type url: str :param url: URL of webpage to open headlessly. :type id: str :param id: ID of DOM element. :return: Image object.

textworld.render.render.temp_viz(nodes, edges, pos, color=[])[source]
textworld.render.render.visualize(world, interactive=False)[source]

Show the current state of the world. :type world: Union[Game, State, GameState, World] :param world: Object representing a game state to be visualized. :type interactive: bool :param interactive: Whether or not to visualize the state in the browser. :return: Image object of the visualization.


helper to see if a program is in PATH :param program: name of program :return: path of program or None

Creates server for streamed game state

class textworld.render.serve.Server(game_state, port)[source]

Bases: object

Visualization server. Uses Server-sent Events to update game_state for visualization.

Note: Flask routes are defined in app.add_url_rule in order to call self in routes. :type game_state: dict :param game_state: game state returned from load_state_from_game_state :type port: int :param port: port to run visualization on


Our generator for listening for updating state. We poll for results to return us something. If nothing is returned then we just pass and keep polling. :return: yields event-stream parsed data.


Index route (“/”). Returns HTML template processed by handlebars. :rtype: str :return: Flask response object

static listen(conn, results)[source]

Listener for updates. Runs on separate thread. :type conn: Connection :param conn: child connection from multiprocessing.Pipe. :type results: Queue :param results: thread-safe queue for results.


Starts the WSGI server and listen for updates on a separate thread.


child_conn (Connection) – Child connection from multiprocessing.Pipe.


Our Server-sent Event stream route. :return: A stream


Updates all subscribers and updates their data. This is for multiple subscribers on the visualization service. :type game_state: dict :param game_state: parsed game_state from load_state_from_game_state

class textworld.render.serve.ServerSentEvent(data)[source]

Bases: object

Object helper to parse dict into SSE data. :type data: any :param data: data to pass to SSE

class textworld.render.serve.SupressStdStreams[source]

Bases: object

for surpressing std.out streams

class textworld.render.serve.VisualizationService(game_state, open_automatically)[source]

Bases: object

Server for visualization.

We instantiate a new process for our flask server, so our game can send updates to the server. The server instantiates new gevent Queues for every connection.

start(parent_thread, port)[source]

Start visualization server on a new process. :type parent_thread: Thread :param parent_thread: the parent thread that called start. :type port: int :param port: Port to run visualization on.

Return type


start_server(game_state, port, child_conn)[source]

function for starting new server on new process. :type game_state: dict :param game_state: initial game state from load :type port: int :param port: port to run server :type child_conn: Connection :param child_conn: child connection from multiprocessing.Pipe

update_state(game_state, command)[source]

Propogate state update to server. We use a multiprocessing.Pipe to pass state into flask process. :type game_state: GameState :param game_state: Glulx game state. :type command: str :param command: previous command