shaped-qr-label
Generate a QR code with a text label drawn on top of it — with correct Arabic shaping and right-to-left layout (letters properly joined, positioned start/middle/end, read right-to-left), while keeping the QR code scannable. English/Latin text is supported too; direction is auto-detected per string.
Built because no existing PyPI/GitHub library reliably combined: QR generation + a still-scannable overlay label + correctly shaped Arabic text.
Why this is hard
Arabic letters are contextual — each letter's shape changes depending on whether it's at the start, middle, or end of a word (منفصل / بداية / وسط / نهاية) — and the script is right-to-left. Most imaging libraries draw each character in isolation, unjoined, and left-to-right, which garbles Arabic text. This library uses Pillow's raqm text-layout backend (HarfBuzz for shaping + FriBidi for bidi reordering) and ships a tested Arabic font (Noto Naskh Arabic) so results don't depend on fonts installed on the host.
Install
pip install shaped-qr-label
Arabic shaping requires Pillow to be built with raqm support. Official Pillow wheels for Linux/macOS/Windows have included it since Pillow 8.2+. You can check at runtime:
from shaped_qr_label import raqm_available
print(raqm_available()) # True if Arabic shaping will work correctly
If it returns False, Arabic text will still render but unjoined and in the
wrong visual order — reinstall Pillow from PyPI (not a system package
manager) to get a raqm-enabled build.
Usage
from shaped_qr_label import render_qr_label
img = render_qr_label(
"https://example.com/asset/123",
primary_text="مستودع الأدوية",
secondary_text="AST-00123",
)
img.save("qr.png")
Mixed or Latin-only text works the same way:
img = render_qr_label(
"https://example.com",
primary_text="Main Warehouse",
secondary_text="AST-00123",
)
Parameters
| Parameter | Default | Description |
|---|---|---|
url |
— | Data encoded in the QR code |
primary_text |
— | Larger, bold line (auto RTL/LTR) |
secondary_text |
None |
Smaller, grey second line (auto RTL/LTR) |
font_path |
bundled Noto Naskh Arabic | Path to a custom .ttf/.otf |
box_size |
18 |
QR module pixel size |
border |
3 |
QR quiet-zone modules |
label_width_ratio |
0.55 |
Label card width as a fraction of QR width |
label_height_ratio |
0.25 |
Label card height as a fraction of QR height |
Keep the label ratios conservative — beyond roughly 14% of the QR's total
area, some scanners fail to decode (error correction level H is used
internally to leave headroom for this).
License
Code: MIT, © Musa Alahmed — see LICENSE.
Bundled font: SIL Open Font License 1.1 — see
src/shaped_qr_label/fonts/NOTICE.txt.
Contributions are welcome under the same MIT license; please keep the copyright notice intact in any fork or redistribution.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file shaped_qr_label-0.1.0.tar.gz.
File metadata
- Download URL: shaped_qr_label-0.1.0.tar.gz
- Upload date:
- Size: 93.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
01145688b5a381d1c9a5c71e20f02c19f01b774e36c593070ad06c2a875a470d
|
|
| MD5 |
937876b0890f2622e97e4604d47270ba
|
|
| BLAKE2b-256 |
27ecd1292754629b8b298d60091d539a7d3ba94c48c0f66ff87a83226c401ccb
|
Provenance
The following attestation bundles were made for shaped_qr_label-0.1.0.tar.gz:
Publisher:
publish.yml on MUSAALAHMED4/shaped-qr-label
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
shaped_qr_label-0.1.0.tar.gz -
Subject digest:
01145688b5a381d1c9a5c71e20f02c19f01b774e36c593070ad06c2a875a470d - Sigstore transparency entry: 2343418626
- Sigstore integration time:
-
Permalink:
MUSAALAHMED4/shaped-qr-label@5207e5e5293e95403f1b1658dd13244ad983ce1e -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/MUSAALAHMED4
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@5207e5e5293e95403f1b1658dd13244ad983ce1e -
Trigger Event:
release
-
Statement type:
File details
Details for the file shaped_qr_label-0.1.0-py3-none-any.whl.
File metadata
- Download URL: shaped_qr_label-0.1.0-py3-none-any.whl
- Upload date:
- Size: 91.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
06ba53ba8618ffcad0563a76a49d5d45034555e7f17f5deaed449db07a9587b0
|
|
| MD5 |
294f639f54b203a6a522039af232bce7
|
|
| BLAKE2b-256 |
405e9cc43866950757bf0b3b55058a65cebf63f2b5a2bc5e624155243b4be67b
|
Provenance
The following attestation bundles were made for shaped_qr_label-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on MUSAALAHMED4/shaped-qr-label
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
shaped_qr_label-0.1.0-py3-none-any.whl -
Subject digest:
06ba53ba8618ffcad0563a76a49d5d45034555e7f17f5deaed449db07a9587b0 - Sigstore transparency entry: 2343418673
- Sigstore integration time:
-
Permalink:
MUSAALAHMED4/shaped-qr-label@5207e5e5293e95403f1b1658dd13244ad983ce1e -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/MUSAALAHMED4
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@5207e5e5293e95403f1b1658dd13244ad983ce1e -
Trigger Event:
release
-
Statement type: