Skip to main content

Train ticket barcode to json decoding library, using zxing-cpp decoding in combination with record interpreter, to transform content into json structure

Project description

ticket_decoder

Optional arguments for instance creation of DecoderFacade.

  • uic_public_key_xml_file = "cert/UIC_PublicKeys.xml"
    Relative path to the XML file containing UIC public keys you can obtain here: https://railpublickey.uic.org/ .
  • vdv_certificate_ldif_file = "cert/VDV_Certificates.ldif"
    Relative path to the LDIF file containing VDV certificates to decrypt VDV barcode content.
  • fail_on_decoder_error = false
    Fail when the aztec/barcode decoder gets an error if true or deliver an empty result when false.
  • fail_on_interpreter_error = true
    Fail when the interpretation of the data gets an error if true or deliver an empty result when false.

Provided python API is in an early state and the class DecoderFacade supports 3 methods right now only.

  • decode_bytes('...')

  • decode_base64('...') is considered for the use case you decode the raw data from aztec-code in advance via zxing-cpp or other aztec-code-decoding library of your choice and you want to decode raw train ticket barcode data to json only. In this case, be careful with the output of the decoder to avoid string encodings like UTF8 or other multi-byte encodings. Ideally try to get access to the raw byte array and just encode those bytes to base64 before passing it to the method. If your aztec-code-decoder provides a string-type only and you are able to pass a character-encoding option, try using 'ISO 8859-1' and cast the result string to raw bytes.

  • decode_files('...') detects and decodes aztec-codes from file or directories (PDF, image) and decodes barcode data to json. This is using zxing-cpp internally. It returns an array of tuples (input-path and json-result) of size x, while x is the amount of aztec-codes found on input. An image can contain always multiple barcodes, the the return value is alway a mapping of origin to content.

Example decoding directly from PDF or image

from ticket_decoder import DecoderFacade

decoder_facade = DecoderFacade(fail_on_interpreter_error = False)
for result in decoder_facade.decode_files('path/2/your/ticket.pdf'):
   print(result[1])

Decoding Aztec-Code in advance using zxingcpp on Python side

from ticket_decoder import DecoderFacade
from zxingcpp import read_barcodes
from cv2 import imread

image = imread('path/2/your/ticket.jpg')

barcodes = read_barcodes(image)
if not barcodes:
    print("No barcodes found")
    exit(1)

decoder_facade = DecoderFacade(\
    fail_on_interpreter_error = False,\
    uic_public_key_xml_file = "cert/UIC_PublicKeys.xml",\
    vdv_certificate_ldif_file = "cert/VDV_Certificates.ldif")

print(decoder_facade.decode_bytes(barcodes[0].bytes))

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

ticket_decoder-0.19.tar.gz (1.7 MB view details)

Uploaded Source

Built Distributions

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

