PythonAnywhere WSGI Config
Relevant source files
The following files were used as context for generating this wiki page:
The PythonAnywhere WSGI configuration serves as the critical interface between the web server and the Promethean Unified Platform's Flask backend. It ensures the application is correctly loaded within the PythonAnywhere hosting environment by managing system paths, environment variables, and the initialization of the Flask application instance.
This configuration is essential for transitioning the platform from a local development environment to a production state on PythonAnywhere, facilitating secure HTTPS communication and integration with external services like Supabase and DeepSeek LLM.
Sources: pythonanywhere_wsgi.py:1-24, DEPLOYMENT.md:3-13
Architecture and Path Management
The WSGI configuration establishes the runtime environment by explicitly modifying the Python system path. This allows the web server to locate the project's root directory and the specific backend module containing the application logic.
Environment Setup Flow
The following diagram illustrates how the WSGI script prepares the environment before the Flask application is invoked.
The configuration ensures that FLASK_ENV is strictly set to production to prevent debug features from exposing sensitive information in the hosted environment.
Sources: pythonanywhere_wsgi.py:6-14, wsgi.py:4-10
Configuration Components
The WSGI setup relies on several key configuration elements to ensure the Promethean Unified Platform functions correctly.
Environment Variable Integration
The system uses the python-dotenv library to load secrets and configuration parameters from a .env file located in the project root. This is critical for connecting to the Supabase database and the DeepSeek API.
| Variable | Source | Description |
|---|---|---|
SUPABASE_URL | .env | Endpoint for the PostgreSQL/Real-time database. |
SUPABASE_ANON_KEY | .env | Anonymous key for database interactions. |
DEEPSEEK_API_KEY | .env | Authentication for the LLM provider. |
FLASK_ENV | WSGI Script | Hardcoded to 'production' for security. |
Sources: pythonanywhere_wsgi.py:16-19, DEPLOYMENT.md:144-152, backend/app.py:11-13
Dependency Management
The environment is powered by a specific set of libraries defined in the project's requirements. These must be installed in the PythonAnywhere virtual environment.
# Key requirements for WSGI/Production
Flask==3.0.0
Flask-CORS==4.0.0
python-dotenv==1.0.0
gunicorn==21.2.0
requests==2.31.0
Sources: requirements.txt:1-9, DEPLOYMENT.md:46-50
WSGI Implementation Details
There are two primary WSGI entry points provided in the repository: pythonanywhere_wsgi.py (optimized for the specific hosting platform) and wsgi.py (a generic implementation).
pythonanywhere_wsgi.py Implementation
This script uses the create_app() factory pattern to instantiate the application, which is a standard practice for scalable Flask applications.
import os
import sys
from pathlib import Path
project_home = '/home/littlebunneh/Promethean-Unified-Platform'
sys.path.insert(0, project_home)
sys.path.insert(0, os.path.join(project_home, 'backend'))
os.environ['FLASK_ENV'] = 'production'
from backend.app import create_app
app = create_app()
Sources: pythonanywhere_wsgi.py:1-21
Security and Headers
When the WSGI application handles a request, the backend app.py injects security headers into every response to protect the platform in a production environment.
Key security headers configured include Strict-Transport-Security (max-age=31536000) and Content-Security-Policy.
Sources: backend/app.py:18-30, DEPLOYMENT.md:112-118
Deployment and Loading Logic
The deployment process links the PythonAnywhere "Web tab" configuration to these WSGI files.
- Manual Configuration: PythonAnywhere is set to manual configuration to use the custom WSGI script.
- Virtualenv Alignment: The WSGI script runs within the context of the
prometheanvirtual environment. - Static Path Mapping: While the WSGI script handles Python logic, static files (HTML, CSS, JS) are mapped to
/static/in the PythonAnywhere dashboard to bypass the WSGI layer for better performance.
Sources: DEPLOYMENT.md:33-44, DEPLOYMENT.md:88-92, static/index.html:1-344
Summary
The PythonAnywhere WSGI configuration is the foundational bridge that enables the Promethean Unified Platform to run in a production cloud environment. By strictly managing path injection, environment loading through dotenv, and enforcing production-level environment settings, it ensures the Flask backend can securely interact with Supabase and DeepSeek while maintaining high security standards via enforced HTTPS and security headers.