Skip to main content

TLV-for-Everyone

A small, Python-based BER-TLV (Tag-Length-Value) parser and encoder, designed for EMV and smartcard-style data structures.
It supports:

  • Parsing TLV streams into a tree structure
  • Constructed vs primitive tags
  • Long-form and short-form lengths
  • Nested TLVs inside constructed tags
  • Round-trip encode/decode
  • Case-insensitive tag lookup with simple path syntax (find("9F02"), find("A0/5F2A"))
  • Dummy-root wrapper (FF) for multiple top-level siblings

Installation

pip install tlv-for-everyone

Usage

from TlvParser.TlvParser import BerTlvParser, BerTlvElement

# Parse an EMV-like TLV string
data = "9F02060000000001009F1A0208405F2A020978"
parser = BerTlvParser()
tlv = parser.parse_tlv(data)

# Pretty-print as dict
print(tlv.get_as_dict())

# Find a tag
val = tlv.find("9F02").get_value_as_hex_str()
print("Amount:", val)

Creating TLVs

# Construct a TLV structure programmatically
parent = BerTlvElement(0xA0, {})
child1 = BerTlvElement(0x9A, bytes.fromhex("250826"))
child2 = BerTlvElement(0x5F2A, bytes.fromhex("0124"))
parent.add_child(child1)
parent.add_child(child2)

# Encode to bytes
encoded = parent.encode().hex().upper()
print("Encoded:", encoded)

Running Tests

This project uses pytest and hypothesis.

pip install -r requirements-dev.txt

Run all tests:

pytest -v

Development Roadmap

  • Improve XML/JSON exporters
  • Add support for indefinite-length encoding
  • More robust error handling and diagnostics
  • PyPI packaging

Contributing

Pull requests are welcome! For major changes, please open an issue first to discuss what you’d like to change.

License

MIT License. See LICENSE for details.

Metadata

Release files for tlv-for-everyone 0.1.0

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

Source distribution (sdist)

Source distribution for tlv-for-everyone 0.1.0
File Size Uploaded
tlv_for_everyone-0.1.0.tar.gz 8.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for tlv-for-everyone 0.1.0
File Interpreter ABI Platform
tlv_for_everyone-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 16.6 kB

Release files / tlv_for_everyone-0.1.0.tar.gz

Download URL tlv_for_everyone-0.1.0.tar.gz
Size 8.7 kB
Tags Source
SHA-256 checksum
How to use checksums
e87b56391cf618cbc5791bdaf704ca65d71cae50547df179debb128b99922f91
BLAKE2b-256 checksum
How to use checksums
9ce7edf3f99d71419d8b30653d7bebfd41ea0a69cf5aaa87b6dba29508884894
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

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 Aug 26, 2025.

Transparency log

Release files / tlv_for_everyone-0.1.0-py3-none-any.whl

Download URL tlv_for_everyone-0.1.0-py3-none-any.whl
Size 7.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b98c21c15d85701600a6122d6ff1e8358c858de699be29fa256fd2eb220a27c6
BLAKE2b-256 checksum
How to use checksums
ef4ff5369315cc428aef97339f1eeac593a1b8d9bb49a3266720f9aa68dd69fc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

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 Aug 26, 2025.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

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