Python BER-TLV parser/encoder for EMV & smartcard data
Project description
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tlv_for_everyone-0.1.0.tar.gz.
File metadata
- Download URL: tlv_for_everyone-0.1.0.tar.gz
- Upload date:
- Size: 8.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e87b56391cf618cbc5791bdaf704ca65d71cae50547df179debb128b99922f91
|
|
| MD5 |
06f84d4c5638914dca157e7875a133f5
|
|
| BLAKE2b-256 |
9ce7edf3f99d71419d8b30653d7bebfd41ea0a69cf5aaa87b6dba29508884894
|
Provenance
The following attestation bundles were made for tlv_for_everyone-0.1.0.tar.gz:
Publisher:
publish.yml on vitalij555/tlv-for-everyone
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tlv_for_everyone-0.1.0.tar.gz -
Subject digest:
e87b56391cf618cbc5791bdaf704ca65d71cae50547df179debb128b99922f91 - Sigstore transparency entry: 435789786
- Sigstore integration time:
-
Permalink:
vitalij555/tlv-for-everyone@21a70b6faa005eb9fc262b23ee689c3da4015827 -
Branch / Tag:
refs/heads/master - Owner: https://github.com/vitalij555
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@21a70b6faa005eb9fc262b23ee689c3da4015827 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file tlv_for_everyone-0.1.0-py3-none-any.whl.
File metadata
- Download URL: tlv_for_everyone-0.1.0-py3-none-any.whl
- Upload date:
- Size: 7.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b98c21c15d85701600a6122d6ff1e8358c858de699be29fa256fd2eb220a27c6
|
|
| MD5 |
01ce58cd3868c5d6a29b071b430f0cc2
|
|
| BLAKE2b-256 |
ef4ff5369315cc428aef97339f1eeac593a1b8d9bb49a3266720f9aa68dd69fc
|
Provenance
The following attestation bundles were made for tlv_for_everyone-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on vitalij555/tlv-for-everyone
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tlv_for_everyone-0.1.0-py3-none-any.whl -
Subject digest:
b98c21c15d85701600a6122d6ff1e8358c858de699be29fa256fd2eb220a27c6 - Sigstore transparency entry: 435789804
- Sigstore integration time:
-
Permalink:
vitalij555/tlv-for-everyone@21a70b6faa005eb9fc262b23ee689c3da4015827 -
Branch / Tag:
refs/heads/master - Owner: https://github.com/vitalij555
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@21a70b6faa005eb9fc262b23ee689c3da4015827 -
Trigger Event:
workflow_dispatch
-
Statement type: