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.
Typical usage flow
sequenceDiagram
actor Staff as Billing Staff
participant ERP as Billing / ERP System
participant Lib as qrid
participant QR as Invoice QR Code
participant App as MergeID App
Staff->>ERP: create invoice
ERP->>Lib: encode_qr_id(code, id, company, email, address)
Lib-->>ERP: SVG QR code
ERP->>QR: print / embed on invoice
Note over App,QR: later, at point of scan
App->>QR: scan with camera
QR-->>App: base64 payload string
App->>Lib: decode_qr_id(encoded)
Lib-->>App: { v, code, id, company, email, address }
App-->>Staff: display verified invoice identity
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
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 qrid-1.0.1.tar.gz.
File metadata
- Download URL: qrid-1.0.1.tar.gz
- Upload date:
- Size: 4.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
90e865d62120543bc16dd2e4a2af8adddce900f8deccad06529dcfc9e7ae2c64
|
|
| MD5 |
75363545f322c83ad3f850a8074a187c
|
|
| BLAKE2b-256 |
114c1b0820e160884b1166c6fe029eff0b5f3814da343039258bc0e3b5de99bf
|
Provenance
The following attestation bundles were made for qrid-1.0.1.tar.gz:
Publisher:
publish.yml on Quality-XP-Development-SESSA/qrid-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
qrid-1.0.1.tar.gz -
Subject digest:
90e865d62120543bc16dd2e4a2af8adddce900f8deccad06529dcfc9e7ae2c64 - Sigstore transparency entry: 2125828194
- Sigstore integration time:
-
Permalink:
Quality-XP-Development-SESSA/qrid-python@f356e65e398f751b4888dc9dc2daa5512048b773 -
Branch / Tag:
refs/tags/v1.0.1 - Owner: https://github.com/Quality-XP-Development-SESSA
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@f356e65e398f751b4888dc9dc2daa5512048b773 -
Trigger Event:
release
-
Statement type:
File details
Details for the file qrid-1.0.1-py3-none-any.whl.
File metadata
- Download URL: qrid-1.0.1-py3-none-any.whl
- Upload date:
- Size: 4.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0966ae13f6529e7b2d0f4b3f0f28a9e332c19bd04eae3666856ec55492ebecd4
|
|
| MD5 |
94b6368f9a2cbcf99c564999a9ce7bf7
|
|
| BLAKE2b-256 |
afc1502cb1a2132d40bb871b74870280539560019ff7154867cab3935369ee72
|
Provenance
The following attestation bundles were made for qrid-1.0.1-py3-none-any.whl:
Publisher:
publish.yml on Quality-XP-Development-SESSA/qrid-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
qrid-1.0.1-py3-none-any.whl -
Subject digest:
0966ae13f6529e7b2d0f4b3f0f28a9e332c19bd04eae3666856ec55492ebecd4 - Sigstore transparency entry: 2125828317
- Sigstore integration time:
-
Permalink:
Quality-XP-Development-SESSA/qrid-python@f356e65e398f751b4888dc9dc2daa5512048b773 -
Branch / Tag:
refs/tags/v1.0.1 - Owner: https://github.com/Quality-XP-Development-SESSA
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@f356e65e398f751b4888dc9dc2daa5512048b773 -
Trigger Event:
release
-
Statement type: