{"id":4290,"library":"treepoem","title":"treepoem","description":"treepoem is a Python library (current version 3.28.0) for rendering various barcode types including QR code, Aztec, PDF417, I25, Code128, and Code39. It acts as a wrapper around the open-source BWIPP PostScript barcode library and utilizes the Ghostscript command-line tool for rendering. The library is actively maintained and typically sees frequent updates to its vendored BWIPP component.","status":"active","version":"3.28.0","language":"en","source_language":"en","source_url":"https://github.com/adamchainz/treepoem","tags":["barcode","qrcode","aztec","pdf417","code128","code39","bwipp","ghostscript","image generation","pil","pillow"],"install":[{"cmd":"pip install treepoem","lang":"bash","label":"Install Python package"},{"cmd":"sudo apt-get install ghostscript","lang":"bash","label":"Install Ghostscript (Debian/Ubuntu)"},{"cmd":"brew install ghostscript","lang":"bash","label":"Install Ghostscript (macOS)"}],"dependencies":[{"reason":"Required for outputting barcode images to various formats (e.g., PNG).","package":"Pillow","optional":false},{"reason":"External command-line tool essential for rendering PostScript into images. Must be installed separately.","package":"Ghostscript","optional":false}],"imports":[{"symbol":"generate_barcode","correct":"from treepoem import generate_barcode"},{"note":"Commonly used with treepoem for image manipulation, like adding borders.","symbol":"ImageOps","correct":"from PIL import ImageOps"}],"quickstart":{"code":"import treepoem\nfrom PIL import ImageOps\n\n# Generate a QR code barcode\nimage = treepoem.generate_barcode(\n    barcode_type=\"qrcode\",\n    data=\"https://www.example.com\"\n)\n\n# Add a white border and save as a monochrome PNG\nimage = ImageOps.expand(image, border=10, fill=\"white\")\nimage.convert(\"1\").save(\"barcode.png\")\nprint(\"Generated barcode.png\")","lang":"python","description":"This quickstart generates a QR code from a URL, adds a 10-pixel white border, and saves it as a monochrome PNG file named 'barcode.png'. The `ImageOps.expand` and `image.convert(\"1\")` steps are common for preparing the output image."},"warnings":[{"fix":"Ensure Ghostscript version 9.26 or newer is installed. Check your Ghostscript version with `gs --version`.","message":"Older Ghostscript versions (e.g., 9.22+) may produce smeared barcode images. While a fix was merged in Ghostscript 9.26, some smearing might still occur with certain barcodes.","severity":"gotcha","affected_versions":"Ghostscript < 9.26 (potential issues)"},{"fix":"Verify that Ghostscript can be installed and is accessible in your target deployment environment. Consider containerization (e.g., Docker) to manage external dependencies.","message":"treepoem relies on an external Ghostscript installation, which is a non-Python dependency. This can complicate deployment in environments where installing system-level packages is restricted (e.g., some serverless functions, shared hosting).","severity":"gotcha","affected_versions":"All versions"},{"fix":"For applications requiring high-volume barcode generation, explore alternatives that can keep the Ghostscript process alive or use a different rendering approach if performance is critical.","message":"Generating multiple barcodes in a tight loop can be slow because treepoem re-initializes and reopens the Ghostscript subprocess for each call to `generate_barcode()`.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}