ticket_decoder-0.19-cp314-cp314-manylinux_2_34_x86_64.whl (10.7 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.34+ x86-64

ticket_decoder-0.19-cp314-cp314-manylinux_2_34_aarch64.whl (9.6 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.34+ ARM64

ticket_decoder-0.19-cp314-cp314-macosx_11_0_arm64.whl (7.3 MB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

ticket_decoder-0.19-cp313-cp313-manylinux_2_34_x86_64.whl (10.7 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ x86-64

ticket_decoder-0.19-cp313-cp313-manylinux_2_34_aarch64.whl (9.6 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ ARM64

ticket_decoder-0.19-cp313-cp313-macosx_11_0_arm64.whl (7.3 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

File details

Details for the file ticket_decoder-0.19.tar.gz.

File metadata

  • Download URL: ticket_decoder-0.19.tar.gz
  • Upload date:
  • Size: 1.7 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for ticket_decoder-0.19.tar.gz
Algorithm Hash digest
SHA256 09e9a48801bdec8fafeabb195018a180a412038c79a05916e0986cdbbe5fdfcf
MD5 22bc3cb665a03cbc34a2b3f3a987544b
BLAKE2b-256 a2bc83cfcbe839760cf45072e9835ad526fe605c3bff9eb4877164cc61d306e8

See more details on using hashes here.

Provenance

The following attestation bundles were made for ticket_decoder-0.19.tar.gz:

Publisher: pypi.yml on user4223/ticket-decoder

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

File details

Details for the file ticket_decoder-0.19-cp314-cp314-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for ticket_decoder-0.19-cp314-cp314-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 d8a0bd5c33f64ea31235ad7edee281049658eb778d6cbbeabedc5c3dc67d6580
MD5 c57711a0dcc0da73833c06eaa060f94b
BLAKE2b-256 1a0dbbde02f0dee8c85d5a796ffcac08f9c90685fcd3e695c10c3b2469284457

See more details on using hashes here.

Provenance

The following attestation bundles were made for ticket_decoder-0.19-cp314-cp314-manylinux_2_34_x86_64.whl:

Publisher: pypi.yml on user4223/ticket-decoder

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

File details

Details for the file ticket_decoder-0.19-cp314-cp314-manylinux_2_34_aarch64.whl.

File metadata

File hashes

Hashes for ticket_decoder-0.19-cp314-cp314-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 af49565b7c23cfca096bbe11e0fa25b4a648230f5af0d1efbb3a5a9a1b1ce822
MD5 1464cc89a53fc36cf3eed9d2ac9c7945
BLAKE2b-256 2c24951bbebf49feb144088fb3c4559920d4e69a7c2ffb887fdcd7b265964adc

See more details on using hashes here.

Provenance

The following attestation bundles were made for ticket_decoder-0.19-cp314-cp314-manylinux_2_34_aarch64.whl:

Publisher: pypi.yml on user4223/ticket-decoder

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

File details

Details for the file ticket_decoder-0.19-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for ticket_decoder-0.19-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9952b22e0c351d137a817c8b70f7eb2ceee537970d71aeed495b71db6399ff1b
MD5 09da868772af2efa5a5d8214a4038b3b
BLAKE2b-256 e6857d881b5b48c8e215287f7e68d51d2854ec73a1921ac16551806572ae824e

See more details on using hashes here.

Provenance

The following attestation bundles were made for ticket_decoder-0.19-cp314-cp314-macosx_11_0_arm64.whl:

Publisher: pypi.yml on user4223/ticket-decoder

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

File details

Details for the file ticket_decoder-0.19-cp313-cp313-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for ticket_decoder-0.19-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 91cf5d559c0cc331f94384ac35d49f84988b2d832cada95cc5b9bdbff43b08bc
MD5 0d6a28935518960e89ea25f2709fdb01
BLAKE2b-256 2623b104092f852883043fc6eb7deccd16f4b3aeba1a5f7cb83e3d314d5ec638

See more details on using hashes here.

Provenance

The following attestation bundles were made for ticket_decoder-0.19-cp313-cp313-manylinux_2_34_x86_64.whl:

Publisher: pypi.yml on user4223/ticket-decoder

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

File details

Details for the file ticket_decoder-0.19-cp313-cp313-manylinux_2_34_aarch64.whl.

File metadata

File hashes

Hashes for ticket_decoder-0.19-cp313-cp313-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 c577b41db85f57de8afccdf90c9626aa040bd3228a5d311616577293f0e4a1a7
MD5 f062a5395f267af6dd07778e87bb2ee7
BLAKE2b-256 f06723006269f1963c498116d8d15555b21867f3da345d5d903383bd3cd6da8c

See more details on using hashes here.

Provenance

The following attestation bundles were made for ticket_decoder-0.19-cp313-cp313-manylinux_2_34_aarch64.whl:

Publisher: pypi.yml on user4223/ticket-decoder

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

File details

Details for the file ticket_decoder-0.19-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for ticket_decoder-0.19-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4368a1cf4d22fb69360ab3d7e67b0a00b4febf368890787169a3829be848d5f6
MD5 8161398e8073d6472230a8031567da78
BLAKE2b-256 55dddd8552189f9686119e0a5d20c5088690823cca18783cd3fb15a8c819279b

See more details on using hashes here.

Provenance

The following attestation bundles were made for ticket_decoder-0.19-cp313-cp313-macosx_11_0_arm64.whl:

Publisher: pypi.yml on user4223/ticket-decoder

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