Skip to main content

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

Metadata

Release files for py2ddoc 0.1.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for py2ddoc 0.1.4
File Size Uploaded Provenance
py2ddoc-0.1.4.tar.gz 26.9 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for py2ddoc 0.1.4
File Interpreter ABI Platform
py2ddoc-0.1.4-py3-none-any.whl Python 3 none any Details

Total release size: 55.5 kB

Release files / py2ddoc-0.1.4.tar.gz

Download URL py2ddoc-0.1.4.tar.gz
Size 26.9 kB
Tags Source
SHA-256 checksum
How to use checksums
0b16d8106ff226fa767377bffc4ad4062fdb6e7e48b6ae95153aae6dbb336845
BLAKE2b-256 checksum
How to use checksums
6ec2e4c8014dbb6ae8c36d44167ef9267bdae43876b317dd9309a625808d948f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Mar 20, 2026.

Transparency log

Release files / py2ddoc-0.1.4-py3-none-any.whl

Download URL py2ddoc-0.1.4-py3-none-any.whl
Size 28.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c41ee489bc7ead7a952c8459de5be9d1cc6c9f98c7d34519a3957f9659957368
BLAKE2b-256 checksum
How to use checksums
e1a5e2c2cedb9f3de1099ee3dbfd62d4e0440cb6f014547c5db8f21dce69b223
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Mar 20, 2026.

Transparency log

Security for py2ddoc 0.1.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for py2ddoc-0.1.4.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Mar 20, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Release history Release notifications | RSS feed

This release

0.1.4 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page