Skip to main content

Aztec Code generator

PyPI License: MIT Build Status

This is a pure-Python library to generate Aztec Code 2D barcodes.

Changelog

  • v0.1-v0.2: initial Python packaging
  • v0.3: allow optional border, more efficient matrix representation
  • v0.4: merge https://github.com/delimitry/aztec_code_generator/pull/5 and fix tests
  • v0.5:
    • code simplification
    • more efficient internal data structures (Enum)
    • encoding of FLG(n)
    • correct handling of Python 3 str vs. bytes (Aztec Code natively encodes bytes, not characters, and a reader's default interpretation of those bytes should be ISO-8859-1 aka Latin-1)
  • v0.6:
    • more code simplification
    • make Pillow dependency optional
    • add print_fancy for UTF-8 output (inspired by qrencode -t ansiutf8)
    • bugfix for DIGIT→PUNCT transition (and add missed test case)
    • allow customization of error correction percentage level
  • v0.7:
  • v0.8-v0.9:
    • replace Travis-CI with Github Actions for CI
  • v0.10
    • bugfix for lowercase → uppercase transition (fixes encoding of strings like abcABC)
  • v0.11
    • fix docstrings
    • change default module_size in image output to 2 pixels; ZXing can't read with module_size=1
  • v0.12
    • fix CRLF optimal sequence bug (#4)
    • fix bugs with calculation of suitable matrix size and error correction level (#7)
    • add support for SVG output (#6)
    • add additional test cases
    • switch to pyrxing for barcode readability testing
    • use uv to build and deploy

Installation

Releases from PyPi may be installed with pip3 install aztec_code_generator.

Bleeding-edge version from master branch of this repository can be installed with pip3 install https://github.com/dlenski/aztec_code_generator/archive/master.zip.

Dependencies

Pillow (Python image generation library) is required if you want to generate image objects and files.

Usage

Creating and encoding

from aztec_code_generator import AztecCode
data = 'Aztec Code 2D :)'
aztec_code = AztecCode(data)

The AztecCode() constructor takes additional, optional arguments:

  • size and compact: to set a specific symbol size (e.g. 19, True for a compact 19×19 symbol); see keys(aztec_code_generator.configs) for possible values
  • ec_percent for error correction percentage (default is the recommended 23), plus size a

Saving an image file

aztec_code.save('aztec_code.png', module_size=4, border=1) will save an image file aztec_code.png of the symbol, with 4×4 blocks of white/black pixels in the output, and with a 1-block border.

Other image formats supported by Pillow are supported as well, as is SVG via a customized SVG generator. Although SVG files are losslessly scalable, they are generally an inefficient format for representing 2D barcodes, producing files ~3-5× larger than equivalent PNG images.

Example

Aztec Code

Creating an image object

aztec_code.image() will yield a monochrome-mode PIL Image object representing the image in-memory. It also accepts optional module_size and border.

Text-based output

aztec_code.print_fancy() will print the resulting Aztec Code to standard output using Unicode half-height block elements encoded with UTF-8 and ANSI color escapes. It accepts optional border.

aztec_code.print_out() will print out the resulting Aztec Code to standard output as plain ASCII text, using # and characters:

##  # ## ####
 #   ## #####  ###
 #  ##  # #   # ###
## #  #    ## ##
    ## # #    # #
## ############ # #
 ### #       ###  #
##   # ##### # ## #
 #   # #   # ##
 # # # # # # ###
    ## #   # ## ##
#### # ##### ## #
  # ##       ## ##
 ##  ########### #
  ##    # ##   ## #
     ## # ### #  ##
      ############
##   #     # ##   #
##  #    ## ###   #

Authors:

Originally written by Dmitry Alimov (delimtry).

Updates, bug fixes, Python 3-ification, packaging, and careful bytes-vs.-str handling by Daniel Lenski (dlenski).

License:

Released under The MIT License.

Metadata

Release files for aztec_code_generator 0.12

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for aztec_code_generator 0.12
File Size Uploaded
aztec_code_generator-0.12.tar.gz 12.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for aztec_code_generator 0.12
File Interpreter ABI Platform
aztec_code_generator-0.12-py3-none-any.whl Python 3 none any Details

Total release size: 24.9 kB

Release files / aztec_code_generator-0.12.tar.gz

Download URL aztec_code_generator-0.12.tar.gz
Size 12.2 kB
Tags Source
SHA-256 checksum
How to use checksums
e27db502c081d0336406bb587ddfe837a8b0a5d44835522f1f21f470c964706b
BLAKE2b-256 checksum
How to use checksums
9ea06ec8038e82fe3cb845cdc8d274fcaecc8db6f911d31d6be9b357f3308d23
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / aztec_code_generator-0.12-py3-none-any.whl

Download URL aztec_code_generator-0.12-py3-none-any.whl
Size 12.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b8b498b5b93378e9c99226a7fada8811e41be33aa20973398d5eeebd19629909
BLAKE2b-256 checksum
How to use checksums
0a869c03721a209ca7b8e9c86ced0d4ade54d99faafb25098b520e9fc7694bcc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release history Release notifications | RSS feed

This release

0.12 This release

2 release files

0.11.1

2 release files

0.11

2 release files

0.10

2 release files

0.9

2 release files

0.8

2 release files

0.6

2 release files

0.5

1 release file

0.4

1 release file

0.3

1 release file

0.2

1 release file

0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page