Skip to content

Example code for article - Simple Guide on Deploying Python Flask API on Vercel — Free of Cost

Notifications You must be signed in to change notification settings

faraasat/flask-vercel-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Flask Vercel Example

This Example Code is a Part of an Article: Simple Guide on Deploying Python Flask API on Vercel — Free of Cost


Live Url: Deployment
Article Link: Medium

Introduction:

Whether you’re working on a hobby project or a professional endeavor, deployment is essential. Flask, a lightweight and versatile Python web framework, is commonly used for building web applications due to its simplicity and flexibility. In this guide, we’ll explore deploying a Python Flask API on Vercel, a platform that offers straightforward deployment with continuous integration, and the best part — it’s free!

Steps for Deployment:

1. Initialize the Project:

  • Create a new project directory (e.g., flask-api-example).
  • Set up a virtual environment (optional but recommended).
  • Install Python and any IDE (if not already installed).

2. Add Dependencies:

  • Specify your app’s dependencies in a requirements.txt file.
  • Install the dependencies using pip install -r requirements.txt.

3. Write the API:

  • Create an /api directory (or any name you prefer).
  • Inside this directory, create an index.py file with your Flask API code.
  • Define routes and handlers (e.g., a simple home route and a 404 error handler).

4. Configure .gitignore:

  • Initialize a Git repository (git init).
  • Create a .gitignore file to exclude specific files and directories (e.g., .vscode, .venv, etc.).

5. Configure vercel.json:

  • Add a vercel.json file at the root of your app.
  • Specify rewrite rules to route requests to your Flask API (e.g., from /api to /api/index).

6. Deploy on Vercel:

  • Using Vercel CLI:
    • Install Vercel CLI globally (npm i -g vercel).
    • Log in to the CLI using vercel login.
  • Deploy using vercel commands.
    • Using GitHub/GitLab Integration:
    • Connect your Vercel account to your Git repository.
    • Automatically deploy on every push to the repository.

Result:

screencapture-flask-vercel-example-tfih-vercel-app-2024-03-06-20_19_16

Releases

No releases published

Packages

No packages published

Languages