Package: pythonanywhereapiclient
pythonanywhereapiclientThin wrapper for thePythonAnywhere API.FeaturesBasic API client responsible for authentication and sending requestsList and configure webappsList and upload filesList and configure schedulesList and work with consolesTechnical requirementsBelow is the list of currently supported Python releases:#Python13.723.833.9Code and contributionThe code is open source and released under theMIT License (MIT). It is available onGitlaband follows the guidelines aboutSemantic Versioningfor 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 timemkvirtualenv--python=python3.8pythonanywhereapiclient-py38
pipinstall-e.[testing]# Running the tests while developmentpytest# Individual Python release tests and code quality checkstox-epy38
tox-ecoverage
tox-eisort
tox-ebrunette
tox-eflake8# Ensure code quality running the entire test suite,# this requires all supported Python releases to be installedtoxGetting StartedThis 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.SetupThere are a few setup steps you need to complete before you can proceed:Sign upfor a PythonAnywhere account, if you don't already have one.Activateyour personal API token.InstallationInstallpythonanywhereapiclientusing pip:pipinstallpythonanywhereapiclientConfigurationThe client simply needs three environment variables to work properly:PYTHONANYWHERE_API_CLIENT_HOSTPYTHONANYWHERE_API_CLIENT_TOKENPYTHONANYWHERE_API_CLIENT_USERFor example to set these environment variables in a bash:exportPYTHONANYWHERE_API_CLIENT_HOST="www.pythonanywhere.com"exportPYTHONANYWHERE_API_CLIENT_TOKEN="yoursecrettoken"exportPYTHONANYWHERE_API_CLIENT_HOST="yourusername"Valid values forPYTHONANYWHERE_API_CLIENT_HOSTarewww.pythonanywhere.comandeu.pythonanywhere.com.UsageThe following examples showcase some typical usage scenarios.frompythonanywhereapiclientimportconsole,file,schedule,webapp# Create a webappwebapp.create('example.com','python36')# List all webappswebapp.list()# Modify an existing webappwebapp.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 mappingwebapp.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 webappwebapp.disable('example.com')# Enable a webappwebapp.enable('example.com')# Delete a webappwebapp.delete('example.com')# List all files at pathfile.list('/home/username/data')# Upload a filefile.upload('/home/username/data/foo.txt','this is a text file')# Create a scheduleschedule.create(command='clear',enabled=True,interval='daily',hour=12,minute=59)# List all schedulesschedule.list()# Delete a scheduleschedule.delete(id=1)# Create a consoleconsole.create(executable='bash',working_directory='/home')# List all consolesconsole.list()# Send input to a consoleconsole.send_input(id=1,input='whoami\n')# Get latest output from a consoleconsole.get_latest_output(id=1)# Kill a consoleconsole.kill(id=1)