API Reference

Users

class pyanywhere.users.User(name, token=None)

The User class represents a PythonAnywhere user. It is the central object because it has to be used in order to access anything else. When running this module from PythonAnywhere, the pyanywhere.users.get_current_user() function can be used to automatically generate this object.

Parameters:
  • name – The username.
  • token – The API token that is associated with the user.
get_consoles()

This method gets the consoles that are running on the user.

Returns:A geterator yielding pyanywhere.consoles.Console objects.
get_shared_consoles()

A variant of get_consoles() that yields consoles shared with the user.

start_console(exec_name, args, working_dir)

This method starts a new console.

Parameters:
  • exec_name – The name of the executable used for the console. For example, you can set this to 'bash' to start a Bash console.
  • args – The command line arguments passed to exec_name. This must be a string.
  • working_dir – The initial working directory of the console.
Returns:

A pyanywhere.consoles.Console object.

pyanywhere.users.get_current_user()

This function can be used to return a pyanywhere.users.User object if this module is running on PythonAnyhwere. It gets your username by getting your Linux username, and it gets your API token from the API_TOKEN environment variable.

Consoles

class pyanywhere.consoles.Console(id, owner, executable, arguments, working_dir, name, url, frame_url)

Represents a console. Can be retrieved from the pyanywhere.users.User class.

get_latest_output(replace_newlines=False)

Gets the latest output from the console. This will contain CRLF (Windows, \r\n) newlines. According to the API’s help page, this will return approximately 500 characters.

Parameters:replace_newlines – Replace \r\n with \n.
Returns:A string
kill()

Kills the console.

send_input(data)

Sends a string to the console’s stdin (types into the console).

Parameters:data – The string to send to the console.