Automates git operations on PythonAnywhere through their console API. Two usage methods available.
Use this for automatic deployment when you push to your repository. Copy the workflow file to your repo and set up GitHub secrets.
Use this approach to add deployment capabilities directly to your own repository. You download the standalone script and create your own workflow file that calls it on each commit.
Copy .github/workflows/external-usage-example.yml to your repository and set these GitHub Secrets:
PAW_USERNAME- Your PythonAnywhere usernamePAW_TOKEN- Your API tokenPAW_HOST- Your domain (username.pythonanywhere.com)PAW_PROJECT_PATH- Project path (/home/username/project)PAW_CLI- Console ID of a pre-initialized console
This method adds deployment capabilities directly to your repository:
-
Download the standalone script to your repository:
curl -O https://raw.githubusercontent.com/cirqt/pythonanywhere-git-pipeline/main/individualPullToPAW.py
-
Create your own GitHub Actions workflow (
.github/workflows/deploy.yml):name: Deploy to PythonAnywhere on: push: branches: [ main ] workflow_dispatch: jobs: deploy: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: actions/setup-python@v5 with: python-version: '3.11' - name: Install dependencies run: pip install requests pyyaml - name: Deploy to PythonAnywhere env: PAW_USERNAME: ${{ secrets.PAW_USERNAME }} PAW_TOKEN: ${{ secrets.PAW_TOKEN }} PAW_HOST: ${{ secrets.PAW_HOST }} PAW_PROJECT_PATH: ${{ secrets.PAW_PROJECT_PATH }} PAW_CLI: ${{ secrets.PAW_CLI }} GIT_USERNAME: ${{ secrets.GIT_USERNAME }} GIT_TOKEN: ${{ secrets.GIT_TOKEN }} run: python individualPullToPAW.py
-
Set up the same GitHub Secrets as Method 1 (see setup instructions below)
- Copy
.github/workflows/external-usage-example.ymlto your repository - Set up GitHub Secrets in your repo (Settings → Secrets and Variables → Actions):
Required Secrets:
PAW_USERNAME- Your PythonAnywhere usernamePAW_TOKEN- Your API token from PythonAnywhere Account → API TokenPAW_HOST- Your domain (username.pythonanywhere.com)PAW_PROJECT_PATH- Project path (/home/username/project)PAW_CLI- Console ID of a pre-initialized console
For Private Repositories (Optional):
GIT_USERNAME- Your GitHub usernameGIT_TOKEN- Your GitHub Personal Access Token
- Download the script to your repository:
curl -O https://raw.githubusercontent.com/cirqt/pythonanywhere-git-pipeline/main/individualPullToPAW.py
- Create
.github/workflows/deploy.yml(see Method 2 example above) - Set up the same GitHub Secrets as Method 1
- Commit both files to your repository
- Each push to main branch will trigger deployment
For Manual Testing: You can also run the script manually by setting environment variables:
export PAW_USERNAME="your_username"
export PAW_TOKEN="your_token"
export PAW_HOST="username.pythonanywhere.com"
export PAW_PROJECT_PATH="/home/username/project"
export PAW_CLI="console_id"
# For private repositories (optional):
export GIT_USERNAME="your_github_username"
export GIT_TOKEN="your_github_token"
python individualPullToPAW.py- Open a console in PythonAnywhere dashboard and keep it open
- Find your console ID in the browser URL:
https://www.pythonanywhere.com/user/username/consoles/12345678/ - Use
12345678as yourPAW_CLIvalue
The PAW_CLI approach bypasses PythonAnywhere's browser activation requirement and is much more reliable.
main.py- Core pipeline code (used by GitHub Actions)github_deploy.py- Deployment logic (used by GitHub Actions)individualPullToPAW.py- Standalone script for manual userequirements.txt- Python dependencies.github/workflows/external-usage-example.yml- Example workflow file
-
Authentication Failed
- Verify your API token is correct and active
- Get a new token from PythonAnywhere Account → API Token
-
Console ID Issues
- Ensure you have an open console in PythonAnywhere dashboard
- Copy the console ID from the browser URL
-
Git Command Failed
- Ensure the repository exists and you have access
- Check if the project path is correct
- Verify Git is configured properly on PythonAnywhere
- Never commit credentials to version control
- Use GitHub Secrets for environment variables
- Regularly rotate your API tokens
For issues, check the console output for detailed error messages and ensure your PythonAnywhere account has console access.