PythonAnywhere¶
A Briefcase publication channel plugin that deploys static web apps to PythonAnywhere.
There is a tutorial that builds on top of the BeeWare Tutorial and walks you through deploying your first app to PythonAnywhere.
Prerequisites¶
- A PythonAnywhere account
- An API token (from your Account page on PythonAnywhere)
Installation¶
Install the plugin into your Briefcase project's virtual environment:
(venv) $ pip install pythonanywhere-briefcase-plugin
Quick start¶
First, build and package your web app:
(venv) $ briefcase create web static
(venv) $ briefcase build web static
(venv) $ briefcase package web static
Set your PythonAnywhere API token:
(venv) $ export API_TOKEN=your-api-token-here
Then publish:
(venv) $ briefcase publish web static
If pythonanywhere-briefcase-plugin is the only publication channel installed, it will be selected automatically. If you have multiple channels installed, specify the channel explicitly:
(venv) $ briefcase publish web static --channel pythonanywhere
Your app will be deployed to https://<username>.pythonanywhere.com/.
Configuration¶
Configuration options can be added to the tool.briefcase.app.<appname>.pythonanywhere section of your pyproject.toml file.
username¶
Your PythonAnywhere username. If not specified, the plugin will check the PYTHONANYWHERE_USERNAME environment variable, then fall back to the system username.
[tool.briefcase.app.myapp.pythonanywhere]
username = "mypauser"
domain¶
The domain name for your PythonAnywhere webapp. If not specified, defaults to <username>.pythonanywhere.com.
[tool.briefcase.app.myapp.pythonanywhere]
domain = "www.mycustomdomain.com"
directory¶
The remote directory on PythonAnywhere where the app files will be uploaded. If not specified, defaults to /home/<username>/<app_name>.
[tool.briefcase.app.myapp.pythonanywhere]
directory = "/home/mypauser/www"
Environment variables¶
The following environment variables are used by the plugin:
API_TOKEN¶
Required. Your PythonAnywhere API token. Obtain this from the API Token tab on your PythonAnywhere Account page.
PYTHONANYWHERE_USERNAME¶
Your PythonAnywhere username. Used as a fallback if username is not set in pyproject.toml.
PYTHONANYWHERE_DOMAIN¶
The PythonAnywhere domain suffix. Defaults to pythonanywhere.com. This is useful if you are using a regional PythonAnywhere instance (e.g., eu.pythonanywhere.com).
Contributing¶
Development requires uv.
Clone the repository and install the development dependencies:
$ git clone https://github.com/pythonanywhere/pythonanywhere-briefcase-plugin.git
$ cd pythonanywhere-briefcase-plugin
$ uv sync
Set up pre-commit hooks:
$ uvx pre-commit install
This will run linting (ruff), formatting, type checking (ty), and other checks automatically on every commit.
To run the test suite:
$ uv run pytest
To run pre-commit checks manually against all files:
$ uvx pre-commit run --all-files
How it works¶
When you run briefcase publish web static, the plugin:
- Reads the packaged
.zipdistribution artifact produced bybriefcase package web static. - Extracts the archive and uploads its contents to
/home/<username>/<app_name>/on PythonAnywhere. - Creates a new webapp (or updates the existing one) with a static file mapping from
/to the uploaded directory. - Reloads the webapp so the changes take effect.