KHQR / EMVCo merchant-presented QR payload generator for Bakong / Cambodia (NBC KHQR spec v2.7-style TLV) with CRC-16/CCITT-FALSE verification.
This package generates the payload string (the EMV tag-length-value text) that you can encode into a QR image.
pip install konthaina-khqrOptional: generate QR images (PNG) using qrcode:
pip install "konthaina-khqr[qrcode]"- Static & Dynamic KHQR
- Correct KHR (116) / USD (840)
- Stable static QR (no timestamp)
- CRC-16 verification
- Decode / verify helpers
- CLI + PNG QR support
from konthaina_khqr import KHQRGenerator, MerchantType, Currency
result = (
KHQRGenerator(MerchantType.INDIVIDUAL)
.set_bakong_account_id("john_smith@devb")
.set_merchant_name("John Smith")
.set_currency(Currency.USD)
.set_amount(100.50)
.set_merchant_city("Phnom Penh")
.generate()
)
print(result.qr) # KHQR payload string
print(result.md5) # md5 of payloadfrom konthaina_khqr import verify, decode
ok = verify(result.qr)
data = decode(result.qr) # simple TLV decodekhqr --type individual --bakong john_smith@devb --name "John Smith" --amount 1.25 --currency USDGenerate a PNG (requires extras):
khqr --type individual --bakong john_smith@devb --name "John Smith" --amount 1.25 --currency USD --png out.pngpython -m venv .venv
. .venv/bin/activate # Windows: .venv\Scripts\activate
pip install -e ".[dev]"
pytest
ruff check .
mypy srcBuild:
python -m build
twine check dist/*Publish to TestPyPI:
twine upload -r testpypi dist/*Publish to PyPI:
twine upload dist/*For GitHub Actions + Trusted Publishing, see .github/workflows/publish.yml.