Skip to main content

pythonanywhereapiclient

Pipeline Coverage PyPI

Thin wrapper for the PythonAnywhere API.

Features

  • Basic API client responsible for authentication and sending requests
  • List and configure webapps
  • List and upload files
  • List and configure schedules
  • List and work with consoles

Technical requirements

Below is the list of currently supported Python releases:

# Python
1 3.7
2 3.8
3 3.9

Code and contribution

The code is open source and released under the MIT License (MIT). It is available on Gitlab and follows the guidelines about Semantic Versioning for transparency within the release cycle and backward compatibility whenever possible.

All contributions are welcome, whether bug reports, reviews, documentation or feature requests.

If you're a developer and have time and ideas for code contributions, fork the repo and prepare a merge request:

# Prepare your environment the first time
mkvirtualenv --python=python3.8 pythonanywhereapiclient-py38
pip install -e .[testing]

# Running the tests while development
pytest

# Individual Python release tests and code quality checks
tox -e py38
tox -e coverage
tox -e isort
tox -e brunette
tox -e flake8

# Ensure code quality running the entire test suite,
# this requires all supported Python releases to be installed
tox

Getting Started

This document provides all the basic information you need to start using the client. It covers base concepts, shows examples, and documents links for further reading.

Setup

There are a few setup steps you need to complete before you can proceed:

  1. Sign up for a PythonAnywhere account, if you don't already have one.
  2. Activate your personal API token.

Installation

Install pythonanywhereapiclient using pip:

pip install pythonanywhereapiclient

Configuration

The client simply needs three environment variables to work properly:

  • PYTHONANYWHERE_API_CLIENT_HOST
  • PYTHONANYWHERE_API_CLIENT_TOKEN
  • PYTHONANYWHERE_API_CLIENT_USER

For example to set these environment variables in a bash:

export PYTHONANYWHERE_API_CLIENT_HOST="www.pythonanywhere.com"
export PYTHONANYWHERE_API_CLIENT_TOKEN="yoursecrettoken"
export PYTHONANYWHERE_API_CLIENT_HOST="yourusername"

Valid values for PYTHONANYWHERE_API_CLIENT_HOST are www.pythonanywhere.com and eu.pythonanywhere.com.

Usage

The following examples showcase some typical usage scenarios.

from pythonanywhereapiclient import console, file, schedule, webapp

# Create a webapp
webapp.create('example.com', 'python36')

# List all webapps
webapp.list()

# Modify an existing webapp
webapp.modify(
    'example.com',
    python_version='3.6',
    working_directory='/home/user/work',
    source_directory='/home/user/source',
    virtualenv_path='/home/user/virtualenv',
    force_https=True
)

# Create a static mapping
webapp.create_static('example.com', '/static/', '/home/user/data/static')

# Reload a webapp (e.g. after source or configuration changes)
webapp.reload('example.com')

# Disable a webapp
webapp.disable('example.com')

# Enable a webapp
webapp.enable('example.com')

# Delete a webapp
webapp.delete('example.com')

# List all files at path
file.list('/home/username/data')

# Upload a file
file.upload('/home/username/data/foo.txt', 'this is a text file')

# Create a schedule
schedule.create(command='clear', enabled=True, interval='daily', hour=12, minute=59)

# List all schedules
schedule.list()

# Delete a schedule
schedule.delete(id=1)

# Create a console
console.create(executable='bash', working_directory='/home')

# List all consoles
console.list()

# Send input to a console
console.send_input(id=1, input='whoami\n')

# Get latest output from a console
console.get_latest_output(id=1)

# Kill a console
console.kill(id=1)

Metadata

Release files for pythonanywhereapiclient 2.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for pythonanywhereapiclient 2.0.1
File Interpreter ABI Platform
pythonanywhereapiclient-2.0.1-py3-none-any.whl Python 3 none any Details

Release files / pythonanywhereapiclient-2.0.1-py3-none-any.whl

Download URL pythonanywhereapiclient-2.0.1-py3-none-any.whl
Size 15.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fb933b6971a88ca98ee2e294c9a9f799657458ec531b768ade53e927423e2da8
BLAKE2b-256 checksum
How to use checksums
fae226c41046a012377fe914040ff53321c9a06c01fbb01ed9499bdcc62d819f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.4

Release history Release notifications | RSS feed

This release

2.0.1 This release

1 release file

2.0.0

1 release file

1.1.0

1 release file

1.0.1

1 release file

1.0.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page