.. figure:: ./artwork/logo.svg
:alt:
Influxable
==========
|pypi version| |build status| |code coverage| |license: MIT|
A lightweight python ORM / ODM / Client for InfluxDB
Table of Contents
-----------------
- `Note <#note>`__
- `Genesis <#genesis>`__
- `Changelog <#changelog>`__
- `Features <#features>`__
- `Dependencies <#dependencies>`__
- `Installation <#installation>`__
- `Getting started <#getting-started>`__
- `Connection <#connection>`__
- `Measurement <#measurement>`__
- `Simple Measurement <#simple-measurement>`__
- `Instanciation <#instanciation>`__
- `Query <#query>`__
- `Saving Data <#saving-data>`__
- `Auto Generation of Measurements <#auto-generation-of-measurements>`__
- `Influxable commands <#influxable-commands>`__
- `Influxable API <#influxable-api>`__
- `Influxable Class <#influxable-class>`__
- `InfluxDBApi Class <#influxdbapi-class>`__
- `Connection Class <#connection-class>`__
- `Measurement Class <#measurement-class>`__
- `Attributes <#attributes>`__
- `InfluxDBResponse <#influxdbresponse>`__
- `Serializers <#serializers>`__
- `Raw Query <#raw-query>`__
- `Query Class <#query-class>`__
- `Query aggregations function <#query-aggregations-function>`__
- `Query selectors function <#query-selectors-function>`__
- `Query transformations function <#query-transformations-function>`__
- `InfluxDBAdmin <#influxdbadmin>`__
- `Exceptions <#exceptions>`__
- `Testing <#testing>`__
- `Supporting <#supporting>`__
- `Versioning <#versioning>`__
- `Contributors <#contributors>`__
- `Credits <#credits>`__
- `References <#references>`__
- `License <#license>`__
Note
----
This project is currently in development.
A better documentation and testing scripts will be added in the next release.
Genesis
-------
I worked on a project with InfluxDB. I needed to build an API for InfluxDB and to plug with Python libraries (scipy, pandas, etc ...).
That's why I decided to create this repository in order to deal with InfluxDB in a smooth way and to manipulate Python object.
Changelog
---------
1.4.1
~~~~~
- Fix Setup Issue
- Merge PR Bump Security Issues
1.4.0
~~~~~
- Add integration with Influxdb OSS 2.0 Authentication (Experimental)
1.3.0
~~~~~
- Add *group\_by()* method for *GROUP BY tags* instructions
- Add *range()* method for *GROUP BY time()* instructions
- Add *into()* method for *INTO* instructions
- Add *tz()* method
1.2.1
~~~~~
- Handle chinese characters.
Features
--------
- Add automation for measurement class generation (command: *autogenerate*)
- Admin commands allowing to manage the database (ex: *create\_user()*, *show\_series()*).
- Measurement class allowing to make queries in order to fetch/save points (ex: *Measurement.where()*, *Measurement.bulk\_save()*).
- Group by commands
- Different serializers for easy data manipulation (ex: *PandasSerializer*).
Dependencies
------------
- Python 3 (Tested with Python 3.7.3)
- InfluxDB (Tested with InfluxDB 1.5.4)
Installation
------------
The package is available in pypi. You can install it via pip :
::
pip install influxable
Getting started
---------------
Connection
~~~~~~~~~~
You can set your environment variable for the connection of InfluxDB in order to override the default values :
::
INFLUXDB_URL=http://localhost:8086
INFLUXDB_DATABASE_NAME=default
#Optional
INFLUXDB_USER=admin
INFLUXDB_PASSWORD=changme
INFLUXDB_PASSWORD=changme
# OSS 2.0
INFLUXDB_AUTH_TOKEN=mytoken
Then you just have to import the influxable package and create an instance of *Influxable* :
.. code:: python
from influxable import Influxable
client = Influxable()
You can also set connection variable in *Influxable* constructor :
.. code:: python
# Without authentication
client = Influxable(
base_url='http://localhost:8086',
database_name='default',
)
# With authentication
client = Influxable(
base_url='http://localhost:8086',
database_name='default',
user='admin',
password='changeme',
)
# With token authentication
client = Influxable(
base_url='http://localhost:8086',
database_name='default',
token='my_token',
)
Measurement
~~~~~~~~~~~
.. code:: python
from influxable import attributes, serializers
from influxable.measurement import Measurement
class TemperatureMeasurement(Measurement):
parser_class = serializers.MeasurementPointSerializer # Default
measurement_name = 'temperature'
time = attributes.TimestampFieldAttribute()
phase = attributes.TagFieldAttribute()
value = attributes.FloatFieldAttribute()
Fields :
- GenericFieldAttribute (IntegerFieldAttribute, FloatFieldAttribute, StringFieldAttribute, BooleanFieldAttribute)
- TagFieldAttribute
- TimestampFieldAttribute, DateTimeFieldAttribute
Parser Classes :
- MeasurementPointSerializer (default)
- JsonSerializer
- FormattedSerieSerializer
- FlatFormattedSerieSerializer
- FlatSimpleResultSerializer
- PandasSerializer
Simple Measurement
~~~~~~~~~~~~~~~~~~
.. code:: python
from influxable.measurement import SimpleMeasurement
my_measurement = SimpleMeasurement('temperature', ['value'], ['phase'])
Instanciation
~~~~~~~~~~~~~
.. code:: python
point = TemperatureMeasurement(
time=1568970572,
phase="HOT",
value=23.5,
)
Query
~~~~~
You can query with *Measurement.get\_query()* :
.. code:: python
from influxable.db import Field
points = TemperatureMeasurement\
.get_query()\
.select('phase', 'value')\
.where(
Field('value') > 15.2,
Field('value') < 30.5,
)\
.limit(100)
.evaluate()
You can also query with *Query* :
.. code:: python
from influxable.db import Query, Field
points = Query()\
.select('phase', 'value')\
.from_measurements('temperature')\
.where(
Field('value') > 15.2,
Field('value') < 30.5,
)\
.limit(100)
.execute()
Saving Data
~~~~~~~~~~~
You can create data by using *Measurement.bulk\_save()*
.. code:: python
points = [
TemperatureMeasurement(phase="HOT",value=10,time=1463289075),
TemperatureMeasurement(phase="COLD",value=10,time=1463289076),
]
TemperatureMeasurement.bulk_save(points)
You can also create data with *BulkInsertQuery*
.. code:: python
str_query = '''
temperature,phase=HOT value=10 1463289075000000000
temperature,phase=COLD value=10 1463289076000000000
'''
raw_query = BulkInsertQuery(str_query)
res = raw_query.execute()
Integration with OSS 2.0 (Experimental)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. code:: bash
# Create the user
influx user create --name admin -- password admin
# Create the auth (in order to retrieve the token)
influx auth create --user admin --operator
# List yours tokens
influx auth list
# (Optional) export the INFLUXDB_AUTH_TOKEN
INFLUXDB_AUTH_TOKEN=my-token
# Create the config
influx config create --config-name defaut --host-url http://localhost:8086 --token NjIYagimNbX5MaZfisDsvuGGvtULdqIY-Wt8EP4eGk-3P9KftDtZjxXU4GocTMTfM0eglkuFJQyA9uF82ZeEoA== --org MyOrganisation
# Create the bucket
influx bucket create --name default
# List your bucket
influx bucket list
ID Name Retention Shard group duration Organization ID Schema Type
4688727b9c388f5f default infinite 168h0m0s b89cbec9670f29f8 implicit
# Create the dbrp (link database api v1 with bucket api v2)
influx v1 dbrp create --db default --rp default --bucket-id 4688727b9c388f5f --default
Auto Generation of Measurements
-------------------------------
You can automatically generate measurement classes file with the bash command *autogenerate*
.. code:: bash
influxable autogenerate #(default to auto_generate_measurement.py)
influxable autogenerate -o measurement.py
Here is the output generated file :
.. code:: python
# auto_generate_measurement.py
from influxable import attributes
from influxable.measurement import Measurement
class CpuMeasurement(Measurement):
measurement_name = 'cpu'
time = attributes.TimestampFieldAttribute(precision='s')
value = attributes.FloatFieldAttribute()
host = attributes.TagFieldAttribute()
Influxable commands
-------------------
- *autogenerate* : automatic generation of measurement classes
.. code:: bash
influxable autogenerate #(default to auto_generate_measurement.py)
influxable autogenerate -o measurement.py
- *populate* : create a measurement filled with a set of random data
.. code:: bash
influxable populate
influxable populate --min_value 5 --max_value 35 -s 2011-01-01T00:00:00 -id 1
influxable populate --help
Influxable API
--------------
Influxable Class
~~~~~~~~~~~~~~~~
The Influxable main app class is a singleton. You can access it via the method *Influxable.get\_instance()*
\_\_init\_\_():
^^^^^^^^^^^^^^^
- base\_url : url to connect to the InfluxDB server (default = 'http://localhost:8086')
- user : authentication user name (default = 'admin')
- password : authentication user password (default = 'changeme')
- database\_name : name of the database (default = 'default')
create\_connection() -> Connection:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- base\_url : url to connect to the InfluxDB server (default = 'http://localhost:8086')
- user : authentication user name (default = 'admin')
- password : authentication user password (default = 'changeme')
- database\_name : name of the database (default = 'default')
ping() -> bool:
^^^^^^^^^^^^^^^
- verbose : enables verbose mode (default = True)
execute\_query() -> json():
^^^^^^^^^^^^^^^^^^^^^^^^^^^
- query: influxdb query to execute
- method: http method of the request (default='get')
- chunked: if enabled, responses will be chunked by series or by every 10,000 points (default=False)
- epoch: specified precision of the timestamp [ns,u,µ,ms,s,m,h] (default='ns')
- pretty: if enadble, the json response is pretty-printed (default=False)
write\_points() -> bool:
^^^^^^^^^^^^^^^^^^^^^^^^
- points: data to write in InfluxDB line protocol format
ex: mymeas,mytag1=1 value=21 1463689680000000000
- precision: specified precision of the timestamp [ns,u,µ,ms,s,m,h] (default='ns')
- consistency: sets the write consistency for the point [any,one,quorum,all] (default='all')
- retention\_policy\_name: sets the target retention policy for the write (default='DEFAULT')
InfluxDBApi Class
~~~~~~~~~~~~~~~~~
get\_debug\_requests() -> bool:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- request : instance of InfluxDBRequest
get\_debug\_vars() -> bool:
^^^^^^^^^^^^^^^^^^^^^^^^^^^
- request : instance of InfluxDBRequest
ping() -> bool:
^^^^^^^^^^^^^^^
- request : instance of InfluxDBRequest
- verbose : enables verbose mode (default = True)
execute\_query() -> json():
^^^^^^^^^^^^^^^^^^^^^^^^^^^
- request : instance of InfluxDBRequest
- query: influxdb query to execute
- method: http method of the request (default='get')
- chunked: if enabled, responses will be chunked by series or by every 10,000 points (default=False)
- epoch: specified precision of the timestamp [ns,u,µ,ms,s,m,h] (default='ns')
- pretty: if enadble, the json response is pretty-printed (default=False)
write\_points() -> bool:
^^^^^^^^^^^^^^^^^^^^^^^^
- request : instance of InfluxDBRequest
- points: data to write in InfluxDB line protocol format
ex: mymeas,mytag1=1 value=21 1463689680000000000
- precision: specified precision of the timestamp [ns,u,µ,ms,s,m,h] (default='ns')
- consistency: sets the write consistency for the point [any,one,quorum,all] (default='all')
- retention\_policy\_name: sets the target retention policy for the write (default='DEFAULT')
Connection Class
~~~~~~~~~~~~~~~~
\_\_init\_\_():
^^^^^^^^^^^^^^^
- base\_url : url to connect to the InfluxDB server (default = 'http://localhost:8086')
- user : authentication user name (default = 'admin')
- password : authentication user password (default = 'changeme')
- database\_name : name of the database (default = 'default')
create() -> Connection:
^^^^^^^^^^^^^^^^^^^^^^^
- base\_url : url to connect to the InfluxDB server (default = 'http://localhost:8086')
- user : authentication user name (default = 'admin')
- password : authentication user password (default = 'changeme')
- database\_name : name of the database (default = 'default')
Measurement Class
~~~~~~~~~~~~~~~~~
fields
^^^^^^
Must be an instance of class located in *influxable.attributes*
- GenericFieldAttribute
- IntegerFieldAttribute
- FloatFieldAttribute
- StringFieldAttribute
- BooleanFieldAttribute
- TagFieldAttribute
- TimestampFieldAttribute
- DateTimeFieldAttribute
Example :
.. code:: python
class MySensorMeasurement(Measurement):
measurement_name = 'mysensor'
time = TimestampFieldAttribute(auto_now=True, precision='s')
phase = TagFieldAttribute()
value = IntegerFieldAttribute()
parser\_class
^^^^^^^^^^^^^
Must be a class of *influxable.serializers* :
- MeasurementPointSerializer (default)
- JsonSerializer
- FormattedSerieSerializer
- FlatFormattedSerieSerializer
- FlatSimpleResultSerializer
- PandasSerializer
measurement\_name
^^^^^^^^^^^^^^^^^
Name of the measurement in InfluxDB
\_\_init\_\_():
^^^^^^^^^^^^^^^
Set the attribute value of a Measurement
Example
.. code:: python
point = MySensorMeasurement(value=0.5, phase="MOON")
get\_query() -> Query:
^^^^^^^^^^^^^^^^^^^^^^
Return an instance of Query which
Example
.. code:: python
points = MySensorMeasurement\
.get_query()\
.select()\
.where()\
.limit()\
.evaluate()
dict()
^^^^^^
Return a dict of the point values
Example
.. code:: python
point = MySensorMeasurement(value=0.5, phase="MOON")
point.dict()
# {'time': Decimal('1568970572'), 'phase': 'MOON', 'value': 0.5}
items()
^^^^^^^
Return an item list of the point values
Example
.. code:: python
point = MySensorMeasurement(value=0.5, phase="MOON")
point.items()
# dict_items([('time', Decimal('1568970572')), ('phase', 'MOON'), ('value', 0.5)])
bulk\_save()
^^^^^^^^^^^^
Save a list of measurement point
.. code:: python
points = [
MySensorMeasurement(phase="moon",value=5,time=1463489075),
MySensorMeasurement(phase="moon",value=7,time=1463489076),
MySensorMeasurement(phase="sun",value=8,time=1463489077),
]
MySensorMeasurement.bulk_save(points)
Attributes
~~~~~~~~~~
GenericFieldAttribute
^^^^^^^^^^^^^^^^^^^^^
- attribute\_name : real name of the measurement attribute in database
- default : set a default value if it is not filled at the instanciation
- is\_nullable : if False, it will raise an error if the value is null (default=True)
- enforce\_cast : if False, it will not raise an error when the value has not the desired type without casting (default=True).
.. code:: python
class MySensorMeasurement(Measurement):
measurement_name = 'mysensor'
temperature_value = GenericFieldAttribute(
attribute_name="temp_v1",
default="15",
is_nullable=True,
enforce_cast=False,
)
IntegerFieldAttribute
^^^^^^^^^^^^^^^^^^^^^
- min\_value : an error is raised if the value is less than the min\_value
- max\_value : an error is raised if the value is greater than the max\_value
- attribute\_name : real name of the measurement attribute in database
- default : set a default value if it is not filled at the instanciation
- is\_nullable : if False, it will raise an error if the value is null (default=True)
- enforce\_cast : if False, it will not raise an error when the value has not the desired type without casting (default=True).
.. code:: python
class MySensorMeasurement(Measurement):
measurement_name = 'mysensor'
temperature_value = IntegerFieldAttribute(
min_value=10,
max_value=30,
)
FloatFieldAttribute
^^^^^^^^^^^^^^^^^^^
- max\_nb\_decimals : set the maximal number of decimals to display
- min\_value : an error is raised if the value is less than the min\_value
- max\_value : an error is raised if the value is greater than the max\_value
- attribute\_name : real name of the measurement attribute in database
- default : set a default value if it is not filled at the instanciation
- is\_nullable : if False, it will raise an error if the value is null (default=True)
- enforce\_cast : if False, it will not raise an error when the value has not the desired type without casting (default=True).
.. code:: python
class MySensorMeasurement(Measurement):
measurement_name = 'mysensor'
value = FloatFieldAttribute(
max_nb_decimals=5,
)
StringFieldAttribute
^^^^^^^^^^^^^^^^^^^^
- choices : an error is raised if the value is not in the list of string options
- max\_length : an error is raised if the string value length is greater than the max\_length
- attribute\_name : real name of the measurement attribute in database
- default : set a default value if it is not filled at the instanciation
- is\_nullable : if False, it will raise an error if the value is null (default=True)
- enforce\_cast : if False, it will not raise an error when the value has not the desired type without casting (default=True).
.. code:: python
class MySensorMeasurement(Measurement):
measurement_name = 'mysensor'
position = FloatFieldAttribute(
choices=['first', 'last'],
max_length=7,
)
BooleanFieldAttribute
^^^^^^^^^^^^^^^^^^^^^
- attribute\_name : real name of the measurement attribute in database
- default : set a default value if it is not filled at the instanciation
- is\_nullable : if False, it will raise an error if the value is null (default=True)
- enforce\_cast : if False, it will not raise an error when the value has not the desired type without casting (default=True).
.. code:: python
class MySensorMeasurement(Measurement):
measurement_name = 'mysensor'
is_marked = BooleanFieldAttribute(
default=False,
)
TagFieldAttribute
^^^^^^^^^^^^^^^^^
- attribute\_name : real name of the measurement attribute in database
- default : set a default value if it is not filled at the instanciation
- is\_nullable : if False, it will raise an error if the value is null (default=True)
- enforce\_cast : if False, it will not raise an error when the value has not the desired type without casting (default=True).
.. code:: python
class MySensorMeasurement(Measurement):
measurement_name = 'mysensor'
phase = TagFieldAttribute(
default='MOON',
)
TimestampFieldAttribute
^^^^^^^^^^^^^^^^^^^^^^^
- auto\_now : Set automatically the current date (default=False)
- precision : Set the timestamp precision which must be one of [ns,u,ms,s,m,h] (default= 'ns')
- attribute\_name : real name of the measurement attribute in database
- default : set a default value if it is not filled at the instanciation
- is\_nullable : if False, it will raise an error if the value is null (default=True)
- enforce\_cast : if False, it will not raise an error when the value has not the desired type without casting (default=True).
.. code:: python
class MySensorMeasurement(Measurement):
measurement_name = 'mysensor'
time = TimestampFieldAttribute(
auto_now=True,
precision='s',
)
DateTimeFieldAttribute
^^^^^^^^^^^^^^^^^^^^^^
- str\_format : Set the arrow format of the timestamp to display (default: "YYYY-MM-DD HH:mm:ss")
- auto\_now : Set automatically the current date
- precision : Set the timestamp precision which must be one of [ns,u,ms,s,m,h]
- attribute\_name : real name of the measurement attribute in database
- default : set a default value if it is not filled at the instanciation
- is\_nullable : if False, it will raise an error if the value is null (default=True)
- enforce\_cast : if False, it will not raise an error when the value has not the desired type without casting (default=True).
.. code:: python
class MySensorMeasurement(Measurement):
measurement_name = 'mysensor'
date = DateTimeFieldAttribute(
attribute_name='time',
auto_now=True,
str_format='YYYY-MM-DD',
)
InfluxDBResponse
~~~~~~~~~~~~~~~~
\_\_init\_\_():
^^^^^^^^^^^^^^^
- raw\_json : the raw json response object
raw
^^^
Return the raw\_json value
main\_serie
^^^^^^^^^^^
Return the first serie from the *series* field in the raw\_json value
series
^^^^^^
Return the *series* field in the raw\_json value
error
^^^^^
Return the *error* field in the raw\_json value
Example of json raw response :
.. code:: python
{
"results":[
{
"statement_id":0,
"series":[
{
"name":"mymeas",
"columns":[
"time",
"myfield",
"mytag1",
"mytag2"
],
"values":[
[
"2017-03-01T00:16:18Z",
33.1,
null,
null
],
[
"2017-03-01T00:17:18Z",
12.4,
"12",
"14"
]
]
}
]
}
]
}
Serializers
~~~~~~~~~~~
Serializers can be used in *parser\_class* field of *Measurement* class.
.. code:: python
class MySensorMeasurement(Measurement):
measurement_name = 'mysensor'
parser_class = serializers.BaseSerializer
It allow to change the output response format of a influxb request
.. code:: python
# res is formatted with BaseSerializer
res = MySensorMeasurement.get_query().limit(10).evaluate()
BaseSerializer
^^^^^^^^^^^^^^
.. code:: python
# res is formatted with BaseSerializer
res
{'results': [{'statement_id': 0, 'series': [{'name': 'mysamplemeasurement', 'columns': ['time', 'value'], 'values': [[1570481055000000000, 10], [1570481065000000000, 20], [1570481075000000000, 30]]}]}]}
JsonSerializer
^^^^^^^^^^^^^^
.. code:: python
# res is formatted with JsonSerializer
res
'{"results": [{"statement_id": 0, "series": [{"name": "mysamplemeasurement", "columns": ["time", "value"], "values": [[1570481055000000000, 10], [1570481065000000000, 20], [1570481075000000000, 30]]}]}]}'
FormattedSerieSerializer
^^^^^^^^^^^^^^^^^^^^^^^^
.. code:: python
# res is formatted with FormattedSerieSerializer
res
[{'mysamplemeasurement': [{'time': 1570481055000000000, 'value': 10}, {'time': 1570481065000000000, 'value': 20}, {'time': 1570481075000000000, 'value': 30}]}]
FlatFormattedSerieSerializer
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. code:: python
# res is formatted with FlatFormattedSerieSerializer
[{'time': 1570481055000000000, 'value': 10}, {'time': 1570481065000000000, 'value': 20}, {'time': 1570481075000000000, 'value': 30}]
FlatSimpleResultSerializer
^^^^^^^^^^^^^^^^^^^^^^^^^^
This serializer is used only when the result set contains only one column
.. code:: python
res = InfluxDBAdmin.show_databases()
# res is formatted with FlatSimpleResultSerializer
res
['_internal', 'example', 'test', 'telegraf', 'mydb', ...]
FlatSingleValueSerializer
^^^^^^^^^^^^^^^^^^^^^^^^^
This serializer is used only when the result set contains only one value
.. code:: python
res = InfluxDBAdmin.show_measurement_cardinality()
# res is formatted with FlatSingleValueSerializer
res
2
PandasSerializer
^^^^^^^^^^^^^^^^
.. code:: python
# res is formatted with PandasSerializer
res time value
0 1570481055000000000 10
1 1570481065000000000 20
2 1570481075000000000 30
MeasurementPointSerializer
^^^^^^^^^^^^^^^^^^^^^^^^^^
This is the default serializer class for Measurement
.. code:: python
[<MySensorMeasurement object at 0x7f49a16227f0>, <MySensorMeasurement object at 0x7f49a16228d0>, <MySensorMeasurement object at 0x7f49a1622438>]
Raw Query
~~~~~~~~~
- str\_query
Example :
.. code:: python
from influxable.db import RawQuery
str_query = 'SHOW DATABASES'
res = RawQuery(str_query).execute()
.. code:: python
from influxable.db import RawQuery
str_query = 'SELECT * FROM temperature LIMIT 10'
res = RawQuery(str_query).execute()
Query Class
~~~~~~~~~~~
You can generate an instance of Query via the initial Query constructor or from a measurement.
Example :
.. code:: python
from influxable.db import Query
query = Query()
...
.. code:: python
query = MySensorMeasurement.get_query()
...
Methods :
from\_measurements()
^^^^^^^^^^^^^^^^^^^^
- \*measurements
Example :
.. code:: python
query = Query()\
.from_measurements('measurement1', 'measurement2')
Render :
.. code:: sql
FROM measurement1, measurement2
select()
^^^^^^^^
- \*fields
Example :
.. code:: python
query = Query()\
.select('param1', 'param2')\
.from_measurements('measurement1')
Render :
.. code:: sql
SELECT value, phase
where()
^^^^^^^
- \*criteria
Example :
.. code:: python
from influxable.db import Query, Field
query = Query()\
.select('param1', 'param2')\
.from_measurements('measurement1')\
.where(
Field('param1') > 800,
Field('param1') < 900,
)
Render :
.. code:: sql
WHERE param1 > 800 AND param1 < 900
limit()
^^^^^^^
- value
Example :
.. code:: python
from influxable.db import Query, Field
query = Query()\
.select('param1', 'param2')\
.from_measurements('measurement1')\
.where(
Field('param1') > 800,
Field('param1') < 900,
)\
.limit(10)
Render :
.. code:: sql
LIMIT 10
slimit()
^^^^^^^^
- value
Example :
.. code:: python
from influxable.db import Query, Field
query = Query()\
.select('param1', 'param2')\
.from_measurements('measurement1')\
.where(
Field('param1') > 800,
Field('param1') < 900,
)\
.limit(10)\
.slimit(5)
Render :
.. code:: sql
SLIMIT 5
offset()
^^^^^^^^
- value
Example :
.. code:: python
from influxable.db import Query, Field
query = Query()\
.select('param1', 'param2')\
.from_measurements('measurement1')\
.where(
Field('param1') > 800,
Field('param1') < 900,
)\
.offset(10)
Render :
.. code:: sql
OFFSET 10
soffset()
^^^^^^^^^
- value
Example :
.. code:: python
from influxable.db import Query, Field
query = Query()\
.select('param1', 'param2')\
.from_measurements('measurement1')\
.where(
Field('param1') > 800,
Field('param1') < 900,
)\
.offset(10)\
.soffset(5)
Render :
.. code:: sql
SOFFSET 5
into()
^^^^^^
- \*measurement
Example :
.. code:: python
query = Query()\
.select('param1')\
.from_measurements('measurement1')\
.into('measurement2')
Render :
.. code:: sql
SELECT param1 INTO measurement2 FROM measurement1
asc()
^^^^^
Example :
.. code:: python
query = Query()\
.select('param1')\
.from_measurements('measurement1')\
.asc()
Render :
.. code:: sql
SELECT param1 FROM measurement1 ORDER BY ASC
desc()
^^^^^^
Example :
.. code:: python
query = Query()\
.select('param1')\
.from_measurements('measurement1')\
.desc()
Render :
.. code:: sql
SELECT param1 FROM measurement1 ORDER BY DESC
tz()
^^^^
Example :
.. code:: python
query = Query()\
.select('param1')\
.from_measurements('measurement1')\
.tz('Europe/Paris')
Render :
.. code:: sql
SELECT param1 FROM measurement1 tz('Europe/Paris')
group\_by()
^^^^^^^^^^^
- \*tags
Example :
.. code:: python
query = Query()\
.select('param1')\
.from_measurements('measurement1')\
.group_by('tag_1')
Render :
.. code:: sql
SELECT param1 FROM measurement1 GROUP BY tag_1
range\_by()
^^^^^^^^^^^
- \*interval
- \*shift
- \*fill
- \*tags
Example :
.. code:: python
query = Query()\
.select('param1')\
.from_measurements('measurement1')\
.range_by('12s', shift='1d', tags=['tag1'], fill=3)
Render :
.. code:: sql
SELECT param1 FROM measurement1 GROUP BY time(12s,1d),tag1 fill(3)'
execute()
^^^^^^^^^
Execute the query and return the response
Example :
.. code:: python
from influxable.db import Query, Field
res = Query()\
.select('param1', 'param2')\
.from_measurements('measurement1')\
.where(
Field('param1') > 800,
Field('param1') < 900,
)\
.execute()
res
Result :
.. code:: python
{'results': [{'statement_id': 0, 'series': [{'name': 'measurement1', 'columns': ['time', 'value'], 'values': [[1570481055000000000, 10], [1570481065000000000, 20], [1570481075000000000, 30]]}]}]}
evaluate()
^^^^^^^^^^
Execute the query and return the serialized response
- parser\_class (default=BaseSerializer for Query and MeasurementPointSerializer for Measurement)
Example with Query :
.. code:: python
from influxable.db import Query, Field
res = Query()\
.select('param1', 'param2')\
.from_measurements('measurement1')\
.where(
Field('param1') > 800,
Field('param1') < 900,
)\
.evaluate()
res
Result :
.. code:: python
{'results': [{'statement_id': 0, 'series': [{'name': 'measurement1', 'columns': ['time', 'value'], 'values': [[1570481055000000000, 10], [1570481065000000000, 20], [1570481075000000000, 30]]}]}]}
Example with Measurement :
.. code:: python
from influxable.db import Field
points = MySensorMeasurement.get_query()
.select('param1', 'param2')\
.from_measurements('measurement1')\
.where(
Field('param1') > 800,
Field('param1') < 900,
)\
.evaluate()
points
Result :
.. code:: python
[<MySensorMeasurement object at 0x7f49a16227f0>, <MySensorMeasurement object at 0x7f49a16228d0>, <MySensorMeasurement object at 0x7f49a1622438>]
count()
^^^^^^^
- value (default='\*')
Example :
.. code:: python
from influxable.db import Query, Field
query = Query()\
.from_measurements('measurement1')\
.where(
Field('param1') > 800,
Field('param1') < 900,
)\
.count()
Render :
.. code:: sql
SELECT COUNT(*)
distinct()
^^^^^^^^^^
- value (default='\*')
Example :
.. code:: python
from influxable.db import Query, Field
query = Query()\
.from_measurements('measurement1')\
.where(
Field('param1') > 800,
Field('param1') < 900,
)\
.distinct()
Render :
.. code:: sql
SELECT DISTINCT(*)
integral()
^^^^^^^^^^
- value (default='\*')
Example :
.. code:: python
from influxable.db import Query, Field
query = Query()\
.from_measurements('measurement1')\
.where(
Field('param1') > 800,
Field('param1') < 900,
)\
.integral()
Render :
.. code:: sql
SELECT INTEGRAL(*)
mean()
^^^^^^
- value (default='\*')
Example :
.. code:: python
from influxable.db import Query, Field
query = Query()\
.from_measurements('measurement1')\
.where(
Field('param1') > 800,
Field('param1') < 900,
)\
.mean()
Render :
.. code:: sql
SELECT MEAN(*)
median()
^^^^^^^^
- value (default='\*')
Example :
.. code:: python
from influxable.db import Query, Field
query = Query()\
.from_measurements('measurement1')\
.where(
Field('param1') > 800,
Field('param1') < 900,
)\
.median()
Render :
.. code:: sql
SELECT MEDIAN(*)
mode()
^^^^^^
- value (default='\*')
Example :
.. code:: python
from influxable.db import Query, Field
query = Query()\
.from_measurements('measurement1')\
.where(
Field('param1') > 800,
Field('param1') < 900,
)\
.mode()
Render :
.. code:: sql
SELECT MODE(*)
spread()
^^^^^^^^
- value (default='\*')
Example :
.. code:: python
from influxable.db import Query, Field
query = Query()\
.from_measurements('measurement1')\
.where(
Field('param1') > 800,
Field('param1') < 900,
)\
.spread()
Render :
.. code:: sql
SELECT SPREAD(*)
std\_dev()
^^^^^^^^^^
- value (default='\*')
Example :
.. code:: python
from influxable.db import Query, Field
query = Query()\
.from_measurements('measurement1')\
.where(
Field('param1') > 800,
Field('param1') < 900,
)\
.std_dev()
Render :
.. code:: sql
SELECT STDDEV(*)
sum()
^^^^^
- value (default='\*')
Example :
.. code:: python
from influxable.db import Query, Field
query = Query()\
.from_measurements('measurement1')\
.where(
Field('param1') > 800,
Field('param1') < 900,
)\
.sum()
Render :
.. code:: sql
SELECT SUM(*)
Query aggregations function
~~~~~~~~~~~~~~~~~~~~~~~~~~~
Usage :
.. code:: python
from influxable.db.function import aggregations
res = Query()\
.select(aggregations.Sum('value'))\
.from_measurements('param1')\
.execute()
Count
^^^^^
Distinct
^^^^^^^^
Integral
^^^^^^^^
Mean
^^^^
Median
^^^^^^
Mode
^^^^
Spread
^^^^^^
StdDev
^^^^^^
Sum
^^^
Query selectors function
~~~~~~~~~~~~~~~~~~~~~~~~
Usage :
.. code:: python
from influxable.db.function import selectors
res = Query()\
.select(selectors.Min('value'), selectors.Max('value'))\
.from_measurements('param1')\
.execute()
Bottom
^^^^^^
First
^^^^^
Last
^^^^
Max
^^^
Min
^^^
Percentile
^^^^^^^^^^
Sample
^^^^^^
Top
^^^
Query transformations function
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Usage :
.. code:: python
from influxable.db.function import selectors, transformations
res = Query()\
.select(transformations.Abs('value'))\
.from_measurements('param1')\
.execute()
.. code:: python
from influxable.db.function.selectors import Min, Max
from influxable.db.function.transformations import Abs
res = Query()\
.select(Abs(Min('value')), Abs(Max('value')))\
.from_measurements('param1')\
.execute()
Abs
^^^
ACos
^^^^
ASin
^^^^
ATan
^^^^
ATan2
^^^^^
Ceil
^^^^
Cos
^^^
CumulativeSum
^^^^^^^^^^^^^
Derivative
^^^^^^^^^^
Difference
^^^^^^^^^^
Elapsed
^^^^^^^
Exp
^^^
Floor
^^^^^
Histogram
^^^^^^^^^
Ln
^^
Log
^^^
Log2
^^^^
Log10
^^^^^
MovingAverage
^^^^^^^^^^^^^
NonNegativeDerivative
^^^^^^^^^^^^^^^^^^^^^
NonNegativeDifference
^^^^^^^^^^^^^^^^^^^^^
Pow
^^^
Round
^^^^^
Sin
^^^
Sqrt
^^^^
Tan
^^^
InfluxDBAdmin
~~~~~~~~~~~~~
alter\_retention\_policy()
^^^^^^^^^^^^^^^^^^^^^^^^^^
- policy\_name
- duration (default=None)
- replication (default=None)
- shard\_duration (default=None)
- is\_default (default=False)
.. code:: sql
ALTER RETENTION POLICY {policy_name} ON {database_name} [DURATION {duration} REPLICATION {replication} SHARD DURATION {shard_duration} DEFAULT]
create\_database()
^^^^^^^^^^^^^^^^^^
- new\_database\_name
- duration (default=None)
- replication (default=None)
- shard\_duration (default=None)
- policy\_name (default=False)
.. code:: sql
CREATE DATABASE {new_database_name} [WITH DURATION {duration} REPLICATION {replication} SHARD DURATION {shard_duration} NAME {policy_name}]
create\_retention\_policy()
^^^^^^^^^^^^^^^^^^^^^^^^^^^
- policy\_name
- duration (default=None)
- replication (default=None)
- shard\_duration (default=None)
- is\_default (default=False)
.. code:: sql
CREATE RETENTION POLICY {policy_name} ON {database_name} [DURATION {duration} REPLICATION {replication} SHARD DURATION {shard_duration} DEFAULT]
create\_subscription()
^^^^^^^^^^^^^^^^^^^^^^
- subscription\_name
- hosts
- any (default=False)
.. code:: sql
CREATE SUBSCRIPTION {subscription_name} ON {database_name} DESTINATIONS ANY/ALL {hosts}
create\_user()
^^^^^^^^^^^^^^
- user\_name
- password
- with\_privileges (default=False)
.. code:: sql
CREATE USER {user_name} WITH PASSWORD {password} [WITH ALL PRIVILEGES]
delete()
^^^^^^^^
- measurements (default=[])
- criteria (default=[])
.. code:: sql
DELETE FROM {measurements} WHERE {criteria}
drop\_continuous\_query()
^^^^^^^^^^^^^^^^^^^^^^^^^
- query\_name
.. code:: sql
DROP CONTINUOUS QUERY {query_name} ON {database_name}
drop\_database()
^^^^^^^^^^^^^^^^
- database\_name\_to\_delete
.. code:: sql
DROP DATABASE {database_name_to_delete}
drop\_measurement()
^^^^^^^^^^^^^^^^^^^
- measurement\_name
.. code:: sql
DROP MEASUREMENT {measurement_name}
drop\_retention\_policy()
^^^^^^^^^^^^^^^^^^^^^^^^^
- policy\_name
.. code:: sql
DROP RETENTION POLICY {policy_name} ON {database_name}
drop\_series()
^^^^^^^^^^^^^^
- measurements (default=[])
- criteria (default=[])
.. code:: sql
DROP SERIES FROM {measurements} WHERE {criteria}
drop\_subscription()
^^^^^^^^^^^^^^^^^^^^
- subscription\_name
.. code:: sql
DROP SUBSCRIPTION {subscription_name} ON {full_database_name}
drop\_user()
^^^^^^^^^^^^
- user\_name
.. code:: sql
DROP USER {user_name}
explain()
^^^^^^^^^
- query
- analyze (default=False)
.. code:: sql
EXPLAIN [ANALYZE] {query}
grant()
^^^^^^^
- privilege
- user\_name
.. code:: sql
GRANT {privilege} ON {database_name} TO {user_name}
kill()
^^^^^^
- query\_id
.. code:: sql
KILL QUERY {query_id}
revoke()
^^^^^^^^
- privilege
- user\_name
.. code:: sql
REVOKE {privilege} ON {database_name} FROM {user_name}
show\_field\_key\_cardinality()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- exact (default=False)
.. code:: sql
SHOW FIELD KEY [EXACT] CARDINALITY
show\_measurement\_cardinality()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- exact (default=False)
.. code:: sql
SHOW MEASUREMENT [EXACT] CARDINALITY
show\_series\_cardinality()
^^^^^^^^^^^^^^^^^^^^^^^^^^^
- exact (default=False)
.. code:: sql
SHOW SERIES [EXACT] CARDINALITY
show\_tag\_key\_cardinality()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
- key
- exact (default=False)
.. code:: sql
SHOW TAG VALUES [EXACT] CARDINALITY WITH KEY = {key}
show\_continuous\_queries()
^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. code:: sql
SHOW CONTINUOUS QUERIES
show\_diagnostics()
^^^^^^^^^^^^^^^^^^^
.. code:: sql
SHOW DIAGNOSTICS
show\_field\_keys()
^^^^^^^^^^^^^^^^^^^
- measurements (default=[])
.. code:: sql
SHOW FIELD KEYS FROM {measurements}
show\_grants()
^^^^^^^^^^^^^^
- user\_name
.. code:: sql
SHOW GRANTS FOR {user_name}
show\_databases()
^^^^^^^^^^^^^^^^^
.. code:: sql
SHOW DATABASES
show\_measurements()
^^^^^^^^^^^^^^^^^^^^
- criteria (default=[])
.. code:: sql
SHOW MEASUREMENTS WHERE {criteria}
show\_queries()
^^^^^^^^^^^^^^^
.. code:: sql
SHOW QUERIES
show\_retention\_policies()
^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. code:: sql
SHOW RETENTION POLICIES
show\_series()
^^^^^^^^^^^^^^
- measurements (default=[])
- criteria (default=[])
- limit (default=None)
- offset (default=None)
.. code:: sql
SHOW SERIES ON {database_name} [FROM {measurements} WHERE {criteria} LIMIT {limit} OFFSET {offset}]
show\_stats()
^^^^^^^^^^^^^
.. code:: sql
SHOW STATS
show\_shards()
^^^^^^^^^^^^^^
.. code:: sql
SHOW SHARDS
show\_shard\_groups()
^^^^^^^^^^^^^^^^^^^^^
.. code:: sql
SHOW SHARD GROUPS
show\_subscriptions()
^^^^^^^^^^^^^^^^^^^^^
.. code:: sql
SHOW SUBSCRIPTIONS
show\_tag\_keys()
^^^^^^^^^^^^^^^^^
- measurements (default=[])
.. code:: sql
SHOW TAG KEYS [FROM {measurements}]
show\_tag\_values()
^^^^^^^^^^^^^^^^^^^
- key
- measurements (default=[])
.. code:: sql
SHOW TAG VALUES [FROM {measurements}] WITH KEY = {key}
show\_users()
^^^^^^^^^^^^^
.. code:: sql
SHOW USERS
Exceptions
~~~~~~~~~~
InfluxDBException
^^^^^^^^^^^^^^^^^
InfluxDBError
^^^^^^^^^^^^^
InfluxDBConnectionError
^^^^^^^^^^^^^^^^^^^^^^^
InfluxDBInvalidResponseError
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
InfluxDBInvalidChoiceError
^^^^^^^^^^^^^^^^^^^^^^^^^^
InfluxDBInvalidTypeError
^^^^^^^^^^^^^^^^^^^^^^^^
InfluxDBInvalidURLError
^^^^^^^^^^^^^^^^^^^^^^^
InfluxDBBadRequestError
^^^^^^^^^^^^^^^^^^^^^^^
InfluxDBBadQueryError
^^^^^^^^^^^^^^^^^^^^^
InfluxDBInvalidNumberError
^^^^^^^^^^^^^^^^^^^^^^^^^^
InfluxDBInvalidTimestampError
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
InfluxDBUnauthorizedError
^^^^^^^^^^^^^^^^^^^^^^^^^
InfluxDBAttributeValueError
^^^^^^^^^^^^^^^^^^^^^^^^^^^
Testing
-------
First, you need to install pytest via the file *requirements-test.txt*
.. code:: bash
pip install -r requirements-test.txt
Then, you can launch the *pytest* command.
.. code:: python
pytest -v
Supporting
----------
Feel free to post issues your feedback or if you reach a problem with influxable library.
If you want to contribute, please use the pull requests section.
Versioning
----------
We use `SemVer <http://semver.org/>`__ for versioning. For the versions available, see the `tags on this repository <https://github.com/Javidjms/influxable/releases>`__
Contributors
------------
- `Javid Mougamadou <https://github.com/Javidjms>`__
Credits
-------
- Logo designed by `Maxime Bergerard <https://github.com/maximebergerard>`__
References
----------
- `Influxdb Website <https://docs.influxdata.com/platform/introduction>`__
- `Influxdb Github Repository <https://github.com/influxdata/influxdb>`__
- `Influxdb-Python Github Repository <https://github.com/influxdata/influxdb-python>`__
License
-------
`MIT <LICENSE.txt>`__
.. |pypi version| image:: https://img.shields.io/badge/pypi-1.4.1-blue
:target: https://pypi.org/project/influxable/
.. |build status| image:: https://img.shields.io/badge/build-passing-green
.. |code coverage| image:: https://img.shields.io/badge/coverage-100-green
.. |license: MIT| image:: https://img.shields.io/badge/License-MIT-blue.svg
Raw data
{
"_id": null,
"home_page": "https://github.com/Javidjms/influxable",
"name": "influxable",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.4",
"maintainer_email": "",
"keywords": "python,influxdb,odm,orm,driver,client",
"author": "Javid Mougamadou",
"author_email": "javidjms0@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/04/54/61663023a63cfe332ac51c3a49c9660ee9c64ed3733987318617997addc0/influxable-1.4.1.tar.gz",
"platform": null,
"description": ".. figure:: ./artwork/logo.svg\n :alt:\n\nInfluxable\n==========\n\n|pypi version| |build status| |code coverage| |license: MIT|\n\nA lightweight python ORM / ODM / Client for InfluxDB\n\nTable of Contents\n-----------------\n\n- `Note <#note>`__\n- `Genesis <#genesis>`__\n- `Changelog <#changelog>`__\n- `Features <#features>`__\n- `Dependencies <#dependencies>`__\n- `Installation <#installation>`__\n- `Getting started <#getting-started>`__\n\n - `Connection <#connection>`__\n - `Measurement <#measurement>`__\n - `Simple Measurement <#simple-measurement>`__\n - `Instanciation <#instanciation>`__\n - `Query <#query>`__\n - `Saving Data <#saving-data>`__\n\n- `Auto Generation of Measurements <#auto-generation-of-measurements>`__\n- `Influxable commands <#influxable-commands>`__\n- `Influxable API <#influxable-api>`__\n\n - `Influxable Class <#influxable-class>`__\n - `InfluxDBApi Class <#influxdbapi-class>`__\n - `Connection Class <#connection-class>`__\n - `Measurement Class <#measurement-class>`__\n - `Attributes <#attributes>`__\n - `InfluxDBResponse <#influxdbresponse>`__\n - `Serializers <#serializers>`__\n - `Raw Query <#raw-query>`__\n - `Query Class <#query-class>`__\n - `Query aggregations function <#query-aggregations-function>`__\n - `Query selectors function <#query-selectors-function>`__\n - `Query transformations function <#query-transformations-function>`__\n - `InfluxDBAdmin <#influxdbadmin>`__\n - `Exceptions <#exceptions>`__\n\n- `Testing <#testing>`__\n- `Supporting <#supporting>`__\n- `Versioning <#versioning>`__\n- `Contributors <#contributors>`__\n- `Credits <#credits>`__\n- `References <#references>`__\n- `License <#license>`__\n\nNote\n----\n\nThis project is currently in development.\n\nA better documentation and testing scripts will be added in the next release.\n\nGenesis\n-------\n\nI worked on a project with InfluxDB. I needed to build an API for InfluxDB and to plug with Python libraries (scipy, pandas, etc ...).\n\nThat's why I decided to create this repository in order to deal with InfluxDB in a smooth way and to manipulate Python object.\n\nChangelog\n---------\n\n1.4.1\n~~~~~\n\n- Fix Setup Issue \n- Merge PR Bump Security Issues\n\n\n1.4.0\n~~~~~\n\n- Add integration with Influxdb OSS 2.0 Authentication (Experimental)\n\n1.3.0\n~~~~~\n\n- Add *group\\_by()* method for *GROUP BY tags* instructions\n\n- Add *range()* method for *GROUP BY time()* instructions\n\n- Add *into()* method for *INTO* instructions\n\n- Add *tz()* method\n\n1.2.1\n~~~~~\n\n- Handle chinese characters.\n\nFeatures\n--------\n\n- Add automation for measurement class generation (command: *autogenerate*)\n\n- Admin commands allowing to manage the database (ex: *create\\_user()*, *show\\_series()*).\n\n- Measurement class allowing to make queries in order to fetch/save points (ex: *Measurement.where()*, *Measurement.bulk\\_save()*).\n\n- Group by commands\n\n- Different serializers for easy data manipulation (ex: *PandasSerializer*).\n\nDependencies\n------------\n\n- Python 3 (Tested with Python 3.7.3)\n\n- InfluxDB (Tested with InfluxDB 1.5.4)\n\nInstallation\n------------\n\nThe package is available in pypi. You can install it via pip :\n\n::\n\n pip install influxable\n\nGetting started\n---------------\n\nConnection\n~~~~~~~~~~\n\nYou can set your environment variable for the connection of InfluxDB in order to override the default values :\n\n::\n\n INFLUXDB_URL=http://localhost:8086\n INFLUXDB_DATABASE_NAME=default\n\n #Optional\n INFLUXDB_USER=admin\n INFLUXDB_PASSWORD=changme\n INFLUXDB_PASSWORD=changme\n\n # OSS 2.0\n INFLUXDB_AUTH_TOKEN=mytoken\n\nThen you just have to import the influxable package and create an instance of *Influxable* :\n\n.. code:: python\n\n from influxable import Influxable\n\n client = Influxable()\n\nYou can also set connection variable in *Influxable* constructor :\n\n.. code:: python\n\n # Without authentication\n\n client = Influxable(\n base_url='http://localhost:8086',\n database_name='default',\n )\n\n # With authentication\n\n client = Influxable(\n base_url='http://localhost:8086',\n database_name='default',\n user='admin',\n password='changeme',\n )\n\n # With token authentication\n\n client = Influxable(\n base_url='http://localhost:8086',\n database_name='default',\n token='my_token',\n )\n\nMeasurement\n~~~~~~~~~~~\n\n.. code:: python\n\n from influxable import attributes, serializers\n from influxable.measurement import Measurement\n\n class TemperatureMeasurement(Measurement):\n parser_class = serializers.MeasurementPointSerializer # Default\n measurement_name = 'temperature'\n\n time = attributes.TimestampFieldAttribute()\n phase = attributes.TagFieldAttribute()\n value = attributes.FloatFieldAttribute()\n\nFields :\n\n- GenericFieldAttribute (IntegerFieldAttribute, FloatFieldAttribute, StringFieldAttribute, BooleanFieldAttribute)\n\n- TagFieldAttribute\n\n- TimestampFieldAttribute, DateTimeFieldAttribute\n\nParser Classes :\n\n- MeasurementPointSerializer (default)\n\n- JsonSerializer\n\n- FormattedSerieSerializer\n\n- FlatFormattedSerieSerializer\n\n- FlatSimpleResultSerializer\n\n- PandasSerializer\n\nSimple Measurement\n~~~~~~~~~~~~~~~~~~\n\n.. code:: python\n\n from influxable.measurement import SimpleMeasurement\n\n my_measurement = SimpleMeasurement('temperature', ['value'], ['phase'])\n\nInstanciation\n~~~~~~~~~~~~~\n\n.. code:: python\n\n point = TemperatureMeasurement(\n time=1568970572,\n phase=\"HOT\",\n value=23.5,\n )\n\nQuery\n~~~~~\n\nYou can query with *Measurement.get\\_query()* :\n\n.. code:: python\n\n from influxable.db import Field\n\n points = TemperatureMeasurement\\\n .get_query()\\\n .select('phase', 'value')\\\n .where(\n Field('value') > 15.2,\n Field('value') < 30.5,\n )\\\n .limit(100)\n .evaluate()\n\nYou can also query with *Query* :\n\n.. code:: python\n\n from influxable.db import Query, Field\n\n points = Query()\\\n .select('phase', 'value')\\\n .from_measurements('temperature')\\\n .where(\n Field('value') > 15.2,\n Field('value') < 30.5,\n )\\\n .limit(100)\n .execute()\n\nSaving Data\n~~~~~~~~~~~\n\nYou can create data by using *Measurement.bulk\\_save()*\n\n.. code:: python\n\n points = [\n TemperatureMeasurement(phase=\"HOT\",value=10,time=1463289075),\n TemperatureMeasurement(phase=\"COLD\",value=10,time=1463289076),\n ]\n TemperatureMeasurement.bulk_save(points)\n\nYou can also create data with *BulkInsertQuery*\n\n.. code:: python\n\n str_query = '''\n temperature,phase=HOT value=10 1463289075000000000\n temperature,phase=COLD value=10 1463289076000000000\n '''\n\n raw_query = BulkInsertQuery(str_query)\n res = raw_query.execute()\n\nIntegration with OSS 2.0 (Experimental)\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n.. code:: bash\n\n # Create the user\n influx user create --name admin -- password admin\n\n # Create the auth (in order to retrieve the token)\n influx auth create --user admin --operator\n\n # List yours tokens\n influx auth list\n\n # (Optional) export the INFLUXDB_AUTH_TOKEN\n INFLUXDB_AUTH_TOKEN=my-token\n\n # Create the config\n influx config create --config-name defaut --host-url http://localhost:8086 --token NjIYagimNbX5MaZfisDsvuGGvtULdqIY-Wt8EP4eGk-3P9KftDtZjxXU4GocTMTfM0eglkuFJQyA9uF82ZeEoA== --org MyOrganisation\n\n # Create the bucket\n influx bucket create --name default\n\n # List your bucket\n influx bucket list\n\n ID Name Retention Shard group duration Organization ID Schema Type\n 4688727b9c388f5f default infinite 168h0m0s b89cbec9670f29f8 implicit\n\n # Create the dbrp (link database api v1 with bucket api v2)\n influx v1 dbrp create --db default --rp default --bucket-id 4688727b9c388f5f --default\n\nAuto Generation of Measurements\n-------------------------------\n\nYou can automatically generate measurement classes file with the bash command *autogenerate*\n\n.. code:: bash\n\n influxable autogenerate #(default to auto_generate_measurement.py)\n influxable autogenerate -o measurement.py\n\nHere is the output generated file :\n\n.. code:: python\n\n # auto_generate_measurement.py\n\n from influxable import attributes\n from influxable.measurement import Measurement\n\n\n class CpuMeasurement(Measurement):\n measurement_name = 'cpu'\n\n time = attributes.TimestampFieldAttribute(precision='s')\n value = attributes.FloatFieldAttribute()\n host = attributes.TagFieldAttribute()\n\nInfluxable commands\n-------------------\n\n- *autogenerate* : automatic generation of measurement classes\n\n.. code:: bash\n\n influxable autogenerate #(default to auto_generate_measurement.py)\n influxable autogenerate -o measurement.py\n\n- *populate* : create a measurement filled with a set of random data\n\n.. code:: bash\n\n influxable populate\n influxable populate --min_value 5 --max_value 35 -s 2011-01-01T00:00:00 -id 1\n influxable populate --help\n\nInfluxable API\n--------------\n\nInfluxable Class\n~~~~~~~~~~~~~~~~\n\nThe Influxable main app class is a singleton. You can access it via the method *Influxable.get\\_instance()*\n\n\\_\\_init\\_\\_():\n^^^^^^^^^^^^^^^\n\n- base\\_url : url to connect to the InfluxDB server (default = 'http://localhost:8086')\n\n- user : authentication user name (default = 'admin')\n\n- password : authentication user password (default = 'changeme')\n\n- database\\_name : name of the database (default = 'default')\n\ncreate\\_connection() -> Connection:\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\n- base\\_url : url to connect to the InfluxDB server (default = 'http://localhost:8086')\n\n- user : authentication user name (default = 'admin')\n\n- password : authentication user password (default = 'changeme')\n\n- database\\_name : name of the database (default = 'default')\n\nping() -> bool:\n^^^^^^^^^^^^^^^\n\n- verbose : enables verbose mode (default = True)\n\nexecute\\_query() -> json():\n^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\n- query: influxdb query to execute\n- method: http method of the request (default='get')\n- chunked: if enabled, responses will be chunked by series or by every 10,000 points (default=False)\n- epoch: specified precision of the timestamp [ns,u,\u00b5,ms,s,m,h] (default='ns')\n- pretty: if enadble, the json response is pretty-printed (default=False)\n\nwrite\\_points() -> bool:\n^^^^^^^^^^^^^^^^^^^^^^^^\n\n- points: data to write in InfluxDB line protocol format\n\nex: mymeas,mytag1=1 value=21 1463689680000000000\n\n- precision: specified precision of the timestamp [ns,u,\u00b5,ms,s,m,h] (default='ns')\n- consistency: sets the write consistency for the point [any,one,quorum,all] (default='all')\n- retention\\_policy\\_name: sets the target retention policy for the write (default='DEFAULT')\n\nInfluxDBApi Class\n~~~~~~~~~~~~~~~~~\n\nget\\_debug\\_requests() -> bool:\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\n- request : instance of InfluxDBRequest\n\nget\\_debug\\_vars() -> bool:\n^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\n- request : instance of InfluxDBRequest\n\nping() -> bool:\n^^^^^^^^^^^^^^^\n\n- request : instance of InfluxDBRequest\n\n- verbose : enables verbose mode (default = True)\n\nexecute\\_query() -> json():\n^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\n- request : instance of InfluxDBRequest\n- query: influxdb query to execute\n- method: http method of the request (default='get')\n- chunked: if enabled, responses will be chunked by series or by every 10,000 points (default=False)\n- epoch: specified precision of the timestamp [ns,u,\u00b5,ms,s,m,h] (default='ns')\n- pretty: if enadble, the json response is pretty-printed (default=False)\n\nwrite\\_points() -> bool:\n^^^^^^^^^^^^^^^^^^^^^^^^\n\n- request : instance of InfluxDBRequest\n\n- points: data to write in InfluxDB line protocol format\n\nex: mymeas,mytag1=1 value=21 1463689680000000000\n\n- precision: specified precision of the timestamp [ns,u,\u00b5,ms,s,m,h] (default='ns')\n- consistency: sets the write consistency for the point [any,one,quorum,all] (default='all')\n- retention\\_policy\\_name: sets the target retention policy for the write (default='DEFAULT')\n\nConnection Class\n~~~~~~~~~~~~~~~~\n\n\\_\\_init\\_\\_():\n^^^^^^^^^^^^^^^\n\n- base\\_url : url to connect to the InfluxDB server (default = 'http://localhost:8086')\n\n- user : authentication user name (default = 'admin')\n\n- password : authentication user password (default = 'changeme')\n\n- database\\_name : name of the database (default = 'default')\n\ncreate() -> Connection:\n^^^^^^^^^^^^^^^^^^^^^^^\n\n- base\\_url : url to connect to the InfluxDB server (default = 'http://localhost:8086')\n\n- user : authentication user name (default = 'admin')\n\n- password : authentication user password (default = 'changeme')\n\n- database\\_name : name of the database (default = 'default')\n\nMeasurement Class\n~~~~~~~~~~~~~~~~~\n\nfields\n^^^^^^\n\nMust be an instance of class located in *influxable.attributes*\n\n- GenericFieldAttribute\n\n- IntegerFieldAttribute\n\n- FloatFieldAttribute\n\n- StringFieldAttribute\n\n- BooleanFieldAttribute\n\n- TagFieldAttribute\n\n- TimestampFieldAttribute\n\n- DateTimeFieldAttribute\n\nExample :\n\n.. code:: python\n\n class MySensorMeasurement(Measurement):\n measurement_name = 'mysensor'\n\n time = TimestampFieldAttribute(auto_now=True, precision='s')\n phase = TagFieldAttribute()\n value = IntegerFieldAttribute()\n\nparser\\_class\n^^^^^^^^^^^^^\n\nMust be a class of *influxable.serializers* :\n\n- MeasurementPointSerializer (default)\n\n- JsonSerializer\n\n- FormattedSerieSerializer\n\n- FlatFormattedSerieSerializer\n\n- FlatSimpleResultSerializer\n\n- PandasSerializer\n\nmeasurement\\_name\n^^^^^^^^^^^^^^^^^\n\nName of the measurement in InfluxDB\n\n\\_\\_init\\_\\_():\n^^^^^^^^^^^^^^^\n\nSet the attribute value of a Measurement\n\nExample\n\n.. code:: python\n\n point = MySensorMeasurement(value=0.5, phase=\"MOON\")\n\nget\\_query() -> Query:\n^^^^^^^^^^^^^^^^^^^^^^\n\nReturn an instance of Query which\n\nExample\n\n.. code:: python\n\n points = MySensorMeasurement\\\n .get_query()\\\n .select()\\\n .where()\\\n .limit()\\\n .evaluate()\n\ndict()\n^^^^^^\n\nReturn a dict of the point values\n\nExample\n\n.. code:: python\n\n point = MySensorMeasurement(value=0.5, phase=\"MOON\")\n\n point.dict()\n\n # {'time': Decimal('1568970572'), 'phase': 'MOON', 'value': 0.5}\n\nitems()\n^^^^^^^\n\nReturn an item list of the point values\n\nExample\n\n.. code:: python\n\n point = MySensorMeasurement(value=0.5, phase=\"MOON\")\n\n point.items()\n\n # dict_items([('time', Decimal('1568970572')), ('phase', 'MOON'), ('value', 0.5)])\n\nbulk\\_save()\n^^^^^^^^^^^^\n\nSave a list of measurement point\n\n.. code:: python\n\n points = [\n MySensorMeasurement(phase=\"moon\",value=5,time=1463489075),\n MySensorMeasurement(phase=\"moon\",value=7,time=1463489076),\n MySensorMeasurement(phase=\"sun\",value=8,time=1463489077),\n ]\n MySensorMeasurement.bulk_save(points)\n\nAttributes\n~~~~~~~~~~\n\nGenericFieldAttribute\n^^^^^^^^^^^^^^^^^^^^^\n\n- attribute\\_name : real name of the measurement attribute in database\n\n- default : set a default value if it is not filled at the instanciation\n\n- is\\_nullable : if False, it will raise an error if the value is null (default=True)\n\n- enforce\\_cast : if False, it will not raise an error when the value has not the desired type without casting (default=True).\n\n.. code:: python\n\n class MySensorMeasurement(Measurement):\n measurement_name = 'mysensor'\n\n temperature_value = GenericFieldAttribute(\n attribute_name=\"temp_v1\",\n default=\"15\",\n is_nullable=True,\n enforce_cast=False,\n )\n\nIntegerFieldAttribute\n^^^^^^^^^^^^^^^^^^^^^\n\n- min\\_value : an error is raised if the value is less than the min\\_value\n\n- max\\_value : an error is raised if the value is greater than the max\\_value\n\n- attribute\\_name : real name of the measurement attribute in database\n\n- default : set a default value if it is not filled at the instanciation\n\n- is\\_nullable : if False, it will raise an error if the value is null (default=True)\n\n- enforce\\_cast : if False, it will not raise an error when the value has not the desired type without casting (default=True).\n\n.. code:: python\n\n class MySensorMeasurement(Measurement):\n measurement_name = 'mysensor'\n\n temperature_value = IntegerFieldAttribute(\n min_value=10,\n max_value=30,\n )\n\nFloatFieldAttribute\n^^^^^^^^^^^^^^^^^^^\n\n- max\\_nb\\_decimals : set the maximal number of decimals to display\n\n- min\\_value : an error is raised if the value is less than the min\\_value\n\n- max\\_value : an error is raised if the value is greater than the max\\_value\n\n- attribute\\_name : real name of the measurement attribute in database\n\n- default : set a default value if it is not filled at the instanciation\n\n- is\\_nullable : if False, it will raise an error if the value is null (default=True)\n\n- enforce\\_cast : if False, it will not raise an error when the value has not the desired type without casting (default=True).\n\n.. code:: python\n\n class MySensorMeasurement(Measurement):\n measurement_name = 'mysensor'\n\n value = FloatFieldAttribute(\n max_nb_decimals=5,\n )\n\nStringFieldAttribute\n^^^^^^^^^^^^^^^^^^^^\n\n- choices : an error is raised if the value is not in the list of string options\n\n- max\\_length : an error is raised if the string value length is greater than the max\\_length\n\n- attribute\\_name : real name of the measurement attribute in database\n\n- default : set a default value if it is not filled at the instanciation\n\n- is\\_nullable : if False, it will raise an error if the value is null (default=True)\n\n- enforce\\_cast : if False, it will not raise an error when the value has not the desired type without casting (default=True).\n\n.. code:: python\n\n class MySensorMeasurement(Measurement):\n measurement_name = 'mysensor'\n\n position = FloatFieldAttribute(\n choices=['first', 'last'],\n max_length=7,\n )\n\nBooleanFieldAttribute\n^^^^^^^^^^^^^^^^^^^^^\n\n- attribute\\_name : real name of the measurement attribute in database\n\n- default : set a default value if it is not filled at the instanciation\n\n- is\\_nullable : if False, it will raise an error if the value is null (default=True)\n\n- enforce\\_cast : if False, it will not raise an error when the value has not the desired type without casting (default=True).\n\n.. code:: python\n\n class MySensorMeasurement(Measurement):\n measurement_name = 'mysensor'\n\n is_marked = BooleanFieldAttribute(\n default=False,\n )\n\nTagFieldAttribute\n^^^^^^^^^^^^^^^^^\n\n- attribute\\_name : real name of the measurement attribute in database\n\n- default : set a default value if it is not filled at the instanciation\n\n- is\\_nullable : if False, it will raise an error if the value is null (default=True)\n\n- enforce\\_cast : if False, it will not raise an error when the value has not the desired type without casting (default=True).\n\n.. code:: python\n\n class MySensorMeasurement(Measurement):\n measurement_name = 'mysensor'\n\n phase = TagFieldAttribute(\n default='MOON',\n )\n\nTimestampFieldAttribute\n^^^^^^^^^^^^^^^^^^^^^^^\n\n- auto\\_now : Set automatically the current date (default=False)\n\n- precision : Set the timestamp precision which must be one of [ns,u,ms,s,m,h] (default= 'ns')\n\n- attribute\\_name : real name of the measurement attribute in database\n\n- default : set a default value if it is not filled at the instanciation\n\n- is\\_nullable : if False, it will raise an error if the value is null (default=True)\n\n- enforce\\_cast : if False, it will not raise an error when the value has not the desired type without casting (default=True).\n\n.. code:: python\n\n class MySensorMeasurement(Measurement):\n measurement_name = 'mysensor'\n\n time = TimestampFieldAttribute(\n auto_now=True,\n precision='s',\n )\n\nDateTimeFieldAttribute\n^^^^^^^^^^^^^^^^^^^^^^\n\n- str\\_format : Set the arrow format of the timestamp to display (default: \"YYYY-MM-DD HH:mm:ss\")\n\n- auto\\_now : Set automatically the current date\n\n- precision : Set the timestamp precision which must be one of [ns,u,ms,s,m,h]\n\n- attribute\\_name : real name of the measurement attribute in database\n\n- default : set a default value if it is not filled at the instanciation\n\n- is\\_nullable : if False, it will raise an error if the value is null (default=True)\n\n- enforce\\_cast : if False, it will not raise an error when the value has not the desired type without casting (default=True).\n\n.. code:: python\n\n class MySensorMeasurement(Measurement):\n measurement_name = 'mysensor'\n\n date = DateTimeFieldAttribute(\n attribute_name='time',\n auto_now=True,\n str_format='YYYY-MM-DD',\n )\n\nInfluxDBResponse\n~~~~~~~~~~~~~~~~\n\n\\_\\_init\\_\\_():\n^^^^^^^^^^^^^^^\n\n- raw\\_json : the raw json response object\n\nraw\n^^^\n\nReturn the raw\\_json value\n\nmain\\_serie\n^^^^^^^^^^^\n\nReturn the first serie from the *series* field in the raw\\_json value\n\nseries\n^^^^^^\n\nReturn the *series* field in the raw\\_json value\n\nerror\n^^^^^\n\nReturn the *error* field in the raw\\_json value\n\nExample of json raw response :\n\n.. code:: python\n\n {\n \"results\":[\n {\n \"statement_id\":0,\n \"series\":[\n {\n \"name\":\"mymeas\",\n \"columns\":[\n \"time\",\n \"myfield\",\n \"mytag1\",\n \"mytag2\"\n ],\n \"values\":[\n [\n \"2017-03-01T00:16:18Z\",\n 33.1,\n null,\n null\n ],\n [\n \"2017-03-01T00:17:18Z\",\n 12.4,\n \"12\",\n \"14\"\n ]\n ]\n }\n ]\n }\n ]\n }\n\nSerializers\n~~~~~~~~~~~\n\nSerializers can be used in *parser\\_class* field of *Measurement* class.\n\n.. code:: python\n\n class MySensorMeasurement(Measurement):\n measurement_name = 'mysensor'\n parser_class = serializers.BaseSerializer\n\nIt allow to change the output response format of a influxb request\n\n.. code:: python\n\n # res is formatted with BaseSerializer\n res = MySensorMeasurement.get_query().limit(10).evaluate()\n\nBaseSerializer\n^^^^^^^^^^^^^^\n\n.. code:: python\n\n # res is formatted with BaseSerializer\n res\n {'results': [{'statement_id': 0, 'series': [{'name': 'mysamplemeasurement', 'columns': ['time', 'value'], 'values': [[1570481055000000000, 10], [1570481065000000000, 20], [1570481075000000000, 30]]}]}]}\n\nJsonSerializer\n^^^^^^^^^^^^^^\n\n.. code:: python\n\n # res is formatted with JsonSerializer\n res\n '{\"results\": [{\"statement_id\": 0, \"series\": [{\"name\": \"mysamplemeasurement\", \"columns\": [\"time\", \"value\"], \"values\": [[1570481055000000000, 10], [1570481065000000000, 20], [1570481075000000000, 30]]}]}]}'\n\nFormattedSerieSerializer\n^^^^^^^^^^^^^^^^^^^^^^^^\n\n.. code:: python\n\n # res is formatted with FormattedSerieSerializer\n res\n [{'mysamplemeasurement': [{'time': 1570481055000000000, 'value': 10}, {'time': 1570481065000000000, 'value': 20}, {'time': 1570481075000000000, 'value': 30}]}]\n\nFlatFormattedSerieSerializer\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\n.. code:: python\n\n # res is formatted with FlatFormattedSerieSerializer\n [{'time': 1570481055000000000, 'value': 10}, {'time': 1570481065000000000, 'value': 20}, {'time': 1570481075000000000, 'value': 30}]\n\nFlatSimpleResultSerializer\n^^^^^^^^^^^^^^^^^^^^^^^^^^\n\nThis serializer is used only when the result set contains only one column\n\n.. code:: python\n\n res = InfluxDBAdmin.show_databases()\n\n # res is formatted with FlatSimpleResultSerializer\n res\n ['_internal', 'example', 'test', 'telegraf', 'mydb', ...]\n\nFlatSingleValueSerializer\n^^^^^^^^^^^^^^^^^^^^^^^^^\n\nThis serializer is used only when the result set contains only one value\n\n.. code:: python\n\n res = InfluxDBAdmin.show_measurement_cardinality()\n\n # res is formatted with FlatSingleValueSerializer\n res\n 2\n\nPandasSerializer\n^^^^^^^^^^^^^^^^\n\n.. code:: python\n\n # res is formatted with PandasSerializer\n res time value\n 0 1570481055000000000 10\n 1 1570481065000000000 20\n 2 1570481075000000000 30\n\nMeasurementPointSerializer\n^^^^^^^^^^^^^^^^^^^^^^^^^^\n\nThis is the default serializer class for Measurement\n\n.. code:: python\n\n [<MySensorMeasurement object at 0x7f49a16227f0>, <MySensorMeasurement object at 0x7f49a16228d0>, <MySensorMeasurement object at 0x7f49a1622438>]\n\nRaw Query\n~~~~~~~~~\n\n- str\\_query\n\nExample :\n\n.. code:: python\n\n from influxable.db import RawQuery\n str_query = 'SHOW DATABASES'\n res = RawQuery(str_query).execute()\n\n.. code:: python\n\n from influxable.db import RawQuery\n str_query = 'SELECT * FROM temperature LIMIT 10'\n res = RawQuery(str_query).execute()\n\nQuery Class\n~~~~~~~~~~~\n\nYou can generate an instance of Query via the initial Query constructor or from a measurement.\n\nExample :\n\n.. code:: python\n\n from influxable.db import Query\n query = Query()\n ...\n\n.. code:: python\n\n query = MySensorMeasurement.get_query()\n ...\n\nMethods :\n\nfrom\\_measurements()\n^^^^^^^^^^^^^^^^^^^^\n\n- \\*measurements\n\nExample :\n\n.. code:: python\n\n query = Query()\\\n .from_measurements('measurement1', 'measurement2')\n\nRender :\n\n.. code:: sql\n\n FROM measurement1, measurement2\n\nselect()\n^^^^^^^^\n\n- \\*fields\n\nExample :\n\n.. code:: python\n\n query = Query()\\\n .select('param1', 'param2')\\\n .from_measurements('measurement1')\n\nRender :\n\n.. code:: sql\n\n SELECT value, phase\n\nwhere()\n^^^^^^^\n\n- \\*criteria\n\nExample :\n\n.. code:: python\n\n from influxable.db import Query, Field\n query = Query()\\\n .select('param1', 'param2')\\\n .from_measurements('measurement1')\\\n .where(\n Field('param1') > 800,\n Field('param1') < 900,\n )\n\nRender :\n\n.. code:: sql\n\n WHERE param1 > 800 AND param1 < 900\n\nlimit()\n^^^^^^^\n\n- value\n\nExample :\n\n.. code:: python\n\n from influxable.db import Query, Field\n query = Query()\\\n .select('param1', 'param2')\\\n .from_measurements('measurement1')\\\n .where(\n Field('param1') > 800,\n Field('param1') < 900,\n )\\\n .limit(10)\n\nRender :\n\n.. code:: sql\n\n LIMIT 10\n\nslimit()\n^^^^^^^^\n\n- value\n\nExample :\n\n.. code:: python\n\n from influxable.db import Query, Field\n query = Query()\\\n .select('param1', 'param2')\\\n .from_measurements('measurement1')\\\n .where(\n Field('param1') > 800,\n Field('param1') < 900,\n )\\\n .limit(10)\\\n .slimit(5)\n\nRender :\n\n.. code:: sql\n\n SLIMIT 5\n\noffset()\n^^^^^^^^\n\n- value\n\nExample :\n\n.. code:: python\n\n from influxable.db import Query, Field\n query = Query()\\\n .select('param1', 'param2')\\\n .from_measurements('measurement1')\\\n .where(\n Field('param1') > 800,\n Field('param1') < 900,\n )\\\n .offset(10)\n\nRender :\n\n.. code:: sql\n\n OFFSET 10\n\nsoffset()\n^^^^^^^^^\n\n- value\n\nExample :\n\n.. code:: python\n\n from influxable.db import Query, Field\n query = Query()\\\n .select('param1', 'param2')\\\n .from_measurements('measurement1')\\\n .where(\n Field('param1') > 800,\n Field('param1') < 900,\n )\\\n .offset(10)\\\n .soffset(5)\n\nRender :\n\n.. code:: sql\n\n SOFFSET 5\n\ninto()\n^^^^^^\n\n- \\*measurement\n\nExample :\n\n.. code:: python\n\n query = Query()\\\n .select('param1')\\\n .from_measurements('measurement1')\\\n .into('measurement2')\n\nRender :\n\n.. code:: sql\n\n SELECT param1 INTO measurement2 FROM measurement1\n\nasc()\n^^^^^\n\nExample :\n\n.. code:: python\n\n query = Query()\\\n .select('param1')\\\n .from_measurements('measurement1')\\\n .asc()\n\nRender :\n\n.. code:: sql\n\n SELECT param1 FROM measurement1 ORDER BY ASC\n\ndesc()\n^^^^^^\n\nExample :\n\n.. code:: python\n\n query = Query()\\\n .select('param1')\\\n .from_measurements('measurement1')\\\n .desc()\n\nRender :\n\n.. code:: sql\n\n SELECT param1 FROM measurement1 ORDER BY DESC\n\ntz()\n^^^^\n\nExample :\n\n.. code:: python\n\n query = Query()\\\n .select('param1')\\\n .from_measurements('measurement1')\\\n .tz('Europe/Paris')\n\nRender :\n\n.. code:: sql\n\n SELECT param1 FROM measurement1 tz('Europe/Paris')\n\ngroup\\_by()\n^^^^^^^^^^^\n\n- \\*tags\n\nExample :\n\n.. code:: python\n\n query = Query()\\\n .select('param1')\\\n .from_measurements('measurement1')\\\n .group_by('tag_1')\n\nRender :\n\n.. code:: sql\n\n SELECT param1 FROM measurement1 GROUP BY tag_1\n\nrange\\_by()\n^^^^^^^^^^^\n\n- \\*interval\n- \\*shift\n- \\*fill\n- \\*tags\n\nExample :\n\n.. code:: python\n\n query = Query()\\\n .select('param1')\\\n .from_measurements('measurement1')\\\n .range_by('12s', shift='1d', tags=['tag1'], fill=3)\n\nRender :\n\n.. code:: sql\n\n SELECT param1 FROM measurement1 GROUP BY time(12s,1d),tag1 fill(3)'\n\nexecute()\n^^^^^^^^^\n\nExecute the query and return the response\n\nExample :\n\n.. code:: python\n\n from influxable.db import Query, Field\n res = Query()\\\n .select('param1', 'param2')\\\n .from_measurements('measurement1')\\\n .where(\n Field('param1') > 800,\n Field('param1') < 900,\n )\\\n .execute()\n res\n\nResult :\n\n.. code:: python\n\n {'results': [{'statement_id': 0, 'series': [{'name': 'measurement1', 'columns': ['time', 'value'], 'values': [[1570481055000000000, 10], [1570481065000000000, 20], [1570481075000000000, 30]]}]}]}\n\nevaluate()\n^^^^^^^^^^\n\nExecute the query and return the serialized response\n\n- parser\\_class (default=BaseSerializer for Query and MeasurementPointSerializer for Measurement)\n\nExample with Query :\n\n.. code:: python\n\n from influxable.db import Query, Field\n res = Query()\\\n .select('param1', 'param2')\\\n .from_measurements('measurement1')\\\n .where(\n Field('param1') > 800,\n Field('param1') < 900,\n )\\\n .evaluate()\n res\n\nResult :\n\n.. code:: python\n\n {'results': [{'statement_id': 0, 'series': [{'name': 'measurement1', 'columns': ['time', 'value'], 'values': [[1570481055000000000, 10], [1570481065000000000, 20], [1570481075000000000, 30]]}]}]}\n\nExample with Measurement :\n\n.. code:: python\n\n from influxable.db import Field\n points = MySensorMeasurement.get_query()\n .select('param1', 'param2')\\\n .from_measurements('measurement1')\\\n .where(\n Field('param1') > 800,\n Field('param1') < 900,\n )\\\n .evaluate()\n points\n\nResult :\n\n.. code:: python\n\n [<MySensorMeasurement object at 0x7f49a16227f0>, <MySensorMeasurement object at 0x7f49a16228d0>, <MySensorMeasurement object at 0x7f49a1622438>]\n\ncount()\n^^^^^^^\n\n- value (default='\\*')\n\nExample :\n\n.. code:: python\n\n from influxable.db import Query, Field\n query = Query()\\\n .from_measurements('measurement1')\\\n .where(\n Field('param1') > 800,\n Field('param1') < 900,\n )\\\n .count()\n\nRender :\n\n.. code:: sql\n\n SELECT COUNT(*)\n\ndistinct()\n^^^^^^^^^^\n\n- value (default='\\*')\n\nExample :\n\n.. code:: python\n\n from influxable.db import Query, Field\n query = Query()\\\n .from_measurements('measurement1')\\\n .where(\n Field('param1') > 800,\n Field('param1') < 900,\n )\\\n .distinct()\n\nRender :\n\n.. code:: sql\n\n SELECT DISTINCT(*)\n\nintegral()\n^^^^^^^^^^\n\n- value (default='\\*')\n\nExample :\n\n.. code:: python\n\n from influxable.db import Query, Field\n query = Query()\\\n .from_measurements('measurement1')\\\n .where(\n Field('param1') > 800,\n Field('param1') < 900,\n )\\\n .integral()\n\nRender :\n\n.. code:: sql\n\n SELECT INTEGRAL(*)\n\nmean()\n^^^^^^\n\n- value (default='\\*')\n\nExample :\n\n.. code:: python\n\n from influxable.db import Query, Field\n query = Query()\\\n .from_measurements('measurement1')\\\n .where(\n Field('param1') > 800,\n Field('param1') < 900,\n )\\\n .mean()\n\nRender :\n\n.. code:: sql\n\n SELECT MEAN(*)\n\nmedian()\n^^^^^^^^\n\n- value (default='\\*')\n\nExample :\n\n.. code:: python\n\n from influxable.db import Query, Field\n query = Query()\\\n .from_measurements('measurement1')\\\n .where(\n Field('param1') > 800,\n Field('param1') < 900,\n )\\\n .median()\n\nRender :\n\n.. code:: sql\n\n SELECT MEDIAN(*)\n\nmode()\n^^^^^^\n\n- value (default='\\*')\n\nExample :\n\n.. code:: python\n\n from influxable.db import Query, Field\n query = Query()\\\n .from_measurements('measurement1')\\\n .where(\n Field('param1') > 800,\n Field('param1') < 900,\n )\\\n .mode()\n\nRender :\n\n.. code:: sql\n\n SELECT MODE(*)\n\nspread()\n^^^^^^^^\n\n- value (default='\\*')\n\nExample :\n\n.. code:: python\n\n from influxable.db import Query, Field\n query = Query()\\\n .from_measurements('measurement1')\\\n .where(\n Field('param1') > 800,\n Field('param1') < 900,\n )\\\n .spread()\n\nRender :\n\n.. code:: sql\n\n SELECT SPREAD(*)\n\nstd\\_dev()\n^^^^^^^^^^\n\n- value (default='\\*')\n\nExample :\n\n.. code:: python\n\n from influxable.db import Query, Field\n query = Query()\\\n .from_measurements('measurement1')\\\n .where(\n Field('param1') > 800,\n Field('param1') < 900,\n )\\\n .std_dev()\n\nRender :\n\n.. code:: sql\n\n SELECT STDDEV(*)\n\nsum()\n^^^^^\n\n- value (default='\\*')\n\nExample :\n\n.. code:: python\n\n from influxable.db import Query, Field\n query = Query()\\\n .from_measurements('measurement1')\\\n .where(\n Field('param1') > 800,\n Field('param1') < 900,\n )\\\n .sum()\n\nRender :\n\n.. code:: sql\n\n SELECT SUM(*)\n\nQuery aggregations function\n~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nUsage :\n\n.. code:: python\n\n from influxable.db.function import aggregations\n res = Query()\\\n .select(aggregations.Sum('value'))\\\n .from_measurements('param1')\\\n .execute()\n\nCount\n^^^^^\n\nDistinct\n^^^^^^^^\n\nIntegral\n^^^^^^^^\n\nMean\n^^^^\n\nMedian\n^^^^^^\n\nMode\n^^^^\n\nSpread\n^^^^^^\n\nStdDev\n^^^^^^\n\nSum\n^^^\n\nQuery selectors function\n~~~~~~~~~~~~~~~~~~~~~~~~\n\nUsage :\n\n.. code:: python\n\n from influxable.db.function import selectors\n res = Query()\\\n .select(selectors.Min('value'), selectors.Max('value'))\\\n .from_measurements('param1')\\\n .execute()\n\nBottom\n^^^^^^\n\nFirst\n^^^^^\n\nLast\n^^^^\n\nMax\n^^^\n\nMin\n^^^\n\nPercentile\n^^^^^^^^^^\n\nSample\n^^^^^^\n\nTop\n^^^\n\nQuery transformations function\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nUsage :\n\n.. code:: python\n\n from influxable.db.function import selectors, transformations\n res = Query()\\\n .select(transformations.Abs('value'))\\\n .from_measurements('param1')\\\n .execute()\n\n.. code:: python\n\n from influxable.db.function.selectors import Min, Max\n from influxable.db.function.transformations import Abs\n res = Query()\\\n .select(Abs(Min('value')), Abs(Max('value')))\\\n .from_measurements('param1')\\\n .execute()\n\nAbs\n^^^\n\nACos\n^^^^\n\nASin\n^^^^\n\nATan\n^^^^\n\nATan2\n^^^^^\n\nCeil\n^^^^\n\nCos\n^^^\n\nCumulativeSum\n^^^^^^^^^^^^^\n\nDerivative\n^^^^^^^^^^\n\nDifference\n^^^^^^^^^^\n\nElapsed\n^^^^^^^\n\nExp\n^^^\n\nFloor\n^^^^^\n\nHistogram\n^^^^^^^^^\n\nLn\n^^\n\nLog\n^^^\n\nLog2\n^^^^\n\nLog10\n^^^^^\n\nMovingAverage\n^^^^^^^^^^^^^\n\nNonNegativeDerivative\n^^^^^^^^^^^^^^^^^^^^^\n\nNonNegativeDifference\n^^^^^^^^^^^^^^^^^^^^^\n\nPow\n^^^\n\nRound\n^^^^^\n\nSin\n^^^\n\nSqrt\n^^^^\n\nTan\n^^^\n\nInfluxDBAdmin\n~~~~~~~~~~~~~\n\nalter\\_retention\\_policy()\n^^^^^^^^^^^^^^^^^^^^^^^^^^\n\n- policy\\_name\n\n- duration (default=None)\n\n- replication (default=None)\n\n- shard\\_duration (default=None)\n\n- is\\_default (default=False)\n\n.. code:: sql\n\n ALTER RETENTION POLICY {policy_name} ON {database_name} [DURATION {duration} REPLICATION {replication} SHARD DURATION {shard_duration} DEFAULT]\n\ncreate\\_database()\n^^^^^^^^^^^^^^^^^^\n\n- new\\_database\\_name\n\n- duration (default=None)\n\n- replication (default=None)\n\n- shard\\_duration (default=None)\n\n- policy\\_name (default=False)\n\n.. code:: sql\n\n CREATE DATABASE {new_database_name} [WITH DURATION {duration} REPLICATION {replication} SHARD DURATION {shard_duration} NAME {policy_name}]\n\ncreate\\_retention\\_policy()\n^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\n- policy\\_name\n\n- duration (default=None)\n\n- replication (default=None)\n\n- shard\\_duration (default=None)\n\n- is\\_default (default=False)\n\n.. code:: sql\n\n CREATE RETENTION POLICY {policy_name} ON {database_name} [DURATION {duration} REPLICATION {replication} SHARD DURATION {shard_duration} DEFAULT]\n\ncreate\\_subscription()\n^^^^^^^^^^^^^^^^^^^^^^\n\n- subscription\\_name\n\n- hosts\n\n- any (default=False)\n\n.. code:: sql\n\n CREATE SUBSCRIPTION {subscription_name} ON {database_name} DESTINATIONS ANY/ALL {hosts}\n\ncreate\\_user()\n^^^^^^^^^^^^^^\n\n- user\\_name\n\n- password\n\n- with\\_privileges (default=False)\n\n.. code:: sql\n\n CREATE USER {user_name} WITH PASSWORD {password} [WITH ALL PRIVILEGES]\n\ndelete()\n^^^^^^^^\n\n- measurements (default=[])\n\n- criteria (default=[])\n\n.. code:: sql\n\n DELETE FROM {measurements} WHERE {criteria}\n\ndrop\\_continuous\\_query()\n^^^^^^^^^^^^^^^^^^^^^^^^^\n\n- query\\_name\n\n.. code:: sql\n\n DROP CONTINUOUS QUERY {query_name} ON {database_name}\n\ndrop\\_database()\n^^^^^^^^^^^^^^^^\n\n- database\\_name\\_to\\_delete\n\n.. code:: sql\n\n DROP DATABASE {database_name_to_delete}\n\ndrop\\_measurement()\n^^^^^^^^^^^^^^^^^^^\n\n- measurement\\_name\n\n.. code:: sql\n\n DROP MEASUREMENT {measurement_name}\n\ndrop\\_retention\\_policy()\n^^^^^^^^^^^^^^^^^^^^^^^^^\n\n- policy\\_name\n\n.. code:: sql\n\n DROP RETENTION POLICY {policy_name} ON {database_name}\n\ndrop\\_series()\n^^^^^^^^^^^^^^\n\n- measurements (default=[])\n\n- criteria (default=[])\n\n.. code:: sql\n\n DROP SERIES FROM {measurements} WHERE {criteria}\n\ndrop\\_subscription()\n^^^^^^^^^^^^^^^^^^^^\n\n- subscription\\_name\n\n.. code:: sql\n\n DROP SUBSCRIPTION {subscription_name} ON {full_database_name}\n\ndrop\\_user()\n^^^^^^^^^^^^\n\n- user\\_name\n\n.. code:: sql\n\n DROP USER {user_name}\n\nexplain()\n^^^^^^^^^\n\n- query\n\n- analyze (default=False)\n\n.. code:: sql\n\n EXPLAIN [ANALYZE] {query}\n\ngrant()\n^^^^^^^\n\n- privilege\n\n- user\\_name\n\n.. code:: sql\n\n GRANT {privilege} ON {database_name} TO {user_name}\n\nkill()\n^^^^^^\n\n- query\\_id\n\n.. code:: sql\n\n KILL QUERY {query_id}\n\nrevoke()\n^^^^^^^^\n\n- privilege\n\n- user\\_name\n\n.. code:: sql\n\n REVOKE {privilege} ON {database_name} FROM {user_name}\n\nshow\\_field\\_key\\_cardinality()\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\n- exact (default=False)\n\n.. code:: sql\n\n SHOW FIELD KEY [EXACT] CARDINALITY\n\nshow\\_measurement\\_cardinality()\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\n- exact (default=False)\n\n.. code:: sql\n\n SHOW MEASUREMENT [EXACT] CARDINALITY\n\nshow\\_series\\_cardinality()\n^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\n- exact (default=False)\n\n.. code:: sql\n\n SHOW SERIES [EXACT] CARDINALITY\n\nshow\\_tag\\_key\\_cardinality()\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\n- key\n\n- exact (default=False)\n\n.. code:: sql\n\n SHOW TAG VALUES [EXACT] CARDINALITY WITH KEY = {key}\n\nshow\\_continuous\\_queries()\n^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\n.. code:: sql\n\n SHOW CONTINUOUS QUERIES\n\nshow\\_diagnostics()\n^^^^^^^^^^^^^^^^^^^\n\n.. code:: sql\n\n SHOW DIAGNOSTICS\n\nshow\\_field\\_keys()\n^^^^^^^^^^^^^^^^^^^\n\n- measurements (default=[])\n\n.. code:: sql\n\n SHOW FIELD KEYS FROM {measurements}\n\nshow\\_grants()\n^^^^^^^^^^^^^^\n\n- user\\_name\n\n.. code:: sql\n\n SHOW GRANTS FOR {user_name}\n\nshow\\_databases()\n^^^^^^^^^^^^^^^^^\n\n.. code:: sql\n\n SHOW DATABASES\n\nshow\\_measurements()\n^^^^^^^^^^^^^^^^^^^^\n\n- criteria (default=[])\n\n.. code:: sql\n\n SHOW MEASUREMENTS WHERE {criteria}\n\nshow\\_queries()\n^^^^^^^^^^^^^^^\n\n.. code:: sql\n\n SHOW QUERIES\n\nshow\\_retention\\_policies()\n^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\n.. code:: sql\n\n SHOW RETENTION POLICIES\n\nshow\\_series()\n^^^^^^^^^^^^^^\n\n- measurements (default=[])\n\n- criteria (default=[])\n\n- limit (default=None)\n\n- offset (default=None)\n\n.. code:: sql\n\n SHOW SERIES ON {database_name} [FROM {measurements} WHERE {criteria} LIMIT {limit} OFFSET {offset}]\n\nshow\\_stats()\n^^^^^^^^^^^^^\n\n.. code:: sql\n\n SHOW STATS\n\nshow\\_shards()\n^^^^^^^^^^^^^^\n\n.. code:: sql\n\n SHOW SHARDS\n\nshow\\_shard\\_groups()\n^^^^^^^^^^^^^^^^^^^^^\n\n.. code:: sql\n\n SHOW SHARD GROUPS\n\nshow\\_subscriptions()\n^^^^^^^^^^^^^^^^^^^^^\n\n.. code:: sql\n\n SHOW SUBSCRIPTIONS\n\nshow\\_tag\\_keys()\n^^^^^^^^^^^^^^^^^\n\n- measurements (default=[])\n\n.. code:: sql\n\n SHOW TAG KEYS [FROM {measurements}]\n\nshow\\_tag\\_values()\n^^^^^^^^^^^^^^^^^^^\n\n- key\n\n- measurements (default=[])\n\n.. code:: sql\n\n SHOW TAG VALUES [FROM {measurements}] WITH KEY = {key}\n\nshow\\_users()\n^^^^^^^^^^^^^\n\n.. code:: sql\n\n SHOW USERS\n\nExceptions\n~~~~~~~~~~\n\nInfluxDBException\n^^^^^^^^^^^^^^^^^\n\nInfluxDBError\n^^^^^^^^^^^^^\n\nInfluxDBConnectionError\n^^^^^^^^^^^^^^^^^^^^^^^\n\nInfluxDBInvalidResponseError\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\nInfluxDBInvalidChoiceError\n^^^^^^^^^^^^^^^^^^^^^^^^^^\n\nInfluxDBInvalidTypeError\n^^^^^^^^^^^^^^^^^^^^^^^^\n\nInfluxDBInvalidURLError\n^^^^^^^^^^^^^^^^^^^^^^^\n\nInfluxDBBadRequestError\n^^^^^^^^^^^^^^^^^^^^^^^\n\nInfluxDBBadQueryError\n^^^^^^^^^^^^^^^^^^^^^\n\nInfluxDBInvalidNumberError\n^^^^^^^^^^^^^^^^^^^^^^^^^^\n\nInfluxDBInvalidTimestampError\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\nInfluxDBUnauthorizedError\n^^^^^^^^^^^^^^^^^^^^^^^^^\n\nInfluxDBAttributeValueError\n^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\nTesting\n-------\n\nFirst, you need to install pytest via the file *requirements-test.txt*\n\n.. code:: bash\n\n pip install -r requirements-test.txt\n\nThen, you can launch the *pytest* command.\n\n.. code:: python\n\n pytest -v\n\nSupporting\n----------\n\nFeel free to post issues your feedback or if you reach a problem with influxable library.\n\nIf you want to contribute, please use the pull requests section.\n\nVersioning\n----------\n\nWe use `SemVer <http://semver.org/>`__ for versioning. For the versions available, see the `tags on this repository <https://github.com/Javidjms/influxable/releases>`__\n\nContributors\n------------\n\n- `Javid Mougamadou <https://github.com/Javidjms>`__\n\nCredits\n-------\n\n- Logo designed by `Maxime Bergerard <https://github.com/maximebergerard>`__\n\nReferences\n----------\n\n- `Influxdb Website <https://docs.influxdata.com/platform/introduction>`__\n\n- `Influxdb Github Repository <https://github.com/influxdata/influxdb>`__\n\n- `Influxdb-Python Github Repository <https://github.com/influxdata/influxdb-python>`__\n\nLicense\n-------\n\n`MIT <LICENSE.txt>`__\n\n.. |pypi version| image:: https://img.shields.io/badge/pypi-1.4.1-blue\n :target: https://pypi.org/project/influxable/\n.. |build status| image:: https://img.shields.io/badge/build-passing-green\n.. |code coverage| image:: https://img.shields.io/badge/coverage-100-green\n.. |license: MIT| image:: https://img.shields.io/badge/License-MIT-blue.svg\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "A lightweight python ORM / ODM for InfluxDB",
"version": "1.4.1",
"project_urls": {
"Download": "https://github.com/Javidjms/influxable/archive/1.4.1.zip",
"Homepage": "https://github.com/Javidjms/influxable",
"Source": "https://github.com/Javidjms/influxable"
},
"split_keywords": [
"python",
"influxdb",
"odm",
"orm",
"driver",
"client"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "045461663023a63cfe332ac51c3a49c9660ee9c64ed3733987318617997addc0",
"md5": "e12ca8704e4771393c704d388535c2c8",
"sha256": "bbc71c425bea3e70f1df31627b551a4968d0242c97ea148f0ebaa7167fb6b729"
},
"downloads": -1,
"filename": "influxable-1.4.1.tar.gz",
"has_sig": false,
"md5_digest": "e12ca8704e4771393c704d388535c2c8",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.4",
"size": 57603,
"upload_time": "2023-11-20T18:54:36",
"upload_time_iso_8601": "2023-11-20T18:54:36.285998Z",
"url": "https://files.pythonhosted.org/packages/04/54/61663023a63cfe332ac51c3a49c9660ee9c64ed3733987318617997addc0/influxable-1.4.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-11-20 18:54:36",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "Javidjms",
"github_project": "influxable",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [],
"lcname": "influxable"
}