Generate QR Codes in Python: Numeric, Alphanumeric, Byte, Kanji, and Structured Append Modes

A QR code (quick-response code) is a type of two-dimensional matrix barcode. It uses four standardized modes of encoding: numeric, alphanumeric, byte or binary, and kanji. Its highest storage capacity can be 2,953 bytes.

What you’ll build: A Python script that generates QR codes in all five encoding modes — numeric, alphanumeric, byte, kanji, and structured append — using the segno library.

Key Takeaways

  • Python’s segno library is the only QR code library that supports all five encoding modes including structured append.
  • QR codes support up to 7,089 numeric characters, 4,296 alphanumeric characters, or 2,953 bytes of binary data per symbol.
  • Structured append mode splits large payloads across multiple QR codes, enabling storage beyond a single symbol’s capacity.
  • The generated QR codes can be verified using Dynamsoft Barcode Reader’s web-based scanner.

Common Developer Questions

  • How do I generate a QR code in Python using a specific encoding mode like kanji or byte?
  • What Python library supports QR code structured append for splitting data across multiple codes?
  • How do I store binary data like an image file inside a QR code with Python?

Prerequisites

Install the segno library:

pip install segno

To read and verify the generated QR codes, you can use Dynamsoft Barcode Reader. Get a 30-day free trial license to test it.

Here is a table about different modes:

Input mode Mode indicator Max. characters Possible characters, default encoding
Numeric only 1 7,089 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
Alphanumeric 2 4,296 0–9, A–Z (upper-case only), space, $, %, *, +, -, ., /, :
Binary/byte 4 2,953 ISO/IEC 8859-1
Kanji/kana 8 1,817 Shift JIS X 0208
Structured Append 3 unlimited Not specific

PS: structured append is a mode in which the data is divided into several barcodes.

In this article, we are going to talk about how to generate QR codes in different modes in Python.

Online version

Generate QR Codes in Each Encoding Mode

We are going to use the segno library to generate QR codes as this is the only library that supports structured append.

  1. Numeric QR Codes

    qrcode = segno.make_qr("9780593230060",mode="numeric")
    

    numeric

  2. Alphanumeric QR Codes

    qrcode = segno.make_qr("DYNAMSOFT",mode="alphanumeric")
    

    alphanumeric

  3. Kanji QR Codes

    qrcode = segno.make_qr("ディナムソフト",mode="kanji")
    

    kanji

    Shift-JIS will be used for encoding Kanji.

  4. Bytes QR Codes

    We can use bytes to store a UTF-8 encoded string.

    qrcode = segno.make_qr("Dynamsoft",mode="byte")
    

    byte-text

    We can also directly store the raw bytes of an image file.

    f = open("1-bit.png",mode="rb")
    qrcode = segno.make_qr(f.read(),mode="byte")
    

    byte-image

  5. Structured Append QR Codes

    If the content we need to store is larger than one QR code’s capacity or the version of the QR code will be too high if we store it in one QR code which makes it difficult to print and read, we can store the content in multiple QR codes. This can be done using the structured append mode.

    f = open("8-bit.png",mode="rb")
    qrcode_seq = segno.make_sequence(f.read(), symbol_count=2)
    

    structured_append_image

Read the Generated QR Codes with Dynamsoft Barcode Reader

You can use this Web QR Code Scanner based on Dynamsoft Barcode Reader to read the QR Codes we generated in this article.

Common Issues and Edge Cases

  • Kanji encoding fails with non-Shift-JIS characters. The kanji mode only supports characters in the Shift JIS X 0208 character set. If you pass Unicode characters outside this range, segno will raise an error. Convert your text to Shift-JIS first to verify compatibility.
  • Binary data exceeds single QR code capacity. A single QR code can hold at most 2,953 bytes. If your file is larger, use structured append mode with segno.make_sequence() and set symbol_count to split the data across multiple QR codes.
  • High-version QR codes are difficult to scan. When data fills a single QR code near capacity, the resulting symbol version (up to 40) becomes very dense and hard to scan reliably, especially from printed media. Prefer structured append or reduce payload size to keep the version below 10 for reliable scanning.

Source Code

Check out the source code to have a try:

https://github.com/tony-xlh/qr-code-generator