Skip to main content

Leaf Point

Description

This module enables the creation of a LeafPoint object that can be transformed into either a JSON or LineProtocol format.

Features

InfluxDB Line Protocol Format

The InfluxDB Line Protocol is a text-based format designed for the efficient writing of time-series data into InfluxDB. It organizes the data points with timestamps, measurement names, fields (key-value pairs representing the data), and tags (optional key-value pairs used to store metadata that describes the data). The format is highly optimized for time-series data, enabling quick parsing and writing. A typical line in this format looks like this:

measurementName,tagKey=tagValue fieldKey="fieldValue" 1465839830100400200

  • measurementName: Identifies the measurement.
  • tagKey=tagValue: Zero or more tag sets separated by commas. Tags are optional but recommended for indexing.
  • fieldKey="fieldValue": At least one field set, with multiple fields separated by commas. Fields are the actual data points.
  • 1465839830100400200: An optional timestamp for the data point. If not specified, the server's current time is used.

JSON Format

The JSON format offers a more flexible way to represent data.

{
    "measurement": "measurement",
    "tags": {"tag1": "value1"},
    "fields": {"field1": 1, "field2": 2},
    "timestamp": 1609455600,
}

Usage

    from leafobject.leafpoint import LeafPoint

    leaf_point = LeafPoint()
    leaf_point.set_measurement("measurement")
    leaf_point.set_tags({"tag1": "value1"})
    leaf_point.set_fields({"field1": 1, "field2": 2})
    leaf_point.set_timestamp(datetime.datetime(2021, 1, 1))\
    
    print(leaf_point.to_json())

        # {
        #     "measurement": "measurement",
        #     "tags": {"tag1": "value1"},
        #     "fields": {"field1": 1, "field2": 2},
        #     "timestamp": 1609455600,
        # }
        
    print(leaf_point.to_line_protocol())

        # "measurement,tag1=value1 field1=1,field2=2 1609455600"

All functinoalities of the LeafPoint object are listed below:

    import leafobject
    x = leafobject.LeafPoint()
    x.
        x.add_field(..., ...)
        x.from_json(...)
        x.remove_field(...)
        x.set_measurement(...)
        x.to_line_protocol()
        x.add_tag(..., ...)
        x.remove_tag(...)
        x.set_tags(...)
        x.validate()
        x.parse_line_protocol(...)
        x.set_fields(...)
        x.set_timestamp(...)
        x.to_json()

Migrating from influxobject

influxobject is now leafobject and InfluxPoint is now LeafPoint. InfluxPoint still works as a deprecated alias:

    from leafobject import LeafPoint  # was: from influxobject.influxpoint import InfluxPoint

Installation

To install the package use the pip package manager

    pip install leafobject

Development

Tox is used as the test runner for this project. To run the entire tox suite use the following command:

    tox

To only run the tests under python 3.9

    tox -e py39

Build

    python setup.py sdist

Publish

    twine upload dist/*

Metadata

Release files for leafobject 0.0.13

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

Source distribution (sdist)

Source distribution for leafobject 0.0.13
File Size Uploaded
leafobject-0.0.13.tar.gz 6.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for leafobject 0.0.13
File Interpreter ABI Platform
leafobject-0.0.13-py3-none-any.whl Python 3 none any Details

Total release size: 14.8 kB

Release files / leafobject-0.0.13.tar.gz

Download URL leafobject-0.0.13.tar.gz
Size 6.8 kB
Tags Source
SHA-256 checksum
How to use checksums
68e3e355bb69962db70148a5e461902d107cb0d69659979540de25fed1b85cc1
BLAKE2b-256 checksum
How to use checksums
3e658b6594898b3c278d94e6b737e3af8087765b67a0c47fdbb22c1d33abfb3c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.5.1 CPython/3.12.15 Linux/5.15.154+

Release files / leafobject-0.0.13-py3-none-any.whl

Download URL leafobject-0.0.13-py3-none-any.whl
Size 8.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
aee7d494a8cb6031c13a1b9d5855088f553c64e63a4822a5a3c5cec00609bb1a
BLAKE2b-256 checksum
How to use checksums
edef55e6822cb6cfa58bea2420a222bdc6bff1f0f497b4d80719a644fedcc8be
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.5.1 CPython/3.12.15 Linux/5.15.154+

Release history Release notifications | RSS feed

This release

0.0.13 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