Scheduled Tasks

class schedule.Schedule[source]

Interface for the PythonAnywhere Scheduled Tasks API.

This class uses the get_api_endpoint function from pythonanywhere_core.api to construct the API URL, which is stored in the class variable base_url. It then calls the call_api method with appropriate arguments to perform actions related to scheduled tasks.

Supported HTTP Methods:
  • GET and POST for the tasks list.

  • GET, PATCH, and DELETE for tasks with an ID.

Methods:
create(params: dict) dict | None[source]

Creates new scheduled task using params.

Params should be: command, enabled (True or False), interval (daily or hourly), hour (24h format) and minute.

Parameters:

params – dictionary with required scheduled task specs

Returns:

dictionary with created task specs

delete(task_id: int) Literal[True][source]

Deletes scheduled task by id.

Parameters:

task_id – scheduled task to be deleted id number

Returns:

True when API response is 204

get_list() List[dict][source]

Gets list of existing scheduled tasks.

Returns:

list of existing scheduled tasks specs

get_specs(task_id: int) dict[source]

Get task specs by id.

Parameters:

task_id – existing task id

Returns:

dictionary of existing task specs

update(task_id: int, params: dict) dict[source]

Updates existing task using id and params.

Params should at least one of: command, enabled, interval, hour, minute. To update hourly task don’t use ‘hour’ param. On the other hand when changing task’s interval from ‘hourly’ to ‘daily’ hour is required.

Parameters:
  • task_id – existing task id

  • params – dictionary of specs to update