🐍

received raw code string: a%3Dlambda+x%3A+x%2A2%3B+b=1/a(2)%0Ab-3;c=4;d=5;e=8;a(2)-b-c-d

Here you can see a prettified version of the code string and the result of executing it via IPython

This image has been generated on the fly using a serverless vercel python function

You can see the code that generated this image here

A simple explanation of how it works

  1. GET Request to /py
  2. Vercel serves html file to the client
  3. Browser: GET /api/py.png
  4. Vercel executes lambda function /api/py.png.ts
    1. GET /api/py_pretty: prettyfies the code using ptyhon-black
    2. GET /api/py_exec: executes the code using IPython and returns stdout
    3. html from template.html with mustache
    4. uses playwright to get a screenshot of the html
    5. return the image to the client

An og:image tag is set so that this also works on the fly for twitter and social media