Generating QR Codes with Python's segno Library
This tutorial explains how to install the segno Python package and use it to create simple and customized QR codes for URLs, Wi‑Fi credentials, vCards, artistic designs, and in‑memory images, providing complete code examples and practical ideas for personal and social applications.
This article introduces QR codes beyond industrial uses and demonstrates how to generate them programmatically with Python's segno library.
Installation
Install the library and import it:
pip install segno import segnoCreating a simple QR code
Generate a tiny QR code containing a short string and save it as an image:
price_tag = segno.make("£9.99")
price_tag.save("Price Tag.png")QR codes for URLs and media
Encode a YouTube video link and control the output size:
video = segno.make('https://youtu.be/px6FeOKD3Zc')
video.save('Video.png', scale=4)Wi‑Fi configuration QR code
wifi_settings = {
"ssid": "(Wifi Name)",
"password": "(Wifi Password)",
"security": "WPA"
}
wifi = segno.helpers.make_wifi(**wifi_settings)
wifi.save("Wifi.png", dark="yellow", light="#323524", scale=8)vCard QR code
vcard = segno.helpers.make_vcard(
name='Pxxx;Jxxx',
displayname='Times Tables Furniture',
email=('[email protected]'),
url=[
'https://www.etsy.com/uk/shop/TimesTablesFurniture',
'https://www.facebook.com/profile.php?id=100083448533180'
],
phone="+44xxxxxxxxxx"
)
img = vcard.to_pil(scale=6, dark="#FF7D92").rotate(45, expand=True)
img.save('Etsy.png')Artistic QR codes
piet = segno.make('https://esolangs.org/wiki/Piet', error='h')
piet.to_artistic(background="background.png", target="Piet.png", scale=16)Custom QR code with company logo
awsom = segno.helpers.make_vcard(
name='Fison;Pete',
displayname='AWSOM Solutions Ltd.',
email=('[email protected]'),
url=[
'https://twitter.com/awsom_solutions',
'https://medium.com/@petefison',
'https://github.com/pfython'
],
phone="+44xxxxxxxxxx"
)
awsom.to_artistic(background="logo.png", target="AWSOM.png", scale=6, quiet_zone="#D29500")In‑memory QR generation
beatle = segno.make('Paul McCartney')
import io
buff = io.BytesIO()
beatle.save(buff, kind='svg')Load a background image directly from a URL and create an artistic QR code:
from urllib.request import urlopen
url = 'https://media.giphy.com/media/HNo1tVKdFaoco/giphy.gif'
bg_file = urlopen(url)
beatle = segno.make('Ringo Starr', error='h')
beatle.to_artistic(background=bg_file, target='ringo.gif', scale=10)The article concludes with a long list of creative, home‑use ideas for QR codes, ranging from recycling instructions on trash cans to emergency contact stickers on devices.
Python Programming Learning Circle
A global community of Chinese Python developers offering technical articles, columns, original video tutorials, and problem sets. Topics include web full‑stack development, web scraping, data analysis, natural language processing, image processing, machine learning, automated testing, DevOps automation, and big data.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.