aedev.pythonanywhere
web api for www.pyanywhere.com and eu.pyanywhere.com
a similar package can be found at `https://gitlab.com/texperience/pythonanywhereapiclient`__
Classes
|
remote host api to a project package on the web hosts eu.pythonanywhere.com and pythonanywhere.com. |
- class PythonanywhereApi(web_domain, web_user, web_token, project_name)[source]
Bases:
object
remote host api to a project package on the web hosts eu.pythonanywhere.com and pythonanywhere.com.
- __init__(web_domain, web_user, web_token, project_name)[source]
initialize web host api and the deployed project package name.
- property error_message: str
error message string if an error occurred or an empty string if not.
- Getter:
return the accumulated error message of the recently occurred error(s).
- Setter:
any assigned error message will be accumulated to recent error messages. pass an empty string to reset the error message.
- property project_name: str
project main package name string property.
- Getter:
return the currently connected/configured project package name of the web host server.
- Setter:
set/change the currently connected/configured project name of the web host server.
- _request(url_path, task, method=<function get>, success_codes=(200, 201), **request_kwargs)[source]
send a https request specified via
method
and return the response.- Parameters:
- Return type:
Response
- Returns:
request response. if on error occurred then the instance string attribute
error_message
contains an error message. if the caller is not checking for errors and not resetting the error message string, then this function will accumulate further errors toerror_message
, separated by two new line characters.
- deployed_code_files(path_masks, skip_file_path=<function PythonanywhereApi.<lambda>>)[source]
determine all deployed code files of given package name deployed to the pythonanywhere server.
- Parameters:
path_masks¶ (
Sequence
[str
]) – root package paths with glob wildcards to collect deployed code files from.skip_file_path¶ (
Callable
[[str
],bool
]) – called for each found file/folder with the path_mask relative to the package root folder as argument, returning True to exclude the specified item from the returned result set. calls of a folder have a prefix of a slash character followed by a dot (“/.”) and help to minimize the number of calls against the web server api.
- Return type:
- Returns:
set of file paths of the package deployed on the web, relative to the project root or None if an error occurred.
- deployed_file_content(file_path)[source]
determine the file content of a file deployed to a web server.
- deployed_version()[source]
determine the version of a deployed django project package.
- Return type:
- Returns:
version string of the package deployed to the web host/server or empty string if package version file or version-in-file not found.
- files_iterator(path_mask, level_index=0)[source]
find files matching the path mask string passed as the paramref:.path_mask argument.
- Parameters:
path_mask¶ (
str
) – file path pattern/mask with optional wildcards. passing an empty string will return the files of the project/package root directory, as well as passing ‘.’ or ‘*’. also absolute path masks will be relative to the project root directory. file path mask matches are case-sensitive (done with the functionfnmatch.fnmatchcase()
).level_index¶ (
int
) – folder level depth inpassed file path mask
to start searching (only specified in recursive call).
- Return type:
- Returns:
iterator/generator yielding dicts. each dict has a file_path key containing the path string of the found file relative to the project root folder and a type key containing the string ‘directory’ or `’file’
- find_project_files(path_mask='', skip_file_path=<function PythonanywhereApi.<lambda>>, collector=None)[source]
determine the files matching the glob pattern provided in
path_mask
at the app/web server.not using the files tree api endpoints/function (f”files/tree/?path=/home/{self.web_user}/{project_name}”) because their response is limited to 1000 files (see https://help.pythonanywhere.com/pages/API#apiv0userusernamefilestreepathpath) and e.g. kairos has more than 5300 files in its package folder (mainly for django filer and the static files).
- Parameters:
path_mask¶ (
str
) – file mask including relative path to the package project root to be searched. passing an empty string (the default) returns all files in the package root directory.skip_file_path¶ (
Callable
[[str
],bool
]) – called for each found file/folder with the path_mask relative to the package root folder as argument, returning True to exclude the specified item from the returned result set. calls of a folder have a prefix of a slash character followed by a dot (“/.”) and help to minimize the number of calls against the web server api.
- Return type:
- Returns:
set of file paths of the package deployed on the web, relative to the project root or None if an error occurred. all files underneath a