Skip to main content

simpleinflux - A simple frontend for InfluxDB

Project description

simpleinflux

A simple Python frontend for InfluxDB

Installation

pip install simpleinflux

simpleinflux only requires time, datetime, socket, and requests, so this should work on most systems.

Quickstart

simpleinflux does not use a stateful connection object, only stateless functions which execute the underlying http requests and parse the results into a sane representation. The functions

import simpleinflux

# host = 'localhost' and port = 8086 are assumed, read below to change:
simpleinflux.ping()
# -> True (or False)

simpleinflux.create_database('testDB')

simpleinflux.get_databases()
# -> ['_internal', 'testDB']

simpleinflux.write(db='testDB', measurement='test', timestamp=time.time(),  {'temperature_C': 21.2})
# -> True (or False)
simpleinflux.get_measurements(db='testDB')
# -> ['test']
simpleinflux.read_latest(db='testDB', measurement='test')
# -> {'time': 1654500223, 'temperature_C':21.2}

# Set default database and measurement on package level:
simpleinflux.default_db = 'testDB'
simpleinflux.default_measurement = 'test'

simpleinflux.write(timestamp=time.time(),  {'temperature_C': 21.3})
simpleinflux.read_latest()
# -> {'time': 1654500223, 'temperature_C':21.2}

Changing host and port

simpleinflux assumes host = 'localhost' and port = 8086, which can be changed with optional arguments in most functions, e.g.

ping_ok = simpleinflux.ping(host='localhost', port=28086)
data = simpleinflux.read_latest(measurement='test', host='localhost', port=28086)

or on the package level, e.g.

simpleinflux.default_host = 'db.mydomain.com'
simpleinflux.default_port = 28086
data = simpleinflux.read_latest(measurement='test')

Timestamps

All timestamps in InfluxDB are integers with explicit precision. simpleinflux uses second-precision as standard for both writes and reads. Other precisions can be set with the precision parameter in the write-function and the output_time_unit parameter in the various read_-functions.
InfluxDB recommends using the broadest precision timestamp you and your data can get away with for optimal compression.

Function Reference

ping(raise_on_error=True, host='localhost', port=8086)
returns ping_ok [Bool]
Checks the connection to the port, and to the InfluxDB-API and returns True when successful. Does not check the connection to only the host, because supporting ping on multiple platforms seems kind of messy.

  • raise_on_error [Bool], default: True
    If True, raises a ConnectionError if either the port or the API can't be reached
  • host [String], default: 'localhost'
    The hostname of the system to be pinged
  • port [Int], default: 8086
    The port of the system to be pinged

Changelog

Version Date Changes
0.0.4 2022-04-28 Bugfix: Put DESC into the query for read_latest() so that it actually returns the last entry
0.0.3 2022-04-27 Changed read_latest because it didn't work correctly with all influx versions (returns time=0)
0.0.2 2022-04-26 Added actual functionality

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

simpleinflux-0.1.0.tar.gz (9.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

simpleinflux-0.1.0-py2.py3-none-any.whl (6.5 kB view details)

Uploaded Python 2Python 3

File details

Details for the file simpleinflux-0.1.0.tar.gz.

File metadata

  • Download URL: simpleinflux-0.1.0.tar.gz
  • Upload date:
  • Size: 9.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.27.1

File hashes

Hashes for simpleinflux-0.1.0.tar.gz
Algorithm Hash digest
SHA256 edf318612c3f42b834590deb132336483f70bd5d2790e1d5ebed3fc504855162
MD5 ed7283ac298c9d500a04c6f3a2dd3b4f
BLAKE2b-256 f383f3a4486dc63d71572ee66cc51a13fc3f42db5c3c5f5d25749fb7d1ca2aad

See more details on using hashes here.

File details

Details for the file simpleinflux-0.1.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for simpleinflux-0.1.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 22afcb7accda37e965a8c621a1068cbb642bf2993e2ce58c3f11e416d83d52b6
MD5 046f229e3cb80b1c46709c882e2e15ec
BLAKE2b-256 d60714de0ca419b1dbf38ac9fb2402bea56c5d9900ba1b99d99da80e278cb361

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page