Web Apps

class webapp.Webapp(domain: str)[source]

Interface for PythonAnywhere webapps API. Uses pythonanywhere_core.base :method: get_api_endpoint to create url, which is stored in a class variable Webapp.base_url, then calls call_api with appropriate arguments to execute webapps action.

Methods:
Class Methods:
add_default_static_files_mappings(project_path: Path) None[source]

Add default static files mappings for /static/ and /media/.

Parameters:

project_path – path to the project

Raises:

PythonAnywhereApiException – if API call fails

create(python_version: str, virtualenv_path: Path | None, project_path: Path, nuke: bool) None[source]

Create a webapp for the given domain, using the given python version and virtualenv path

Parameters:
  • python_version – python version to use

  • virtualenv_path – path to the virtualenv, or None to skip setting it

  • project_path – path to the project

  • nuke – if True, delete any existing webapp for this domain

Raises:

PythonAnywhereApiException – if API call fails

create_static_file_mapping(url_path: str, directory_path: Path) None[source]

Create a static file mapping via the API.

Parameters:
  • url_path – URL path (e.g., ‘/static/’)

  • directory_path – Filesystem path to serve (as Path)

Raises:

PythonAnywhereApiException – if API call fails

delete() None[source]

Delete webapp.

Raises:

PythonAnywhereApiException – if API call fails

delete_log(log_type: str, index: int = 0) None[source]

Delete log file

Parameters:
  • log_type – log type (access, error, server)

  • index – log file index (0 for current, 1 for previous, etc.)

Raises:

PythonAnywhereApiException – if API call fails

get() dict[str, Any][source]

Retrieve webapp information.

Returns:

dictionary with webapp information

Raises:

PythonAnywhereApiException – if API call fails

get_log_info() dict[str, list[int]][source]

Get log files info.

Returns:

dictionary with log files info, keys are log types (‘access’, ‘error’, ‘server’), values are lists of log file indices

Raises:

PythonAnywhereApiException – if API call fails

get_ssl_info() dict[str, Any][source]

Get SSL certificate info.

Returns:

dictionary with SSL certificate information including parsed expiration date

Raises:

PythonAnywhereApiException – if API call fails

classmethod list_webapps() list[dict[str, Any]][source]

List all webapps for the current user.

Returns:

list of webapps info as dictionaries

Raises:

PythonAnywhereApiException – if API call fails

patch(data: dict) dict[str, Any][source]

Patch webapp with provided data.

Parameters:

data – dictionary with data to update

Returns:

dictionary with updated webapp information

Raises:

PythonAnywhereApiException – if API call fails

reload() None[source]

Reload webapp

Raises:
sanity_checks(nuke: bool) None[source]

Check that we have a token, and that we don’t already have a webapp for this domain.

Parameters:

nuke – if True, skip the check for existing webapp

Raises:

SanityException – if API token is missing or webapp already exists

set_ssl(certificate: str, private_key: str) None[source]

Set SSL certificate and private key for webapp.

Parameters:
  • certificate – SSL certificate

  • private_key – SSL private key

Raises:

PythonAnywhereApiException – if API call fails