I'll create a Python app that reads student marks from a CSV file and exposes an API to query individual student marks. Then, I'll guide you through deploying it to Vercel. Let's break this down into steps:
Let's start with creating the Python app:
Now that we have our Python app ready, let's go through the steps to deploy it to Vercel:
First, make sure you have the Vercel CLI installed. If not, you can install it using npm:
npm install -g vercel
Login to Vercel if you haven't already:
vercel login
Deploy your app to Vercel:
vercel
After deployment, you can access your API using the provided URL. For example:
https://your-app.vercel.app/api?name=Alice
This should return a JSON response with Alice's marks:
{
"name": "Alice",
"marks": 85
}
If you query for a student not in the CSV, you'll get a 404 error:
https://your-app.vercel.app/api?name=Frank
This will return:
{
"error": "Student not found"
}
Remember to replace your-app.vercel.app
with the actual URL provided by Vercel after deployment.
This setup creates a simple API that reads from a CSV file and returns student marks based on the provided name. You can expand on this by adding more features, error handling, or connecting to a database for larger datasets.
Is there anything specific you'd like me to explain further or any modifications you'd like to make to this app?
The error you're encountering is because we're using a Python application, but the system is trying to use Bun, which is a JavaScript runtime. Let's modify our project structure to work with Vercel's Python runtime instead. Here's how we can fix this:
vercel.json
file to correctly configure the Python runtime:Now, let's go through the deployment steps again:
Make sure you have the Vercel CLI installed. If not, you can install it using npm:
npm install -g vercel
Login to Vercel if you haven't already:
vercel login
Deploy your app to Vercel:
vercel
These changes should resolve the Bun-related error you were encountering. The application is now set up to use Python and Flask, reading from the JSON file you provided.
After deployment, you can access your API using the provided URL. For example:
https://your-app.vercel.app/api?name=L8cQVB
This should return a JSON response with the student's marks:
{
"name": "L8cQVB",
"marks": 8
}
Remember to replace your-app.vercel.app
with the actual URL provided by Vercel after deployment.
Is there anything else you'd like me to explain or modify in this setup?