This CLI script turns a single URL into four PNG files that cover the L, M, Q, and H QR error correction levels using the Pillow-backed qrcode library. The tool validates that the URL already includes a scheme such as https:// and names each file based on the sanitized URL.
- Python 3.10 or newer
- Create a virtual environment:
python3 -m venv .venv - Activate it:
source .venv/bin/activate - Install the dependency:
pip install 'qrcode[pil]'
Run the generator after activating the virtual environment.
Default output directory (current working directory):
python generate_qr_codes.py "https://example.com/path"
Custom directory using -o/--output-dir (created automatically):
python generate_qr_codes.py "https://example.com/path" -o output/qr
- Filenames remove the scheme, drop slashes, and keep only letters, digits, dot, underscore, and dash. When nothing remains, the script falls back to
qr-code. - Reactivate the
.venvfor future sessions withsource .venv/bin/activateto reuse the installed dependency.