Python builder for WSGI applications on Vercel Fix
npm install @abudu/vercel-python-wsgi-fixvercel.json file to the root of your application:
json
{
"builds": [{
"src": "index.py",
"use": "@ardnt/vercel-python-wsgi",
"config": { "maxLambdaSize": "15mb" }
}]
}
`
This configuration is doing a few things in the "builds" part:
1. "src": "index.py"
This tells Now that there is one entrypoint to build for. index.py is a
file we'll create shortly.
2. "use": "@ardnt/vercel-python-wsgi"
Tell Now to use this builder when deploying your application
3. "config": { "maxLambdaSize": "15mb" }
Bump up the maximum size of the built application to accommodate some larger
python WSGI libraries (like Django or Flask). This may not be necessary for
you.
$3
Add index.py to the root of your application. This entrypoint should make
available an object named application that is an instance of your WSGI
application. E.g.:
`python
For a Dango app
from django_app.wsgi import application
Replace
django_app with the appropriate name to point towards your project's
wsgi.py file
`
Look at your framework documentation for help getting access to the WSGI
application.
If the WSGI instance isn't named application you can set the
wsgiApplicationName configuration option to match your application's name (see
the configuration section below).
$3
That's it, you're ready to go:
`
$ vercel
> Deploying python-wsgi-app
...
> Success! Deployment ready [57s]
`
Requirements
Your project may optionally include a requirements.txt file to declare any
dependencies, e.g.:
`
requirements.txt
Django >=2.2,<2.3
`
Be aware that the builder will install Werkzeug as a requirement of the
handler. This can cause issues if your project requires a different version of
Werkzeug than the handler.
Configuration options
$3
Select the lambda runtime. Defaults to python3.6.
`json
{
"builds": [{
"config": { "runtime": "python3.6" }
}]
}
`
$3
Select the WSGI application to run from your entrypoint. Defaults to
application.
`json
{
"builds": [{
"config": { "wsgiApplicationName": "application" }
}]
}
`
Additional considerations
$3
You'll likely want all requests arriving at your deployment url to be routed to
your application. You can do this by adding a route rewrite to the Now
configuration:
`json
{
"builds": [{
"src": "index.py",
"use": "@ardnt/vercel-python-wsgi"
}],
"routes" : [{
"src" : "/(.*)", "dest":"/"
}]
}
`
$3
If having an extra file in your project is troublesome or seems unecessary, it's
also possible to configure Now to use your application directly, without passing
it through index.py.
If your WSGI application lives in vercel_app/wsgi.py and is named application,
then you can configure it as the entrypoint and adjust routes accordingly:
`json
{
"builds": [{
"src": "vercel_app/wsgi.py",
"use": "@ardnt/vercel-python-wsgi"
}],
"routes" : [{
"src" : "/(.*)", "dest":"/vercel_app/wsgi.py"
}]
}
``