Skip to main content

Decode and verify French ANTS 2D-Doc barcodes (QR/DataMatrix)

Project description

py2ddoc

Python library to decode and verify French ANTS 2D-Doc barcodes (QR Code / Data Matrix).

The 2D-Doc standard is issued by the French Agence Nationale des Titres Sécurisés (ANTS) and is embedded in many official French documents: tax notices, pay slips, driving licences, vehicle registration certificates, social security attestations, etc.

Features

  • Parse 2D-Doc v2, v3, and v4 barcodes
  • Verify ECDSA (P-256, P-384) and RSA-PKCS1v15 digital signatures
  • ANTS TSL bundled — no external file required out of the box
  • Decode field IDs to human-readable names for all major document types
  • Pure Python — no native dependencies beyond cryptography

Installation

pip install py2ddoc

Quickstart

from py2ddoc import TwoDDoc

# The ANTS TSL is bundled with the package — no external file needed
barcode = "DC03FR010001AAAA0000000101Jean\x1d02Dupont\x1fSIGNATURE..."
doc = TwoDDoc.from_string(barcode)

print(doc)
# 2D-Doc v03
#   Type         : 0001 — Avis d'imposition
#   CA / Cert    : FR01 / 0001
#   Doc date     : 2023-05-15
#   Sign date    : 2023-05-15
#   Authenticity : ✓ verified
#   Fields:
#     [01] Numéro de l'avis d'imposition: 12345678901234
#     ...

print(doc.is_authentic)    # True
print(doc.doc_type_label)  # "Avis d'imposition"
print(doc.fields)          # {"01": "...", "02": "..."}
print(doc.named_fields)    # {"numero_avis": "...", "nom": "..."}

Parse without verification

from py2ddoc import parse

parsed = parse(barcode_string)
print(parsed.ca_id)    # "FR01"
print(parsed.doc_type) # "0001"
print(parsed.fields)   # {"01": "value", ...}

Load a single certificate manually

from py2ddoc import TrustStore

with open("my_cert.der", "rb") as f:
    store = TrustStore.from_der("FR01", f.read())

doc = TwoDDoc.from_string(barcode, trust_store=store)

# Or from PEM:
with open("my_cert.pem", "rb") as f:
    store = TrustStore.from_pem("FR01", f.read())

Merge multiple stores

from py2ddoc import TrustStore, TwoDDoc

bundled = TrustStore.from_bundled_tsl()
extra = TrustStore.from_pem("FR99", open("extra.pem", "rb").read())
store = bundled.merge(extra)
doc = TwoDDoc.from_string(barcode, trust_store=store)

Trust Store (TSL)

The official ANTS TSL is bundled with this package and loaded automatically when you call TwoDDoc.from_string(). No download or configuration is needed.

For advanced use cases (e.g. a custom authority or a TSL downloaded independently), you can load it explicitly:

store = TrustStore.from_tsl("/path/to/tsl_signed.xml")
doc = TwoDDoc.from_string(barcode, trust_store=store)

The official TSL file is published by ANTS at:

https://pub.ants.gouv.fr/2D-DOC/V1/PRD/01_TSL/tsl_signed.xml

Supported document types

Code Label
0001 Avis d'imposition
0007 Fiche de paie
0008 Attestation Pôle Emploi
000C Permis de conduire
000E Carte nationale d'identité
001A Attestation de droits Sécurité Sociale
0024 Certificat d'immatriculation
(see py2ddoc/fields.py for the full list)

Exceptions

Exception Raised when
ParseError Barcode content is malformed
CertificateNotFoundError CA ID not found in trust store
SignatureError Signature present but invalid

All inherit from TwoDBarcodeError.

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

py2ddoc-0.1.0.tar.gz (26.9 kB view details)

Uploaded Source

Built Distribution

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

py2ddoc-0.1.0-py3-none-any.whl (28.6 kB view details)

Uploaded Python 3

File details

Details for the file py2ddoc-0.1.0.tar.gz.

File metadata

  • Download URL: py2ddoc-0.1.0.tar.gz
  • Upload date:
  • Size: 26.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for py2ddoc-0.1.0.tar.gz
Algorithm Hash digest
SHA256 1bdfa13ed8737605dd6c19c7115c779fbddfe2118110e399f09e33b47850bb17
MD5 16558a703982c22310b2b6009fd87b97
BLAKE2b-256 605ac591c7d9506731032e6363657640e97fbffac1c3a30ee23d1cdcc82f40e2

See more details on using hashes here.

Provenance

The following attestation bundles were made for py2ddoc-0.1.0.tar.gz:

Publisher: publish.yml on Game-K-Hack/py2ddoc

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file py2ddoc-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: py2ddoc-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 28.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for py2ddoc-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f0f34e3fc5318e4ee8c001474df517f41986e978f973af6cb02b657ef2d2e509
MD5 bc6a758cd6206ca79778411c7ced19c4
BLAKE2b-256 e7d4b5b1a68a96493db34ab18d0ef2cc1b9f4224beb1bdcd0bdd0ecf602f16a4

See more details on using hashes here.

Provenance

The following attestation bundles were made for py2ddoc-0.1.0-py3-none-any.whl:

Publisher: publish.yml on Game-K-Hack/py2ddoc

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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