Python

Warning! This page documents an old version of InfluxDB, which is no longer actively developed. InfluxDB v1.3 is the most recent stable version of InfluxDB.

The InfluxDB Python library lives on GitHub thanks to smly.

Get and Install

Using pip

pip install influxdb

Manual Installation

git clone https://github.com/influxdb/influxdb-python.git
cd influxdb-python
pip install -r requirements.txt
python setup.py install

Initialization

First, create a new InfluxDB object by connecting to a running instance.

from influxdb import client as influxdb
db = influxdb.InfluxDBClient(host, port, username, password, database)

Available Functions

create_database(database)

Create database. Requires cluster-admin privileges.

delete_database(database)

Delete database. Requires cluster-admin privileges.

switch_db(databaseName)

Switch to another database.

switch_user(username, password)

Change your user-context.

write_points(data)

Write to multiple time series names.

Example:

data = [
  {"points":[[1.1,4.3,2.1],[1.2,2.0,2.0]],
   "name":"web_devweb01_load",
   "columns":["min1", "min5", "min15"]
  }
]
db.write_points(data)

write_points_with_precision(data, time_precision=’s’)

Write to multiple time series names with defined precision.

query(query, time_precision=’s’, chunked=False)

Query for data

Example:

result = db.query('select min5 from web_devweb01_load;')

This will print the following (timestamps will be obviously different):

[
 {u'points': [[1386001532, 6, 2], [1386001532, 5, 4.3]],
  u'name': u'web_devweb01_load',
  u'columns': [u'time', u'sequence_number', u'min5']
 }
]