Skip to main content

Decode and encode MergeID electronic invoice QR codes

Project description

qrid — Python

Decode and encode MergeID electronic invoice QR codes.

Python port of qrid/codec (PHP). All three implementations (PHP, Node.js, Python) share the same payload format and function signatures, so QR codes generated by any one of them scan correctly in the others.

Installation

# Decode only (no extra dependencies)
pip install qrid

# Decode + encode SVG
pip install 'qrid[encode]'

Usage

Decode

from qrid import decode_qr_id

# `encoded` is the raw string value scanned from a MergeID QR code
payload = decode_qr_id(encoded)

print(payload["v"])       # Payload schema version (int, currently 1)
print(payload["code"])    # Installation / activity code  (e.g. "ACT-001")
print(payload["id"])      # Tax or company ID              (e.g. "3101679980")
print(payload["company"]) # Company legal name
print(payload["email"])   # Billing e-mail address
print(payload["address"]) # Physical address

decode_qr_id strips surrounding whitespace before decoding, so strings copied with accidental padding are handled transparently.

Exceptions raised:

Exception Cause
ValueError Input is not valid base64
json.JSONDecodeError Decoded bytes are not valid JSON
import json
from qrid import decode_qr_id

try:
    payload = decode_qr_id(raw)
except ValueError:
    # QR data was not base64
    ...
except json.JSONDecodeError:
    # QR data decoded but was not the expected JSON structure
    ...

Encode (requires qrid[encode])

from qrid import encode_qr_id

svg = encode_qr_id(
    code="ACT-001",
    id="3101679980",
    company="Acme Corp S.A.",
    email="billing@acme.example",
    address="123 Main St, San José, Costa Rica",
)

# Write to a file
with open("invoice_qr.svg", "w") as f:
    f.write(svg)

# Or serve directly
# Content-Type: image/svg+xml

Exceptions raised:

Exception Cause
ImportError segno is not installed (pip install 'qrid[encode]')

Payload format

The QR code data is a UTF-8 JSON object encoded as standard base64 (no line-breaks):

{
  "v": 1,
  "code": "ACT-001",
  "id": "3101679980",
  "company": "Acme Corp S.A.",
  "email": "billing@acme.example",
  "address": "123 Main St, San José, Costa Rica"
}
Field Type Description
v int Payload schema version. Currently always 1.
code str Installation or activity code that links the QR to an internal record.
id str Tax / company registration ID.
company str Legal company name (UTF-8, including accented characters).
email str Primary billing or contact e-mail address.
address str Physical address of the company.

Requirements

Dependency Version Required for
Python >= 3.9 Always
segno >= 1.6 encode_qr_id() only

Running tests

pip install 'qrid[dev]'
pytest

License

MIT

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

qrid-1.0.0.tar.gz (3.8 kB view details)

Uploaded Source

Built Distribution

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

qrid-1.0.0-py3-none-any.whl (3.7 kB view details)

Uploaded Python 3

File details

Details for the file qrid-1.0.0.tar.gz.

File metadata

  • Download URL: qrid-1.0.0.tar.gz
  • Upload date:
  • Size: 3.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for qrid-1.0.0.tar.gz
Algorithm Hash digest
SHA256 c9b251074bad740366752638e02444cf2c0a9f15e65d7bf6e4736d2dd6b511b3
MD5 3893d3354853726cdde6ace25f8fa10b
BLAKE2b-256 f53b209a38e6f0749885eddbd64f4db2e2a6fa959422fe8d6f7649428881953b

See more details on using hashes here.

File details

Details for the file qrid-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: qrid-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 3.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for qrid-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9105af5a648654f437d975a0f07e4322a43ce4b23add28b93d4157a362ce4de9
MD5 3ae38e0c0eb32578a7daca8a29984e2e
BLAKE2b-256 72d0740989e17b594d2b7f28c11a74006667b22e2d79829ed802db90e89f664f

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