Skip to content
This repository was archived by the owner on Oct 29, 2024. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 33 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ python:
- "2.7"
- "3.5"
- "3.6"
- "pypy-5.3.1"
- "pypy"
- "pypy3"

env:
- INFLUXDB_VER=1.2.4
- INFLUXDB_VER=1.3.9
- INFLUXDB_VER=1.4.2
- INFLUXDB_VER=1.5.4
- INFLUXDB_VER=1.2.4 # 2017-05-08
- INFLUXDB_VER=1.3.9 # 2018-01-19
- INFLUXDB_VER=1.4.3 # 2018-01-30
- INFLUXDB_VER=1.5.4 # 2018-06-22
- INFLUXDB_VER=1.6.4 # 2018-10-24
- INFLUXDB_VER=1.7.4 # 2019-02-14

addons:
apt:
Expand All @@ -20,7 +22,31 @@ addons:

matrix:
include:
- python: 2.7
- python: 3.7
dist: xenial
sudo: true
env: INFLUXDB_VER=1.2.4
- python: 3.7
dist: xenial
sudo: true
env: INFLUXDB_VER=1.3.9
- python: 3.7
dist: xenial
sudo: true
env: INFLUXDB_VER=1.4.3
- python: 3.7
dist: xenial
sudo: true
env: INFLUXDB_VER=1.5.4
- python: 3.7
dist: xenial
sudo: true
env: INFLUXDB_VER=1.6.4
- python: 3.7
dist: xenial
sudo: true
env: INFLUXDB_VER=1.7.4
- python: 3.6
env: TOX_ENV=pep257
- python: 3.6
env: TOX_ENV=docs
Expand All @@ -31,7 +57,7 @@ matrix:

install:
- pip install tox-travis
- pip install setuptools==20.6.6
- pip install setuptools
- pip install coveralls
- mkdir -p "influxdb_install/${INFLUXDB_VER}"
- if [ -n "${INFLUXDB_VER}" ] ; then wget "https://dl.influxdata.com/influxdb/releases/influxdb_${INFLUXDB_VER}_amd64.deb" ; fi
Expand Down
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,24 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
## [Unreleased]

