title: Python Serverless Function Vercel - Next.js
body: <p>I found out that I could use Python to create a serverless function inside a <a href="https://nextjs.org/docs/getting-started" rel="noreferrer">Next.js</a> project. Once deployed to <a href="https://vercel.com/" rel="noreferrer">Vercel</a>, it will get converted into a serverless function.</p>
  <p>I went through the docs and found a <a href="https://vercel.com/docs/serverless-functions/supported-languages#python" rel="noreferrer">simple example</a> that outputs the date:</p>
  <pre><code>from http.server import BaseHTTPRequestHandler
  from datetime import datetime
  
  class handler(BaseHTTPRequestHandler):
  
    def do_GET(self):
      self.send_response(200)
      self.send_header('Content-type', 'text/plain')
      self.end_headers()
      self.wfile.write(str(datetime.now().strftime('%Y-%m-%d %H:%M:%S')).encode())
      return
  </code></pre>
  <p>They offer a live working example <a href="https://python-api.now-examples.now.sh/api/date" rel="noreferrer">here</a>.</p>
  <p>Apparently all that is needed is to place the file <code>date.py</code> inside the <code>api</code> folder of a bootstrapped Next.js project and you're off to the races. When deployed, Vercel will detect the Python file and serve it as a serverless function.</p>
  <p>The deploy succeeded and I placed the file inside the <code>pages/api</code> folder as required. However, the function is never picked up (image below):
  <a href="https://i.stack.imgur.com/amdED.png" rel="noreferrer"><img src="https://i.stack.imgur.com/amdED.png" alt="vercel function output" /></a></p>
  <p>Older versions apparently required the <a href="https://vercel.com/docs/configuration#project/functions" rel="noreferrer">configuration of serverless functions by adding a <code>vercel.json</code> file</a>. But this doesn't seem necessary now.</p>
  <p>What am I missing?</p>