Generating QR Codes in Python with the segno Library
This article introduces QR codes, explains their diverse personal and social applications, and provides a step‑by‑step guide using Python’s segno library—including installation, creating simple and artistic QR codes for URLs, Wi‑Fi, vCards, and advanced in‑memory handling—along with creative ideas for everyday use.
When QR codes are mentioned, most people think of industrial uses, but this article focuses on personal and social applications, highlighting their non‑contact feature and versatility.
Interesting facts : QR codes were invented in 1994 and have become popular due to their ability to be scanned by any smartphone, triggering actions based on the encoded data such as opening URLs, connecting to Wi‑Fi, adding contacts, or showing locations.
Getting started : After researching, the author chose the segno module for its comprehensive features and documentation.
Installation :
<code>pip install segno</code>Creating a simple QR code (a tiny QR for a price tag):
<code>import segno
price_tag = segno.make("£9.99")
price_tag.save("Price Tag.png")</code>The .show() method can be used instead of .save() to open a temporary image for quick testing.
QR code for a URL (sharing a video link):
<code>import segno
video = segno.make('https://www.baidu.com/')
video.save('Video.png', scale=4)</code>Artistic QR codes using a background image (Piet "Hello World" script):
<code>pip install qrcode-artistic
import segno
piet = segno.make('https://www.baidu.com/', error='h')
piet.to_artistic(background="background.png", target='Piet.png', scale=16)</code>QR code containing Wi‑Fi credentials with custom colors:
<code>import segno
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)</code>QR code for a vCard (business card with logo background):
<code>import segno
vcard = segno.helpers.make_vcard(
name='Pxxx;Jxxx',
displayname='Times Tables Furniture',
email=('[email protected]'),
url=[
'https://www.baidu.com/',
'https://www.baidu.com/'
],
phone="+44xxxxxxxxxx",
)
img = vcard.to_pil(scale=6, dark="#FF7D92").rotate(45, expand=True)
img.save('Etsy.png')
</code>Another vCard example with a company logo:
<code>import segno
awsom = segno.helpers.make_vcard(
name='Fison;Pete',
displayname='AWSOM Solutions Ltd.',
email=('[email protected]'),
url=[
'https://www.baidu.com/',
'https://medium.com/@petefison',
'https://github.com/pfython'
],
phone="+44xxxxxxxxxx",
)
awsom.to_artistic(
background="logo.png",
target='AWSOM.png',
scale=6,
quiet_zone="#D29500"
)
</code>In‑memory handling (creating a QR code without writing to disk):
<code>import segno
beatle = segno.make('Paul McCartney')
beatle = qrcode.to_pil()
</code>Saving to a BytesIO buffer as SVG:
<code>import segno
import io
beatle = segno.make('Paul McCartney')
buff = io.BytesIO()
beatle.save(buff, kind='svg')
</code>Loading a background image directly from a URL:
<code>from urllib.request import urlopen
import segno
beatle = segno.make('Ringo Starr', error='h')
url = 'https://www.baidu.com/'
bg_file = urlopen(url)
beatle.to_artistic(background=bg_file, target='ringo.gif', scale=10)
</code>Creative, everyday QR code ideas include using QR codes for recycling rules, emergency contacts, treasure hunts, linking to travel diaries, appliance manuals, family histories, and more, encouraging readers to explore personal and social uses beyond commercial marketing.
QR codes on trash bins for recycling instructions
Send an email to family when you arrive home safely
Trigger updates when you leave home
Treasure hunts in your town with QR‑linked information
Postcards with QR codes linking to travel blogs
Appliance manuals (washer, microwave, 3D printer, etc.)
Family genealogy or property records
Online guestbook for visitors
QR‑linked shopping lists on the fridge
Weekly chore lists for household members
Lost‑item stickers for laptops, phones, drones
Pay‑by‑QR for shared fridge items or farm‑egg sales
Reservation management for TV/internet/gaming privileges
Emergency contacts for babysitters or pet sitters
Emergency utilities contacts during power outages
Local food delivery info for house‑sitters
Personal video reminders
Info about favorite decorations or artwork
Wine cellar tasting notes
Garden plant and tree labels with species and care details
Overall, the article demonstrates how to generate functional and artistic QR codes with Python and encourages readers to apply them creatively in daily life.
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.