### Added
- Add `get_list_continuous_queries`, `drop_continuous_query`, and `create_continuous_query` management methods for
continuous queries (#681 thx @lukaszdudek-silvair)
- query() now accepts a bind_params argument for parameter binding (#678 thx @clslgrnc)

### Changed
- Add consistency param to InfluxDBClient.write_points (#643 thx @RonRothman)
- Update test suite to add support for Python 3.7 and InfluxDB v1.6.4 and 1.7.4 (#692 thx @clslgrnc)
- Update classifiers tuple to list in setup.py (#697 thx @Hanaasagi)
- Update documentation for empty `delete_series` confusion

### Removed

## [v5.2.2] - 2019-03-14
### Added

### Changed
- Fix 'TypeError: Already tz-aware' introduced with recent versions of Panda (#671, #676, thx @f4bsch @clslgrnc)

## [v5.2.1] - 2018-12-07
### Added

Expand Down
1 change: 1 addition & 0 deletions CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @aviau @xginn8 @sebito91
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ InfluxDB is an open-source distributed time series database, find more about Inf
InfluxDB pre v1.1.0 users
-------------------------

This module is tested with InfluxDB versions: v1.2.4, v1.3.9, v1.4.2, and v1.5.4.
This module is tested with InfluxDB versions: v1.2.4, v1.3.9, v1.4.3, v1.5.4, v1.6.4, and 1.7.4.

Those users still on InfluxDB v0.8.x users may still use the legacy client by importing ``from influxdb.influxdb08 import InfluxDBClient``.

Expand All @@ -59,7 +59,7 @@ On Debian/Ubuntu, you can install it with this command::
Dependencies
------------

The influxdb-python distribution is supported and tested on Python 2.7, 3.5, 3.6, PyPy and PyPy3.
The influxdb-python distribution is supported and tested on Python 2.7, 3.5, 3.6, 3.7, PyPy and PyPy3.

**Note:** Python <3.5 are currently untested. See ``.travis.yml``.

Expand Down
6 changes: 6 additions & 0 deletions docs/source/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,9 @@ Tutorials - SeriesHelper

.. literalinclude:: ../../examples/tutorial_serieshelper.py
:language: python

Tutorials - UDP
===============

.. literalinclude:: ../../examples/tutorial_udp.py
:language: python
9 changes: 8 additions & 1 deletion examples/tutorial.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ def main(host='localhost', port=8086):
dbname = 'example'
dbuser = 'smly'
dbuser_password = 'my_secret_password'
query = 'select value from cpu_load_short;'
query = 'select Float_value from cpu_load_short;'
query_where = 'select Int_value from cpu_load_short where host=$host;'
bind_params = {'host': 'server01'}
json_body = [
{
"measurement": "cpu_load_short",
Expand Down Expand Up @@ -50,6 +52,11 @@ def main(host='localhost', port=8086):

print("Result: {0}".format(result))

print("Querying data: " + query_where)
result = client.query(query_where, bind_params=bind_params)

print("Result: {0}".format(result))

print("Switch user: " + user)
client.switch_user(user, password)

Expand Down
66 changes: 66 additions & 0 deletions examples/tutorial_udp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# -*- coding: utf-8 -*-
"""Example for sending batch information to InfluxDB via UDP."""

"""
INFO: In order to use UDP, one should enable the UDP service from the
`influxdb.conf` under section
[[udp]]
enabled = true
bind-address = ":8089" # port number for sending data via UDP
database = "udp1" # name of database to be stored
[[udp]]
enabled = true
bind-address = ":8090"
database = "udp2"
"""


import argparse

from influxdb import InfluxDBClient


def main(uport):
"""Instantiate connection to the InfluxDB."""
# NOTE: structure of the UDP packet is different than that of information
# sent via HTTP
json_body = {
"tags": {
"host": "server01",
"region": "us-west"
},
"time": "2009-11-10T23:00:00Z",
"points": [{
"measurement": "cpu_load_short",
"fields": {
"value": 0.64
}
},
{
"measurement": "cpu_load_short",
"fields": {
"value": 0.67
}
}]
}

# make `use_udp` True and add `udp_port` number from `influxdb.conf` file
# no need to mention the database name since it is already configured
client = InfluxDBClient(use_udp=True, udp_port=uport)

# Instead of `write_points` use `send_packet`
client.send_packet(json_body)


def parse_args():
"""Parse the args."""
parser = argparse.ArgumentParser(
description='example code to play with InfluxDB along with UDP Port')
parser.add_argument('--uport', type=int, required=True,
help=' UDP port of InfluxDB')
return parser.parse_args()


if __name__ == '__main__':
args = parse_args()
main(uport=args.uport)
2 changes: 1 addition & 1 deletion influxdb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@
]


__version__ = '5.2.1'
__version__ = '5.2.2'
15 changes: 14 additions & 1 deletion influxdb/_dataframe_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ def write_points(self,
def query(self,
query,
params=None,
bind_params=None,
epoch=None,
expected_response_code=200,
database=None,
Expand All @@ -153,8 +154,18 @@ def query(self,
"""
Query data into a DataFrame.

.. danger::
In order to avoid injection vulnerabilities (similar to `SQL
injection <https://www.owasp.org/index.php/SQL_Injection>`_
vulnerabilities), do not directly include untrusted data into the
``query`` parameter, use ``bind_params`` instead.

:param query: the actual query string
:param params: additional parameters for the request, defaults to {}
:param bind_params: bind parameters for the query:
any variable in the query written as ``'$var_name'`` will be
replaced with ``bind_params['var_name']``. Only works in the
``WHERE`` clause and takes precedence over ``params['params']``
:param epoch: response timestamps to be in epoch format either 'h',
'm', 's', 'ms', 'u', or 'ns',defaults to `None` which is
RFC3339 UTC format with nanosecond precision
Expand All @@ -172,6 +183,7 @@ def query(self,
:rtype: :class:`~.ResultSet`
"""
query_args = dict(params=params,
bind_params=bind_params,
epoch=epoch,
expected_response_code=expected_response_code,
raise_errors=raise_errors,
Expand Down Expand Up @@ -202,7 +214,8 @@ def _to_dataframe(self, rs, dropna=True):
df = pd.DataFrame(data)
df.time = pd.to_datetime(df.time)
df.set_index('time', inplace=True)
df.index = df.index.tz_localize('UTC')
if df.index.tzinfo is None:
df.index = df.index.tz_localize('UTC')
df.index.name = None
result[key].append(df)
for key, data in result.items():
Expand Down
Loading