Calmcode - qr code: python qr service

Python QR Service

1 2 3 4

There are many ways to handle QR codes but it's likely you'll like to build a web interface for it. We've implemented one with FastAPI as an example below.

QRCode and FastAPI 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() # 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.