Generate Wi-Fi QR Code Instantly with Python: A Complete Guide
Sharing Wi-Fi passwords can be frustrating—especially when they are long, complex, or frequently updated. Instead of typing passwords again and again, you can generate a QR code that allows users to connect instantly by simply scanning it. With Python, creating a Wi-Fi QR code is quick, efficient, and customizable.
In this blog, you’ll learn how to generate Wi-Fi QR codes using Python, understand the format behind them, and explore practical use cases.
1. What is a Wi-Fi QR Code?
A Wi-Fi QR code contains your network credentials in a special format. When scanned, it automatically connects a device to the Wi-Fi network without manually entering the password.
Standard Format:
WIFI:T:<encryption>;S:<SSID>;P:<password>;H:<hidden>;;
Where:
- T → Encryption type (WPA, WEP, or nopass)
- S → Network name (SSID)
- P → Password
- H → Hidden network (true/false)
2. Why Use Wi-Fi QR Codes?
- Faster connection for guests
- No need to share passwords verbally
- Reduces typing errors
- Useful for cafes, offices, and homes
- Enhances user experience
3. Required Python Library
We’ll use the qrcode library to generate QR codes.
Installation
pip install qrcode[pil]
4. Generate a Basic Wi-Fi QR Code
Here’s a simple Python script:
import qrcode
ssid = "MyWiFi"
password = "12345678"
encryption = "WPA" # WPA, WEP, or nopass
wifi_data = f"WIFI:T:{encryption};
S:{ssid};P:{password};H:false;;"
qr = qrcode.make(wifi_data)
qr.save("wifi_qr.png")
print("QR Code generated successfully!")
5. Customize the QR Code
You can create more visually appealing QR codes:
import qrcode
qr = qrcode.QRCode(
version=1,
box_size=10,
border=4
)
wifi_data = "WIFI:T:WPA;S:MyWiFi;
P:12345678;H:false;;"
qr.add_data(wifi_data)
qr.make(fit=True)
img = qr.make_image(fill="black",
back_color="white")
img.save("custom_wifi_qr.png")
6. Add Logo to QR Code (Advanced)
You can embed a logo in the center:
from PIL import Image
import qrcode
qr = qrcode.QRCode(error_correction=
qrcode.constants.ERROR_CORRECT_H)
qr.add_data("WIFI:T:WPA;S:MyWiFi;
P:12345678;H:false;;")
qr.make()
img = qr.make_image().convert("RGB")
logo = Image.open("logo.png")
logo = logo.resize((60, 60))
pos = ((img.size[0] - logo.size[0]) // 2,
(img.size[1] - logo.size[1]) // 2)
img.paste(logo, pos)
img.save("wifi_qr_logo.png")
7. Batch Generate Multiple Wi-Fi QR Codes
Useful for businesses managing multiple networks:
networks = [
("OfficeWiFi", "pass123"),
("GuestWiFi", "guest456")
]
import qrcode
for ssid, password in networks:
data = f"WIFI:T:WPA;S:{ssid};
P:{password};H:false;;"
img = qrcode.make(data)
img.save(f"{ssid}_qr.png")
8. Real-World Use Cases
1. Cafes and Restaurants
Display QR codes for customers to connect instantly.
2. Offices
Provide easy Wi-Fi access to employees and visitors.
3. Homes
Share Wi-Fi with guests without revealing passwords.
4. Events
Offer seamless internet access at conferences or gatherings.
9. Tips for Better QR Codes
- Use high contrast colors (black & white works best)
- Keep QR code size large enough for scanning
- Avoid overcrowding with large logos
- Test the QR code before sharing
10. Common Issues and Fixes
QR Code Not Working
- Check SSID and password accuracy
- Ensure correct encryption type
Not Scanning Properly
- Increase image resolution
- Improve lighting conditions
Connection Fails
- Ensure Wi-Fi is active
- Verify device compatibility
11. Security Considerations
- Avoid sharing sensitive networks publicly
- Change passwords regularly
- Use guest networks for public access
- Limit access if needed
Conclusion
Generating a Wi-Fi QR code with Python is a simple yet powerful way to improve user experience and streamline connectivity. With just a few lines of code, you can create QR codes that eliminate the hassle of manually entering passwords.
From basic generation to advanced customization with logos and batch processing, Python gives you complete control over how you share network access. Whether you’re managing a home network or running a business, this small automation can make a big difference.
Start experimenting today and make Wi-Fi sharing smarter, faster, and more secure!