Skip to main content

Aztec Code generator in Python

Project description

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 DIGITPUNCT 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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aztec_code_generator-0.12.tar.gz (12.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aztec_code_generator-0.12-py3-none-any.whl (12.8 kB view details)

Uploaded Python 3

File details

Details for the file aztec_code_generator-0.12.tar.gz.

File metadata

  • Download URL: aztec_code_generator-0.12.tar.gz
  • Upload date:
  • Size: 12.2 kB
  • Tags: Source
  • Uploaded using 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}

File hashes

Hashes for aztec_code_generator-0.12.tar.gz
Algorithm Hash digest
SHA256 e27db502c081d0336406bb587ddfe837a8b0a5d44835522f1f21f470c964706b
MD5 396e188dc53108373fd134898689a50f
BLAKE2b-256 9ea06ec8038e82fe3cb845cdc8d274fcaecc8db6f911d31d6be9b357f3308d23

See more details on using hashes here.

File details

Details for the file aztec_code_generator-0.12-py3-none-any.whl.

File metadata

  • Download URL: aztec_code_generator-0.12-py3-none-any.whl
  • Upload date:
  • Size: 12.8 kB
  • Tags: Python 3
  • Uploaded using 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}

File hashes

Hashes for aztec_code_generator-0.12-py3-none-any.whl
Algorithm Hash digest
SHA256 b8b498b5b93378e9c99226a7fada8811e41be33aa20973398d5eeebd19629909
MD5 107d1a92c91307518c8ca159731c960c
BLAKE2b-256 0a869c03721a209ca7b8e9c86ced0d4ade54d99faafb25098b520e9fc7694bcc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page