line-protocol-parser 2.0.1__cp315-cp315-win_amd64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- line_protocol_parser/__init__.py +12 -0
- line_protocol_parser/_line_protocol_parser.cp315-win_amd64.pyd +0 -0
- line_protocol_parser-2.0.1.dist-info/METADATA +267 -0
- line_protocol_parser-2.0.1.dist-info/RECORD +7 -0
- line_protocol_parser-2.0.1.dist-info/WHEEL +5 -0
- line_protocol_parser-2.0.1.dist-info/licenses/LICENSE.md +21 -0
- line_protocol_parser-2.0.1.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"""Parse InfluxDB line protocol strings into dictionaries or ``None``."""
|
|
2
|
+
from ._line_protocol_parser import parse_line, LineFormatError
|
|
3
|
+
|
|
4
|
+
# Module metadata
|
|
5
|
+
__author__ = 'Daniel Andersson'
|
|
6
|
+
__maintainer__ = __author__
|
|
7
|
+
__email__ = 'daniel.4ndersson@gmail.com'
|
|
8
|
+
__contact__ = __email__
|
|
9
|
+
__copyright__ = 'Copyright (c) 2019 Daniel Andersson'
|
|
10
|
+
__license__ = 'MIT'
|
|
11
|
+
__url__ = "https://github.com/Penlect/line-protocol-parser"
|
|
12
|
+
__version__ = '2.0.1'
|
|
Binary file
|
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: line-protocol-parser
|
|
3
|
+
Version: 2.0.1
|
|
4
|
+
Summary: Parse InfluxDB line protocol string into Python dictionary
|
|
5
|
+
Home-page: https://github.com/Penlect/line-protocol-parser
|
|
6
|
+
Author: Daniel Andersson
|
|
7
|
+
Author-email: daniel.4ndersson@gmail.com
|
|
8
|
+
License: MIT
|
|
9
|
+
Keywords: InfluxDB influx line protocol parser reader
|
|
10
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
11
|
+
Classifier: Environment :: Console
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Intended Audience :: Education
|
|
14
|
+
Classifier: Intended Audience :: Science/Research
|
|
15
|
+
Classifier: Topic :: Software Development :: Version Control :: Git
|
|
16
|
+
Classifier: Natural Language :: English
|
|
17
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
18
|
+
Classifier: Operating System :: MacOS
|
|
19
|
+
Classifier: Operating System :: Microsoft :: Windows :: Windows 10
|
|
20
|
+
Classifier: Programming Language :: C
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
24
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
25
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
26
|
+
Classifier: Programming Language :: Python :: 3.15
|
|
27
|
+
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
28
|
+
Requires-Python: >=3.10
|
|
29
|
+
License-File: LICENSE.md
|
|
30
|
+
Dynamic: author
|
|
31
|
+
Dynamic: author-email
|
|
32
|
+
Dynamic: classifier
|
|
33
|
+
Dynamic: description
|
|
34
|
+
Dynamic: home-page
|
|
35
|
+
Dynamic: keywords
|
|
36
|
+
Dynamic: license
|
|
37
|
+
Dynamic: license-file
|
|
38
|
+
Dynamic: requires-python
|
|
39
|
+
Dynamic: summary
|
|
40
|
+
|
|
41
|
+
Welcome to InfluxDB line-protocol-parser
|
|
42
|
+
========================================
|
|
43
|
+
|
|
44
|
+
Parse InfluxDB `line protocol`_ strings into Python dictionaries.
|
|
45
|
+
|
|
46
|
+
Example:
|
|
47
|
+
^^^^^^^^
|
|
48
|
+
|
|
49
|
+
.. code-block:: python
|
|
50
|
+
|
|
51
|
+
>>> from line_protocol_parser import parse_line
|
|
52
|
+
>>> data = parse_line('myMeas,someTag=ABC field1=3.14,field2="Hello, World!" 123')
|
|
53
|
+
>>> print(data)
|
|
54
|
+
{'measurement': 'myMeas',
|
|
55
|
+
'fields': {'field1': 3.14, 'field2': 'Hello, World!'},
|
|
56
|
+
'tags': {'someTag': 'ABC'},
|
|
57
|
+
'time': 123}
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
**The InfluxDB line protocol is a text based format for writing points to InfluxDB.
|
|
61
|
+
This project can read this format and convert line strings to Python dicitonaries.**
|
|
62
|
+
|
|
63
|
+
The line protocol has the following format:
|
|
64
|
+
|
|
65
|
+
<measurement>[,<tag_key>=<tag_value>[,<tag_key>=<tag_value>]] <field_key>=<field_value>[,<field_key>=<field_value>] [<timestamp>]
|
|
66
|
+
|
|
67
|
+
and is documented here: `InfluxDB line protocol`_.
|
|
68
|
+
|
|
69
|
+
This parser is aligned with archived InfluxDB v1.2 single-line parser
|
|
70
|
+
semantics for standard text inputs. When an input point omits the timestamp,
|
|
71
|
+
``parse_line()`` returns ``None`` for ``time`` so omission remains distinct
|
|
72
|
+
from an explicit ``0`` timestamp. Leading ``#`` comment lines, including
|
|
73
|
+
lines with leading whitespace before ``#``, are treated as valid input and
|
|
74
|
+
``parse_line()`` returns ``None`` for those lines as well. The parser also
|
|
75
|
+
accepts the same top-level whitespace skipping before measurements, fields,
|
|
76
|
+
and timestamps that the archived v1.2 parser tolerated, along with trailing
|
|
77
|
+
spaces after the optional timestamp. The combined measurement/tag key is
|
|
78
|
+
limited to 65535 bytes, matching the archived parser limit.
|
|
79
|
+
Unsigned ``123u`` field values are retained as a package extension even though
|
|
80
|
+
they are not documented in the archived v1.2 reference.
|
|
81
|
+
|
|
82
|
+
The ``line_protocol_parser`` module only contains the ``parse_line`` function and the ``LineFormatError`` exception which is raised on failure.
|
|
83
|
+
|
|
84
|
+
Installation
|
|
85
|
+
^^^^^^^^^^^^
|
|
86
|
+
Python 3.10 or newer is required.
|
|
87
|
+
|
|
88
|
+
From PyPI:
|
|
89
|
+
|
|
90
|
+
.. code-block:: bash
|
|
91
|
+
|
|
92
|
+
$ python3 -m pip install line-protocol-parser
|
|
93
|
+
|
|
94
|
+
or from source (make sure you have ``python3 -m pip install wheel setuptools`` first):
|
|
95
|
+
|
|
96
|
+
.. code-block:: bash
|
|
97
|
+
|
|
98
|
+
$ git clone https://github.com/Penlect/line-protocol-parser.git
|
|
99
|
+
$ cd line-protocol-parser
|
|
100
|
+
$ python3 setup.py bdist_wheel
|
|
101
|
+
$ python3 -m pip install ./dist/line-protocol-parser-*.whl
|
|
102
|
+
|
|
103
|
+
or from generated Debian package:
|
|
104
|
+
|
|
105
|
+
.. code-block:: bash
|
|
106
|
+
|
|
107
|
+
# Install build dependencies
|
|
108
|
+
$ sudo apt install python3-all python3-all-dev python3-setuptools dh-python
|
|
109
|
+
$ git clone https://github.com/Penlect/line-protocol-parser.git
|
|
110
|
+
$ cd line-protocol-parser
|
|
111
|
+
$ make deb
|
|
112
|
+
$ sudo apt install ./python3-line-protocol-parser_*.deb
|
|
113
|
+
|
|
114
|
+
Use Case 1: Read points from a file
|
|
115
|
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
116
|
+
Suppose you have a text file with influxDB measurement points, "my_influxDB_points.txt"::
|
|
117
|
+
|
|
118
|
+
# generated by sensor gateway
|
|
119
|
+
myMeasurement,someTag=A temperature=37.0 1570977942581909918
|
|
120
|
+
myMeasurement,someTag=A temperature=37.3 1570977942581910000
|
|
121
|
+
myMeasurement,someTag=A temperature=36.9 1570977942581912345
|
|
122
|
+
myMeasurement,someTag=A temperature=37.1 1570977942581923399
|
|
123
|
+
...
|
|
124
|
+
|
|
125
|
+
Then you can load each line into a dicitonary to be printed like this:
|
|
126
|
+
|
|
127
|
+
.. code-block:: python3
|
|
128
|
+
|
|
129
|
+
>>> from line_protocol_parser import parse_line
|
|
130
|
+
>>> with open('my_influxDB_points.txt', 'r') as f_obj:
|
|
131
|
+
... for line in f_obj:
|
|
132
|
+
... point = parse_line(line)
|
|
133
|
+
... if point is not None:
|
|
134
|
+
... print(point)
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
Use Case 2: InfluxDB subscriptions
|
|
138
|
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
139
|
+
InfluxDB subscriptions are documented here: `InfluxDB Subscriptions`_.
|
|
140
|
+
|
|
141
|
+
InfluxDB subscriptions are local or remote endpoints to which all data written to InfluxDB is copied. Endpoint able to accept UDP, HTTP, or HTTPS connections can subscribe to InfluxDB and receive a copy of all data as it is written.
|
|
142
|
+
|
|
143
|
+
In this example we will do the following:
|
|
144
|
+
|
|
145
|
+
1) Setup and run a InfluxDB container.
|
|
146
|
+
2) Create a subscription.
|
|
147
|
+
3) Create a Python server and register it as an endpoint.
|
|
148
|
+
4) Use ``line_protocol_parser`` to read and print incoming data.
|
|
149
|
+
|
|
150
|
+
**Step 1**. Run the following commands to run a `InfluxDB container`_ and attach to the influx client.
|
|
151
|
+
|
|
152
|
+
.. code-block:: bash
|
|
153
|
+
|
|
154
|
+
$ docker run -d --network="host" --name inf influxdb
|
|
155
|
+
$ docker exec -it inf influx
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
**Step 2**. Create subscription. Run these commands in the influx client prompt.
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
.. code-block:: bash
|
|
162
|
+
|
|
163
|
+
> CREATE DATABASE mydb
|
|
164
|
+
> USE mydb
|
|
165
|
+
> CREATE SUBSCRIPTION "mysub" ON "mydb"."autogen" DESTINATIONS ALL 'http://localhost:9090'
|
|
166
|
+
|
|
167
|
+
Since we used `--network="host"` we can use localhost from inside the container.
|
|
168
|
+
|
|
169
|
+
**Step 3 & 4**. Python server to receive InfluxDB data.
|
|
170
|
+
|
|
171
|
+
Create a python file *server.py* with the following content:
|
|
172
|
+
|
|
173
|
+
.. code-block:: python
|
|
174
|
+
|
|
175
|
+
from pprint import pprint
|
|
176
|
+
from http.server import HTTPServer, BaseHTTPRequestHandler
|
|
177
|
+
from line_protocol_parser import parse_line
|
|
178
|
+
|
|
179
|
+
class PostHandler(BaseHTTPRequestHandler):
|
|
180
|
+
|
|
181
|
+
def do_POST(self):
|
|
182
|
+
content_length = int(self.headers['Content-Length'])
|
|
183
|
+
post_data = self.rfile.read(content_length)
|
|
184
|
+
point = parse_line(post_data)
|
|
185
|
+
if point is not None:
|
|
186
|
+
pprint(point)
|
|
187
|
+
self.send_response(200)
|
|
188
|
+
self.end_headers()
|
|
189
|
+
|
|
190
|
+
if __name__ == '__main__':
|
|
191
|
+
server = HTTPServer(('localhost', 9090), PostHandler)
|
|
192
|
+
print('Starting server, use <Ctrl-C> to stop')
|
|
193
|
+
server.serve_forever()
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
Start the server:
|
|
197
|
+
|
|
198
|
+
.. code-block:: bash
|
|
199
|
+
|
|
200
|
+
$ python3 server.py
|
|
201
|
+
Starting server, use <Ctrl-C> to stop
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
Next, go back to your influx client and insert a data point:
|
|
205
|
+
|
|
206
|
+
.. code-block:: bash
|
|
207
|
+
|
|
208
|
+
> INSERT oven,room=kitchen temperature=225.0 1234567890
|
|
209
|
+
|
|
210
|
+
Head back to your Python server and watch the output:
|
|
211
|
+
|
|
212
|
+
.. code-block:: bash
|
|
213
|
+
|
|
214
|
+
$ python3 server.py
|
|
215
|
+
Starting server, use <Ctrl-C> to stop
|
|
216
|
+
{'fields': {'temperature': 225.0},
|
|
217
|
+
'measurement': 'oven',
|
|
218
|
+
'tags': {'room': 'kitchen'},
|
|
219
|
+
'time': 1234567890}
|
|
220
|
+
172.17.0.2 - - [14/Oct/2019 21:02:57] "POST /write?consistency=&db=mydb&precision=ns&rp=autogen HTTP/1.1" 200 -
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
Pure C usage
|
|
224
|
+
^^^^^^^^^^^^
|
|
225
|
+
If you are not interested in the Python wrapper you may find the pure-c files useful:
|
|
226
|
+
|
|
227
|
+
* ``include/line_protocol_parser.h``
|
|
228
|
+
* ``src/line_protocol_parser.c``
|
|
229
|
+
|
|
230
|
+
The C API keeps the original point-or-error contract. If you want to skip
|
|
231
|
+
leading ``#`` comment lines in C code, filter those lines before calling
|
|
232
|
+
``LP_parse_line()``. The C API accepts NUL-terminated strings only, while the
|
|
233
|
+
Python wrapper rejects embedded NUL bytes instead of silently truncating
|
|
234
|
+
input.
|
|
235
|
+
|
|
236
|
+
Example:
|
|
237
|
+
|
|
238
|
+
.. code-block:: c
|
|
239
|
+
|
|
240
|
+
int main()
|
|
241
|
+
{
|
|
242
|
+
const char *line = "measurement,tag=value field=\"Hello, world!\" 1570283407262541159";
|
|
243
|
+
struct LP_Point *point;
|
|
244
|
+
int status = 0;
|
|
245
|
+
point = LP_parse_line(line, &status);
|
|
246
|
+
if (point == NULL) {
|
|
247
|
+
LP_DEBUG_PRINT("ERROR STATUS: %d\n", status);
|
|
248
|
+
}
|
|
249
|
+
// < Do something useful with point here >
|
|
250
|
+
LP_free_point(point);
|
|
251
|
+
return status;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
Please see the comments in the source and header file for more information.
|
|
255
|
+
|
|
256
|
+
Examples from the Test Cases
|
|
257
|
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
258
|
+
The test cases are a good source of examples. Please see: `tests/test_parse_line.py <tests/test_parse_line.py>`_.
|
|
259
|
+
|
|
260
|
+
Changelog
|
|
261
|
+
^^^^^^^^^
|
|
262
|
+
The changelog is maintained in the debian directory, please check there: `changelog <debian/changelog>`_.
|
|
263
|
+
|
|
264
|
+
.. _line protocol: https://archive.docs.influxdata.com/influxdb/v1.2/write_protocols/line_protocol_reference/
|
|
265
|
+
.. _InfluxDB line protocol: https://archive.docs.influxdata.com/influxdb/v1.2/write_protocols/line_protocol_reference/
|
|
266
|
+
.. _InfluxDB Subscriptions: https://docs.influxdata.com/influxdb/latest/administration/subscription-management/
|
|
267
|
+
.. _InfluxDB container: https://hub.docker.com/_/influxdb
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
line_protocol_parser/__init__.py,sha256=HQ_2BwTkCwEMljdLVobCaJXNlQWMT_fYOt3hYD0IW8Q,449
|
|
2
|
+
line_protocol_parser/_line_protocol_parser.cp315-win_amd64.pyd,sha256=78oyexPTIGM5S2GYVK1LsG8pEb5dtYxaoVTYL5LYCwE,19968
|
|
3
|
+
line_protocol_parser-2.0.1.dist-info/licenses/LICENSE.md,sha256=ZwCi4PL_jfr7S29_rsDtkAwdETi41TFwhpTDCPuFm0M,1094
|
|
4
|
+
line_protocol_parser-2.0.1.dist-info/METADATA,sha256=NbyLMhUU85tg3gIk7YQxwQ0R7gJNZgc45fyv18Zk0_g,9599
|
|
5
|
+
line_protocol_parser-2.0.1.dist-info/WHEEL,sha256=geuJoH1aW6kS7q0cKuoOBUdE-tpBsTvRf9l5rOGbxQs,101
|
|
6
|
+
line_protocol_parser-2.0.1.dist-info/top_level.txt,sha256=C4XTC2uwMUV0R7rzgFVrjtetkEg2YK8vOeK5C7OuBoQ,21
|
|
7
|
+
line_protocol_parser-2.0.1.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2019 Daniel Andersson
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
line_protocol_parser
|