Skip to main content

Generate QR codes with customizable colors in PNG and SVG formats

Project description

QR Code Generator

PyPI version Python versions License

A simple, fast QR code generator with customizable colors. Outputs PNG or SVG with transparent backgrounds.

Features

  • Generate QR codes in PNG or SVG format
  • Customizable foreground color (hex format)
  • Transparent background support
  • Configurable size and border
  • Simple CLI and Python API

Installation

pip install qr-code-generator-cli

Or install from source:

git clone https://github.com/nabilragab/qrgen.git
cd qrgen
pip install .

Quick Start

Command Line

# Generate a white QR code (default)
qrgen "https://example.com"

# Generate an SVG
qrgen "https://example.com" --output qr.svg

# Custom color
qrgen "https://example.com" --fg-color "#0000FF" --output blue.svg

Python API

from qr_code_generator import create_qr_code

# Basic usage
create_qr_code("https://example.com", "qr.png")

# SVG with custom color
create_qr_code("https://example.com", "qr.svg", fg_color="#FF5733")

# With all options
create_qr_code(
    data="https://example.com",
    output_file="custom.svg",
    fg_color="#694585",
    box_size=15,
    border=2,
)

CLI Reference

usage: qrgen [-h] [-o OUTPUT] [-c COLOR] [--box-size SIZE] [--border SIZE] [-v] data

Generate QR codes with customizable colors in PNG and SVG formats.

positional arguments:
  data                  Data to encode in the QR code (URL, text, etc.)

options:
  -h, --help            show this help message and exit
  -o, --output OUTPUT   Output file path (default: qrcode.png)
  -c, --fg-color COLOR  Foreground color in hex format (default: "#FFFFFF")
  --box-size SIZE       Size of each box in the QR code (default: 10)
  --border SIZE         Border size around the QR code (default: 4)
  -v, --version         show program's version number and exit

API Reference

create_qr_code(data, output_file, fg_color="#FFFFFF", box_size=10, border=4)

Generate a QR code with customizable options.

Parameters:

Parameter Type Default Description
data str required Data to encode (URL, text, etc.)
output_file str required Output path (.png or .svg)
fg_color str "#FFFFFF" Foreground color in hex format
box_size int 10 Size of each QR code module
border int 4 Border size (minimum 4 per spec)

Returns: str - Path to the generated file.

Examples

Generate QR codes for different use cases

# Website URL
qrgen "https://mywebsite.com" -o website.svg

# WiFi credentials (standard format)
qrgen "WIFI:T:WPA;S:MyNetwork;P:MyPassword;;" -o wifi.png

# Contact vCard
qrgen "BEGIN:VCARD\nVERSION:3.0\nN:Doe;John\nEND:VCARD" -o contact.png

# Plain text
qrgen "Hello, World!" -o hello.svg

Batch generation with Python

from qr_code_generator import create_qr_code

urls = [
    ("https://example.com", "example.svg"),
    ("https://google.com", "google.svg"),
    ("https://github.com", "github.svg"),
]

for url, filename in urls:
    create_qr_code(url, filename, fg_color="#333333")
    print(f"Generated {filename}")

Development

# Clone and install with dev dependencies
git clone https://github.com/nabilragab/qrgen.git
cd qrgen
pip install -e ".[dev]"

# Run linting
ruff check src/ tests/

# Run tests
pytest -v

# Build distribution
python -m build

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

qr_code_generator_cli-1.0.0.tar.gz (8.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

qr_code_generator_cli-1.0.0-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

Details for the file qr_code_generator_cli-1.0.0.tar.gz.

File metadata

  • Download URL: qr_code_generator_cli-1.0.0.tar.gz
  • Upload date:
  • Size: 8.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for qr_code_generator_cli-1.0.0.tar.gz
Algorithm Hash digest
SHA256 e4ce8cdaa3217b1d8ffad3e86569df1a5b5528bfb6d387fcb431db203ec8e909
MD5 f05299a27cd1865bc0503391d9be8fe0
BLAKE2b-256 52262f4232380a51c5aef01db4ecee92fda51d419330c3a9fef5b741442b38cd

See more details on using hashes here.

File details

Details for the file qr_code_generator_cli-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for qr_code_generator_cli-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 80512734300b922f5ed874ac1fef898c00273d694fca11b37cac8306460691ea
MD5 d3251c4141555155644f30590c32db58
BLAKE2b-256 f9697aa54dc7780c64d398dcbf1311c8986a71765ce3138c6863c0c7805d048d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page