... qr code: web


There are many ways to serve QR codes but we've implemented one with FastAPI as an example.

import io
import qrcode

from fastapi import FastAPI
from starlette.responses import StreamingResponse

app = FastAPI()

def generate(message: str):
    img = qrcode.make(message)
    buf = io.BytesIO()
    buf.seek(0) # important here!
    return StreamingResponse(buf, media_type="image/jpeg")

You can run this locally by running this command from the terminal:

uvicorn fastqrapi:app --reload

These commands do assume that both fastapi and uvicorn are installed. If you've never worked with FastAPI before you might appreciate our series of videos here.

Feedback? See an issue? Something unclear? Feel free to mention it here.

If you want to be kept up to date, consider signing up for the newsletter.