Python QR Code Library

Generate QR Codes with Python

Python offers powerful QR code libraries like qrcode and segno for scripting, automation, and data pipelines. Generate QR codes locally or use the QRCode.fun API for advanced styling.

Installation

Install Python QR code libraries using pip.

pip
pip install qrcode[pil]
pip (segno)
pip install segno

Generate QR Codes with Python Libraries

Code examples using popular Python QR code libraries.

Basic QR Code with qrcode
import qrcode

# Simple generation
img = qrcode.make('https://qrcode.fun')
img.save('qrcode.png')

# Advanced with customization
qr = qrcode.QRCode(
    version=1,
    error_correction=qrcode.constants.ERROR_CORRECT_H,
    box_size=10,
    border=4,
)
qr.add_data('https://qrcode.fun')
qr.make(fit=True)

img = qr.make_image(fill_color='#1A2B3C', back_color='white')
img.save('qrcode_custom.png')
SVG Output with segno
import segno

qr = segno.make('https://qrcode.fun')
qr.save('qrcode.svg', scale=10)
qr.save('qrcode.png', scale=10, dark='#1A2B3C')
QR Code with Logo
import qrcode
from PIL import Image

qr = qrcode.QRCode(error_correction=qrcode.constants.ERROR_CORRECT_H)
qr.add_data('https://qrcode.fun')
qr.make(fit=True)

img = qr.make_image(fill_color='#1A2B3C', back_color='white').convert('RGB')

# Add logo
logo = Image.open('logo.png')
logo_size = img.size[0] // 4
logo = logo.resize((logo_size, logo_size))

pos = ((img.size[0] - logo_size) // 2, (img.size[1] - logo_size) // 2)
img.paste(logo, pos)
img.save('qrcode_logo.png')
QRCode.fun API

Generate QR Codes via API in Python

Call the QRCode.fun API from Python to generate styled QR codes with custom colors, shapes, and logos.

Python API Integration
import requests

response = requests.post('https://qrcode.fun/api/generate-qr-styled', json={
    'data': 'https://qrcode.fun',
    'width': 300,
    'height': 300,
    'type': 'png',
    'margin': 10,
    'dotsOptions': {
        'color': '#1A2B3C',
        'type': 'rounded'
    },
    'cornersSquareOptions': {
        'color': '#8564C3',
        'type': 'extra-rounded'
    },
    'backgroundOptions': {
        'color': '#FFFFFF'
    }
})

result = response.json()
# result['data'] contains the base64 PNG data URL
print(result['data'][:50])

Live QR Code Preview

Try generating a QR code with Python right now.

QR preview

Native Library vs API

Compare using a Python QR code library directly versus the QRCode.fun API.

FeatureNative LibraryQRCode.fun API
Setup complexitypip install + Pillow for imagesSingle HTTP request via requests
CustomizationColors, error correction, box sizeFull styling: colors, shapes, logos
Offline supportYesRequires internet
MaintenanceUpdate packages manuallyAlways up-to-date
Output formatsPNG, SVG, EPS, terminalPNG, SVG

Python QR Code Use Cases

Common scenarios where Python developers generate QR codes.

Data Science & Reports

Embed QR codes in automated reports, Jupyter notebooks, and data visualizations linking to dashboards or datasets.

Web Applications (Django/Flask)

Generate QR codes server-side in Django or Flask apps for user profiles, tickets, and authentication tokens.

Automation Scripts

Create QR codes in batch processing scripts for inventory labels, asset tracking, and document management.

IoT & Raspberry Pi

Generate QR codes on embedded devices for Wi-Fi setup, device pairing, and configuration sharing.

Frequently Asked Questions

Common questions about generating QR codes with Python.

The qrcode library is the most popular choice — it is simple, well-maintained, and supports Pillow for image output. segno is a good alternative offering SVG output and more compact code.

Start generating QR codes with Python

Use our free online generator or integrate the API into your Python scripts, Django apps, or data pipelines.