Skip to main content

DCC utils for Python

Project description

Python library to decode the EU Covid-19 vaccine certificate, as specified by the EU.

Latest Version CI Coverage Supported Python versions License Downloads

Setup

pip install dcc-utils

Make sure zbar is installed in your system * For Mac OS X, it can be installed via brew install zbar * Debian systems via apt install libzbar0. Source * Fedora / Red Hat dnf install zbar

Usage

Parse DCC

This library takes an image with a QR code or a raw repr. of a vaccine certificate as the parameter and will show the certificate’s content.

from dcc_utils import dcc

dcc_from_img = dcc.from_image("/my/certificate/path")
dcc_from_raw = dcc.from_raw("HC1:6BF...FTPQ3C3F")

Then you can access to payload and kid

assert dcc_from_img.kid == "53FOjX/4aJs="
assert dcc_from_img.payload["v"][0]["ci"] == "URN:UVCI:01:FR:W7V2BE46QSBJ#L"

👉🏻 payload follows EU Digital COVID Certificates JSON Schema Specification

from_image and from_raw methods may rise DCCParsingError

from dcc_utils.exceptions import DCCParsingError

Validate DCC digital signature

signature = b"""
-----BEGIN CERTIFICATE-----
MIIIAjCCBeqgAwIBAgIQAnq8g/T
-----END CERTIFICATE-----
"""
assert my_dcc.check_signature(signature)

check_signature method may rise DCCSignatureError

from dcc_utils.exceptions import DCCSignatureError

Evaluate CertLogic business rules

With dcc-utils you can evaluate business rules against a DCC

from dcc_utils import rule, dcc

my_dcc = dcc.from_image("/my/certificate/path")
my_rule = rule.from_file("/my/rule.json")
print(my_rule.description["en"])
my_rule.evaluate_dcc(my_dcc) # True or False

evaluate_dcc accepts extra variables as a second parameter, e.g. validationClock

import datetime
clock = datetime.datetime(2022, 10, 10, 0, 0, tzinfo=datetime.timezone.utc)
my_rule.evaluate_dcc(
    my_dcc,
    {
        "validationClock": clock,
    },
)

you can also load rules from JSON (from_json), useful to evaluate rules exposed on a server

my_rule = rule.from_json({...})

from_file and from_json method may rise DCCRuleError

from dcc_utils.exceptions import DCCRuleError

Dev setup

Install dependencies using pip:

pip install -r requirements-dev.txt

Run tests

make test

EU Digital COVID Certificate Specifications

What’s in a EU Digital COVID/Green Certificate? * Value Sets for Digital Green Certificates https://ec.europa.eu/health/sites/default/files/ehealth/docs/digital-green-certificates_dt-specifications_en.pdf * JSON schema: https://github.com/ehn-dcc-development/ehn-dcc-schema

Sample data

Digital Green Certificate Gateway (DGCG) samples for all participating countries: https://github.com/eu-digital-green-certificates/dgc-testdata

Credits

Parts of this code are adapted from vacdec project.

License

This library is available under the MIT license.

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

dcc-utils-0.2.0.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

dcc_utils-0.2.0-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

Details for the file dcc-utils-0.2.0.tar.gz.

File metadata

  • Download URL: dcc-utils-0.2.0.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.8.2 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.6

File hashes

Hashes for dcc-utils-0.2.0.tar.gz
Algorithm Hash digest
SHA256 6f5cd0cd542d0a293de936f11d5bd7bdde0da94c6b955d67c3da0283d7de05a9
MD5 aa5bb0993dec6517bba09d83fb9d7bfe
BLAKE2b-256 c10df88f73ac1cce3b7f3912ff4bc88c19ff599d6aea51b99806877b9dda80cd

See more details on using hashes here.

File details

Details for the file dcc_utils-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: dcc_utils-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 6.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.8.2 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.6

File hashes

Hashes for dcc_utils-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bc2a094d75e784515f195c80421bc4ec889b9a61eac8162ae1f47eb164c3ac9b
MD5 82375d1cc910d7aaa39194f8073df6ad
BLAKE2b-256 ded239c06da3036c2a298cc7bd32ebdd68c432d1eecc859708f80391ca842421

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page