Simple Guide on Deploying Vanilla Python API on Vercel — Free of Cost

Whether you are working on your hobby project or a professional project, deployment is necessary. Vercel provides a very simple way and interface for deploying applications with continuous deployment. One big benefit of deploying on Vercel is that it is Free!
Please note that this article assumes you have Python and any IDE installed. If not, you can follow installation guides for Python and VS Code.
1) Initialize the Project:
If you already have a project move to the next step!
In this step, we will initialize a basic project. Run the following command to create a new project and open it in the IDE.
mkdir python-api-example
cd ./python-api-example
# below command will open vscode in the current directory
# if you have any other IDE, feel free to use that
code .
Open the terminal in IDE and create the virtual environment. Virtual Environment is not necessary but it is a good practice:
python -m venv venv
2) Write the API:
Now create a directory api
(you can choose any directory name) and within this directory create index.py
with the following code:
# /api/index.py
from http.server import BaseHTTPRequestHandler
import json
# Create a custom HTTP request handler
class handler(BaseHTTPRequestHandler):
# Define how to handle GET requests
def do_GET(self):
print("Here => ", self.path)
if self.path == "/api":
self.send_response(200)
self.send_header("Content-type", "text/plain")
self.end_headers()
self.wfile.write(
"Python API Example - Welcome to the homepage!".encode("utf-8")
)
else:
self.send_response(404)
self.send_header("Content-type", "application/json")
self.end_headers()
error_data = {"message": "Not Found", "status": "error"}
json_error_data = json.dumps(error_data)
self.wfile.write(json_error_data.encode("utf-8"))
In this, you don't need to include the server creation code as Vercel will automatically create one for us.
3) Add a .gitignore file:
Initialize the git repository using the command:
git init
Add a .gitignore
file to specify intentionally untracked files that Git should ignore.
# Byte-compiled / optimized files
__pycache__/
*.py[cod]
# Virtual environment
venv/
env/
.venv/
ENV/
# IDE files
.idea/
.vscode/
# Compiled Python files
*.pyc
# Logs
*.log
# OS or editor-generated files
.DS_Store
Thumbs.db
4) Configure the vercel.json file:
Now add a vercel.json
file at the root of the app and write the following code.
{
"rewrites": [{ "source": "/(.*)", "destination": "/api" }]
}
You can replace the "dest": "/api"
with the folder name you choose to place index.py
in!
After all the steps your folder structure will look like the following:

5) Deploying on Vercel:
Now you can deploy on Vercel using two ways:
a) By Using Vercel CLI:
Install Vercel CLI globally using the following command:
npm i -g vercel
To login to CLI you can run the following command:
vercel login
You will be presented with the following options and you can select one. A session in the browser will open and it will authenticate the CLI!

To run in your local environment you can use:
vercel dev
To deploy it to Vercel, use the following command:
vercel deploy
You will be presented with the options as follows, select the appropriate ones!
Vercel CLI 32.6.1
? Set up and deploy “D:\example\python-api-example”? [Y/n] y
? Which scope do you want to deploy to? example
? Link to existing project? [y/N] n
? What’s your project’s name? python-api-example
? In which directory is your code located? ./
Local settings detected in vercel.json:
No framework detected.
? Want to modify these settings? [y/N] n
And your application is deployed!
b) Using Vercel Dashboard:
Upload your repo to GitHub or any other provider and connect the provider to your Vercel account. Now go to your Vercel Dashboard and follow along.
Click on Add New...
and then select Project
. After clicking you will be directed to the screen where you can import your project. Find your desired project and click import. Leave the settings as it is and click Deploy
and it will take a few minutes to deploy. All the steps written are shown below:



And that’s it, Happy Coding! 😊
Access the Code at:
Visit the Live version at: https://vanilla-python-api-vercel-deployment-example.vercel.app/
If you liked my story you can follow me for more interesting tips and tricks at Farasat Ali — Medium.
You can Find Me on LinkedIn and GitHub.
Also, Visit My Portfolio at:
You can also check out the related articles:
Stackademic
Thank you for reading until the end. Before you go:
- Please consider clapping and following the writer! 👏
- Follow us on Twitter(X), LinkedIn, and YouTube.
- Visit Stackademic.com to find out more about how we are democratizing free programming education around the world.