Skip to main content

Key Length Value encoding and decoding

Project description

Build Status

KLV in Python

A Python parser for KLV (Key Length Value) encoded data. KLV encoding is commonly used in the motion picture industry.

Unit Tests

Install nose:

pip install nose

Run the command nosetests in the root directory.

Encode Key/Value

import klv
key = [0x03, 0x2E, 0x5F, 0xAB, 0x08, 0x12, 0x2F, 0x0C,
       0xEE, 0x33, 0x00, 0x01, 0x02, 0x45, 0x6D, 0xDD]
value = [0x05, 0x04, 0x03, 0x02, 0x01]
klv_msg = klv.encode(key, value)

klv_msg will be a bytearray; to convert to an array of ints, use list(klv_msg) and to convert to a string of bytes, use str(klv_msg).

Decode KLV Messages

import klv
key, value = klv.decode(klv_msg, 16)

Decode takes the form decode(<klv>, <key length>) to accomodate messages with different length keys. The key and value results are bytearrays.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for klv, version 0.0.5
Filename, size File type Python version Upload date Hashes
Filename, size klv-0.0.5-py3-none-any.whl (3.7 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size klv-0.0.5.tar.gz (2.7 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page