wndkx

Deploying Python apps for free on Pylex or PythonAnywhere

Deploying your Python applications online doesn’t have to cost money. There are free platforms available that make it easy to publish web apps built with frameworks like Flask or FastAPI. In this guide, we’ll walk you through deploying Python apps using PyLex and PythonAnywhere.

Before You Begin

Make sure you have the following:


Option 1: Deploy Using PyLex

PyLex is a modern platform that allows you to deploy Python apps straight from GitHub. It supports auto-deployment, handles dependencies, and provides a free public URL.

Step-by-Step Guide:

  1. Create an Account:

    Go to https://pylex.dev and sign up using your GitHub account.

  2. Prepare Your App:

    Ensure your repository contains the following:

  3. Create a New Project:

    Click on “New Project” in the PyLex dashboard. Choose your GitHub repo and specify the runtime (e.g., Python 3.10).

  4. Deploy:

    PyLex will automatically install the dependencies and run your app. You will receive a public URL once the build is complete.

  5. Update Automatically:

    Any changes you push to GitHub will be automatically deployed.

Example Flask App:

from flask import Flask

app = Flask(__name__)

@app.route("/")
def home():
    return "Hello from PyLex!"
    

Option 2: Deploy Using PythonAnywhere

PythonAnywhere is an online IDE and hosting service that supports Python web apps. It’s ideal for small apps and educational projects.

Step-by-Step Guide:

  1. Sign Up:

    Register for a free account at pythonanywhere.com.

  2. Upload Your App:

    You can upload your files via the web interface or clone your GitHub repo using the Bash console:

    git clone https://github.com/your-username/your-repo.git
  3. Install Dependencies:

    Open the Bash console and install packages with pip:

    pip install --user -r requirements.txt
  4. Set Up the Web App:

    Go to the “Web” tab and click “Add a new web app.” Choose:

  5. Configure WSGI:

    Open the WSGI config file (linked in the web app settings) and point it to your app. Example for Flask:

    import sys
    path = '/home/yourusername/yourproject'
    if path not in sys.path:
        sys.path.insert(0, path)
    
    from app import app as application
                
  6. Reload the App:

    Click “Reload” in the Web tab to start the app. Your public link will look like yourusername.pythonanywhere.com.

Example Flask App:

from flask import Flask

app = Flask(__name__)

@app.route("/")
def home():
    return "Hello from PythonAnywhere!"