A minimal, production-friendly Python project to generate QR codes from text or URLs.
qr/
├─ pyproject.toml # Project metadata and dependencies
├─ src/
│ └─ qrgen/
│ ├─ __init__.py
│ ├─ generate.py # Library functions
│ └─ cli.py # CLI entrypoint `qrgen`
├─ tests/
│ └─ test_generate.py
├─ .gitignore
└─ README.md
python3 -m venv .venv
source .venv/bin/activate
# install in editable/development mode (and dependencies)
pip install -e .
# or install dependencies directly
# pip install qrcode[pil]- Library:
from qrgen import save_qr
save_qr("https://example.com", "out.png")- CLI:
qrgen "https://example.com" -o out.png --error-correction H --box-size 8The output is a PNG image file containing the QR code.
- Default location: If you don't specify
-o, the file is saved asqr.pngin your current working directory - Custom location: Use
-o path/to/file.pngto save anywhere you want - After running: The CLI prints the full path where the file was saved, e.g.:
Saved QR to /Users/owner/Desktop/Django/qr/qr.png
To view the QR code:
- Open the PNG file with any image viewer (Photos app, Preview on Mac, etc.)
- Scan it with any QR code scanner app on your phone
- Open it in a web browser to see the image
Example:
# Generate QR code (saves to qr.png in current directory)
qrgen "Hello World"
# Generate and save to a specific location
qrgen "https://example.com" -o ~/Desktop/my_qr.pngpip install pytest
pytestIf you prefer this as a Django app inside your existing project:
- Create a Django app (e.g.,
python manage.py startapp qrcodes) - Add a view that calls
save_qrand returns the image viaFileResponse - Wire up a URL like
/qr/?data=...and generate on-the-fly
This repository remains framework-agnostic so you can use it from Django, Flask, or CLI.