line-protocol-parser

raw JSON →
2.0.0 verified Fri May 01 auth: no python

A fast C-based parser for InfluxDB line protocol, converting strings into Python dictionaries. Current version 2.0.0 (2025), requires Python >=3.10. Active development with regular releases.

pip install line-protocol-parser
error ValueError: Invalid line protocol: duplicate tag key 'location'
cause The input line contains the same tag key more than once.
fix
Remove duplicate tag keys from the line.
error ValueError: Invalid line protocol: unexpected trailing characters
cause Extra whitespace or characters after the timestamp or at end of line.
fix
Trim trailing whitespace or ensure line ends after valid timestamp.
error ValueError: Invalid line protocol: missing measurement name
cause Line is empty or starts with a comma or space.
fix
Ensure line starts with a valid measurement name.
error AttributeError: module 'line_protocol_parser' has no attribute 'parse_line'
cause Trying to import from a wrong package name (e.g., 'line_protocol_parser' vs 'line-protocol-parser').
fix
Install correct package: pip install line-protocol-parser
breaking In version 2.0.0, omitted timestamps now yield None for timestamp and has_time=False, instead of timestamp=0. Check code that assumed explicit 0 for missing timestamps.
fix Update logic that compares timestamp to 0; use has_time field to distinguish.
breaking Duplicate tags within a single line are now rejected as malformed. Previously, the last tag might silently override earlier ones.
fix Ensure no duplicate tag keys in input lines.
gotcha Parser is strict about key/value formatting: tag keys and field keys must not start with underscore, must be valid identifiers, etc. Invalid lines raise ValueError.
fix Sanitize line protocol strings before parsing.

Parse a single line protocol string.

from line_protocol_parser import parse_line

line = 'weather,location=us-midwest temperature=82 1465839830100400200'
result = parse_line(line)
print(result)
# {'measurement': 'weather', 'tags': {'location': 'us-midwest'}, 'fields': {'temperature': 82}, 'timestamp': 1465839830100400200, 'has_time': True}