The PythonAnywhere API (beta)

Disclaimer

Warning: our API is new and in beta and not officially supported, and may change at any time, and it is not to be relied upon, and may cause unpredictable growth of extra ears. Extra ears not guaranteed.

Getting started and Authentication

The PythonAnywhere API uses token-based authentication. You can get your token from the Accounts page

It's used in a header called Authorization, and the value is encoded as the string "Token", followed by a space, followed by your token, like this:

'Authorization': 'Token {}'.format(token)

Again, you can see a nice example on the Accounts page

Once you've generated your token, you can copy and paste it for use in your scripts. You can also access it at any time from PythonAnywhere consoles, webapps and tasks in a pre-populated environment variable, $API_TOKEN.

Endpoints

All endpoints are hosted at https://www.pythonanywhere.com/

/api/v0/user/{username}/consoles/

Method Description Parameters
GET List all your consoles (no parameters)

/api/v0/user/{username}/consoles/shared_with_you/

Method Description Parameters
GET View consoles shared with you (no parameters)

/api/v0/user/{username}/consoles/{id}/

Method Description Parameters
GET Return information about a console instance. (no parameters)
DELETE Kill a console. (no parameters)

/api/v0/user/{username}/files/sharing/

Method Description Parameters
POST Start sharing a file. Returns 201 on success, or 200 if file was already shared. POST parameter: path

/api/v0/user/{username}/files/sharing/?path={path}

Method Description Parameters
GET Check sharing status for a path. Returns 404 if path not currently shared. Query parameter: path
DELETE Stop sharing a path. Returns 204 on successful unshare. Query parameter: path

/api/v0/user/{username}/files/tree/?path={path}

Method Description Parameters
GET Returns a list of the contents of a directory, and its subdirectories as a list. Paths ending in slash/ represent directories. Limited to 1000 results. Query parameter: path

/api/v0/user/{username}/webapps/

Method Description Parameters
GET List all webapps (no parameters)
POST Create a new webapp with manual configuration. Python versions are specified in this form: python27 etc. POST parameters: domain_name, python_version

/api/v0/user/{username}/webapps/{domain_name}/

Method Description Parameters
GET Return information about a web app's configuration (no parameters)
PUT Modify configuration of a web app. (NB a reload is usually required to apply changes). python_version, virtualenv_path
PATCH Modify configuration of a web app. (NB a reload is usually required to apply changes). python_version, virtualenv_path
DELETE Delete the webapp. This will take the site offline. Config is backed up in /var/www, and your code is not touched. (no parameters)

/api/v0/user/{username}/webapps/{domain_name}/reload/

Method Description Parameters
POST Reload the webapp to reflect changes to configuration and/or source code on disk. POST parameters: none.

/api/v0/user/{username}/webapps/{domain_name}/static_files/

Method Description Parameters
GET List all the static files mappings for a domain. (no parameters)
POST Create a new static files mapping. (webapp restart required) url, path

/api/v0/user/{username}/webapps/{domain_name}/static_files/{id}/

Method Description Parameters
GET Get URL and path of a particular mapping. (no parameters)
PUT Modify a static files mapping. (webapp restart required) url, path
PATCH Modify a static files mapping. (webapp restart required) url, path
DELETE Remove a static files mapping. (webapp restart required) (no parameters)

All endpoints are hosted at https://www.pythonanywhere.com/