Status: Beta

This builder takes in a Python program that defines a singular HTTP handler and outputs it as a Lambda.

When to Use It

Whenever you want to expose an API or a function written in Python.

How to Use It

Define a file inside a folder as follows:

from http.server import BaseHTTPRequestHandler
from cowpy import cow

class handler(BaseHTTPRequestHandler):

    def do_GET(self):
        message = cow.Cowacter().milk('Hello from Python on Now Lambda!1111111')

Inside requirements.txt define:


And define a now.json like:

  "version": 2,
  "builds": [{ "src": "*.py", "use": "@now/python" }]

The example above can be seen live as

Also, the source code of the deployment can be checked by appending /_src e.g.

Web Server Gateway Interface

The Web Server Gateway Interface (WSGI) is a calling convention for web servers to forward requests to web applications written in Python. You can use WSGI with frameworks such as Flask or Django.

Instead of defining a handler, define an app variable in your Python file.

For example, define a file inside a folder as follows:

from flask import Flask, Response
app = Flask(__name__)

@app.route('/', defaults={'path': ''})
def catch_all(path):
    return Response("<h1>Flask on Now</h1><p>You visited: /%s</p>" % (path), mimetype="text/html")

Inside requirements.txt define:


And define a now.json like:

  "version": 2,
  "builds": [{ "src": "", "use": "@now/python" }],
  "routes": [{ "src": "(.*)", "dest": "" }]

Most frameworks use their own implementation of routing. However, you can use a catch-all route to circumvent the framework and instead use Now Routing Layer to match a route to a Lambda.

The example above can be seen live as

Technical Details


The entrypoint file must be a .py source file with one of the following variables defined:

  • handler that inherits from the BaseHTTPRequestHandler class
  • app that exposes a WSGI Application


Python 3.6 is used.


This builder supports installing dependencies defined in the requirements.txt file or a Pipfile.lock file.

Maximum Lambda Bundle Size

To help keep cold boot times low, the maximum output bundle size for a Python lambda is, by default, 5mb. This limit is extendable up to 50mb.

Example maxLambdaSize configuration:
  "builds": [
    { "src": "*.py", "use": "@now/python", "config": { "maxLambdaSize": "10mb" } }