qr code logo qr code: web

1 2 3 4

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 on fastapi.