A reusable parser for Lightning Network gossip messages format.
Project description
โก lnhistoryclient
A Python client library to parse and handle raw Lightning Network gossip messages from the gossip store. Centralized, reusable, and production-tested on real-world data. Perfect for microservices that consume Lightning Network data in raw_hex format.
For details about the gossip messages see the Lightning Network specifications BOLT #7
This python package is part of the ln-history project
๐ฆ Features
- ๐ Parses raw gossip messages:
ChannelAnnouncement,NodeAnnouncement,ChannelUpdate, and more - ๐งฑ Clean and extensible object model (e.g.,
ChannelAnnouncement,NodeAnnouncement,ChannelUpdate) - ๐งช Tested on real-world data
- ๐งฐ Built with reusability in mind for microservice architectures
๐ ๏ธ Installation
pip install lnhistoryclient
๐งฌ Usage
To parse a raw Lightning Network gossip message, first extract the message type, then use the type to select the appropriate parser. This ensures correctness and avoids interpreting invalid data. The library accepts both bytes and io.BytesIO objects as input for maximum flexibility.
from lnhistoryclient.parser.common import get_message_type
from lnhistoryclient.parser.parser_factory import get_parser_by_message_type
raw_hex = bytes.fromhex("0101...") # Replace with actual raw hex (includes 2-byte type prefix)
msg_type = get_message_type_by_raw_hex(raw_hex)
if msg_type is not None:
parser = get_parser_by_message_type(msg_type)
result = parser(raw_hex[2:]) # Strip the type prefix if your parser expects it
print(result)
else:
print("Unknown or unsupported message type.")
For convenience (and if you're confident the input is valid), a shortcut is also available:
from lnhistoryclient.parser.parser_factory import get_parser_from_raw_hex
raw_hex = bytes.fromhex("0101...") # Replace with actual raw hex
parser = get_parser_from_raw_hex(raw_hex)
if parser:
result = parser(raw_hex[2:])
print(result)
else:
print("Could not determine parser.")
You can also directly use individual parsers if you know the message type:
from lnhistoryclient.parser.channel_announcement_parser import parse_channel_announcement
result = parse_channel_announcement(raw_hex)
print(result.channel_id, result.node1_id, result.node2_id)
๐จ Model
The library provides python typing models for every gossip message. See in the project structure section below for details.
๐ Project Structure
lnhistoryclient
โโโ LICENSE
โโโ lnhistoryclient
โ โโโ constants.py
โ โโโ model
โ โ โโโ __init__.py
โ โ โโโ Address.py
โ โ โโโ AddressType.py
โ โ โโโ cache
โ โ โ โโโ GossipCache.py
โ โ โโโ ChannelAnnouncement.py
โ โ โโโ ChannelUpdate.py
โ โ โโโ core_lightning_internal
โ โ โ โโโ __init__.py
โ โ โ โโโ ChannelAmount.py
โ โ โ โโโ ChannelDying.py
โ โ โ โโโ DeleteChannel.py
โ โ โ โโโ GossipStoreEnded.py
โ โ โ โโโ PrivateChannelAnnouncement.py
โ โ โ โโโ PrivateChannelUpdate.py
โ โ โ โโโ types.py
โ โ โโโ gossip_event_kafka
โ โ โ โโโ __init__.py
โ โ โ โโโ GossipEvent.py
โ โ โโโ gossip_event_zmq
โ โ โ โโโ __init__.py
โ โ โ โโโ ChannelAnnouncementEvent.py
โ โ โ โโโ ChannelUpdateEvent.py
โ โ โ โโโ core_lightning_internal
โ โ โ โ โโโ __init__.py
โ โ โ โ โโโ ChannelAmountEvent.py
โ โ โ โ โโโ ChannelDyingEvent.py
โ โ โ โ โโโ DeleteChannelEvent.py
โ โ โ โ โโโ GossipStoreEndedEvent.py
โ โ โ โ โโโ PrivateChannelAnnouncementEvent.py
โ โ โ โ โโโ PrivateChannelUpdateEvent.py
โ โ โ โโโ NodeAnnouncementEvent.py
โ โ โโโ MessageMetadata.py
โ โ โโโ NodeAnnouncement.py
โ โ โโโ types.py
โ โโโ parser
โ โโโ __init__.py
โ โโโ channel_announcement_parser.py
โ โโโ channel_update_parser.py
โ โโโ common.py
โ โโโ core_lightning_internal
โ โ โโโ __init__.py
โ โ โโโ channel_amount_parser.py
โ โ โโโ channel_dying_parser.py
โ โ โโโ delete_channel_parser.py
โ โ โโโ gossip_store_ended_parser.py
โ โ โโโ private_channel_announcement_parser.py
โ โ โโโ private_channel_update_parser.py
โ โโโ node_announcement_parser.py
โ โโโ parser_factory.py
โโโ pyproject.toml
โโโ README.md
โโโ requirements-dev.txt
โโโ tests
๐งช Testing
Unit tests coming soon.
๐ง Requirements
Python >=3.7, <4.0 Pure Python, no external dependencies
Code Style, Linting etc.
The code has been formatted using ruff, black and mypy
๐ค Contributing
Pull requests, issues, and feature ideas are always welcome! Fork the repo Create a new branch Submit a PR with a clear description
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 lnhistoryclient-3.3.0.tar.gz.
File metadata
- Download URL: lnhistoryclient-3.3.0.tar.gz
- Upload date:
- Size: 21.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e751dbc2cf8122104d9bf1c2469c7a4d2b12fdc7a6c431c63fbae7abdd630ca9
|
|
| MD5 |
a436faae8f4513011f5380d0946d6110
|
|
| BLAKE2b-256 |
417d397c66822fa15dd8fe17413df35456a172dd00fe633f7319d132320c558d
|
Provenance
The following attestation bundles were made for lnhistoryclient-3.3.0.tar.gz:
Publisher:
release.yml on ln-history/ln-history-python-client
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
lnhistoryclient-3.3.0.tar.gz -
Subject digest:
e751dbc2cf8122104d9bf1c2469c7a4d2b12fdc7a6c431c63fbae7abdd630ca9 - Sigstore transparency entry: 270089393
- Sigstore integration time:
-
Permalink:
ln-history/ln-history-python-client@a756a7dcc8439bea85f50dabc7b6fb8f661a9c1e -
Branch / Tag:
refs/heads/main - Owner: https://github.com/ln-history
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@a756a7dcc8439bea85f50dabc7b6fb8f661a9c1e -
Trigger Event:
push
-
Statement type:
File details
Details for the file lnhistoryclient-3.3.0-py3-none-any.whl.
File metadata
- Download URL: lnhistoryclient-3.3.0-py3-none-any.whl
- Upload date:
- Size: 28.3 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 |
3683fe358cfd774ddb6828513c4a1ab4aa53180df45f40031936135fc7a480b8
|
|
| MD5 |
4ecf0a42e67f35e683d645ae495babdd
|
|
| BLAKE2b-256 |
f5bccdbb7f1e5ab6b7c641445978af4d861b769877d0cc73edbcce456633ad78
|
Provenance
The following attestation bundles were made for lnhistoryclient-3.3.0-py3-none-any.whl:
Publisher:
release.yml on ln-history/ln-history-python-client
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
lnhistoryclient-3.3.0-py3-none-any.whl -
Subject digest:
3683fe358cfd774ddb6828513c4a1ab4aa53180df45f40031936135fc7a480b8 - Sigstore transparency entry: 270089403
- Sigstore integration time:
-
Permalink:
ln-history/ln-history-python-client@a756a7dcc8439bea85f50dabc7b6fb8f661a9c1e -
Branch / Tag:
refs/heads/main - Owner: https://github.com/ln-history
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@a756a7dcc8439bea85f50dabc7b6fb8f661a9c1e -
Trigger Event:
push
-
Statement type: