{ "info": { "author": "", "author_email": "", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Topic :: Database", "Topic :: Software Development :: Libraries", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "influxdb-client-python\n======================\n\n.. marker-index-start\n\n.. image:: https://circleci.com/gh/influxdata/influxdb-client-python.svg?style=svg\n :target: https://circleci.com/gh/influxdata/influxdb-client-python\n :alt: CircleCI\n\n\n.. image:: https://codecov.io/gh/influxdata/influxdb-client-python/branch/master/graph/badge.svg\n :target: https://codecov.io/gh/influxdata/influxdb-client-python\n :alt: codecov\n\n.. image:: https://img.shields.io/circleci/project/github/influxdata/influxdb-client-python/master.svg\n :target: https://circleci.com/gh/influxdata/influxdb-client-python\n :alt: CI status\n\n.. image:: https://img.shields.io/codecov/c/github/influxdata/influxdb-client-python.svg\n :target: https://codecov.io/gh/influxdata/influxdb-client-python\n :alt: Coverage\n\n.. image:: https://img.shields.io/pypi/v/influxdb-client.svg\n :target: https://pypi.python.org/pypi/influxdb-python\n :alt: PyPI package\n\n.. image:: https://img.shields.io/pypi/pyversions/influxdb-client.svg\n :target: https://pypi.python.org/pypi/influxdb-client\n :alt: Supported Python versions\n\n.. image:: https://readthedocs.org/projects/influxdb-client/badge/?version=latest\n :target: https://influxdb-client.readthedocs.io/en/latest/?badge=latest\n :alt: Documentation status\n\n.. _documentation: https://influxdb-client.readthedocs.io\n\nInfluxDB 2.0 python client library. The library covers InfluxDB 2.0\n\nInfluxDB 2.0 client features\n----------------------------\n\n- Querying data\n - using the Flux language\n - into csv, raw data, `flux_table `_ structure\n- Writing data using\n - `Line Protocol `_\n - `Data Point `__\n - `RxPY`_ Observable\n - Not implemented yet\n - write user types using decorator\n - write Pandas DataFrame\n- `InfluxDB 2.0 API `_ client for management\n - the client is generated from the `swagger `_ by using the `openapi-generator `_\n - organizations & users management\n - buckets management\n - tasks management\n - authorizations\n - health check\n\nInstallation\n------------\n.. marker-install-start\n\nInfluxDB python library uses `RxPY `_ - The Reactive Extensions for Python (RxPY).\n\n**Python 3.6** or later is required.\n\n\npip install\n^^^^^^^^^^^\n\nThe python package is hosted on Github, you can install latest version directly:\n\n.. code-block:: sh\n\n pip3 install git+https://github.com/influxdata/influxdb-client-python.git\n\nThen import the package:\n\n.. code-block:: python\n\n import influxdb_client\n\nSetuptools\n^^^^^^^^^^\n\nInstall via `Setuptools `_.\n\n.. code-block:: sh\n\n python setup.py install --user\n\n(or ``sudo python setup.py install`` to install the package for all users)\n\n.. marker-install-end\n\nGetting Started\n---------------\n\nPlease follow the `Installation`_ and then run the following:\n\n.. marker-query-start\n\n.. code-block:: python\n\n from influxdb_client import InfluxDBClient, Point\n from influxdb_client.client.write_api import SYNCHRONOUS\n\n bucket = \"my-bucket\"\n\n client = InfluxDBClient(url=\"http://localhost:9999\", token=\"my-token\", org=\"my-org\")\n\n write_api = client.write_api(write_options=SYNCHRONOUS)\n query_api = client.query_api()\n\n p = Point(\"my_measurement\").tag(\"location\", \"Prague\").field(\"temperature\", 25.3)\n\n write_api.write(bucket=bucket, org=\"my-org\", record=p)\n\n ## using Table structure\n tables = query_api.query('from(bucket:\"my-bucket\") |> range(start: -10m)')\n\n for table in tables:\n print(table)\n for row in table.records:\n print (row.values)\n\n\n ## using csv library\n csv_result = query_api.query_csv('from(bucket:\"my-bucket\") |> range(start: -10m)')\n val_count = 0\n for row in csv_result:\n for cell in row:\n val_count += 1\n\n.. marker-query-end\n.. marker-index-end\n\n\nHow to use\n----------\n\nWrites\n^^^^^^\n.. marker-writes-start\n\nThe `WriteApi `_ supports synchronous, asynchronous and batching writes into InfluxDB 2.0.\nThe data should be passed as a `InfluxDB Line Protocol `_\\ , `Data Point `_ or Observable stream.\n\n*The default instance of ``WriteApi`` use batching.*\n\nBatching\n\"\"\"\"\"\"\"\"\n\n.. marker-batching-start\n\nThe batching is configurable by ``write_options``\\ :\n\n.. list-table::\n :header-rows: 1\n\n * - Property\n - Description\n - Default Value\n * - **batch_size**\n - the number of data pointx to collect in a batch\n - ``1000``\n * - **flush_interval**\n - the number of milliseconds before the batch is written\n - ``1000``\n * - **jitter_interval**\n - the number of milliseconds to increase the batch flush interval by a random amount\n - ``0``\n * - **retry_interval**\n - the number of milliseconds to retry unsuccessful write. The retry interval is used when the InfluxDB server does not specify \"Retry-After\" header.\n - ``1000``\n\n\n.. code-block:: python\n\n import rx\n from rx import operators as ops\n\n from influxdb_client import InfluxDBClient, Point, WriteOptions\n from influxdb_client.client.write_api import SYNCHRONOUS\n\n _client = InfluxDBClient(url=\"http://localhost:9999\", token=\"my-token\", org=\"my-org\")\n _write_client = _client.write_api(write_options=WriteOptions(batch_size=500, \n flush_interval=10_000, \n jitter_interval=2_000, \n retry_interval=5_000))\n\n \"\"\"\n Write Line Protocol\n \"\"\"\n _write_client.write(\"my-bucket\", \"my-org\", \"h2o_feet,location=coyote_creek water_level=1.0 1\")\n _write_client.write(\"my-bucket\", \"my-org\", [\"h2o_feet,location=coyote_creek water_level=2.0 2\",\n \"h2o_feet,location=coyote_creek water_level=3.0 3\"])\n\n \"\"\"\n Write Data Point\n \"\"\"\n _write_client.write(\"my-bucket\", \"my-org\", Point(\"h2o_feet\").tag(\"location\", \"coyote_creek\").field(\"water_level\", 4.0).time(4))\n _write_client.write(\"my-bucket\", \"my-org\", [Point(\"h2o_feet\").tag(\"location\", \"coyote_creek\").field(\"water_level\", 5.0).time(5),\n Point(\"h2o_feet\").tag(\"location\", \"coyote_creek\").field(\"water_level\", 6.0).time(6)])\n\n \"\"\"\n Write Observable stream\n \"\"\"\n _data = rx \\\n .range(7, 11) \\\n .pipe(ops.map(lambda i: \"h2o_feet,location=coyote_creek water_level={0}.0 {0}\".format(i)))\n\n _write_client.write(\"my-bucket\", \"my-org\", _data)\n\n\n \"\"\"\n Close client\n \"\"\"\n _write_client.__del__()\n _client.__del__()\n\n.. marker-batching-end\n\nAsynchronous client\n\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\n\nData are writes in an asynchronous HTTP request.\n\n.. code-block:: python\n\n from influxdb_client import InfluxDBClient\n from influxdb_client.client.write_api import ASYNCHRONOUS\n\n client = InfluxDBClient(url=\"http://localhost:9999\", token=\"my-token\", org=\"my-org\")\n write_client = client.write_api(write_options=ASYNCHRONOUS)\n\n ...\n\n client.__del__()\n\nSynchronous client\n\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\n\nData are writes in a synchronous HTTP request.\n\n.. code-block:: python\n\n from influxdb_client import InfluxDBClient\n from influxdb_client .client.write_api import SYNCHRONOUS\n\n client = InfluxDBClient(url=\"http://localhost:9999\", token=\"my-token\", org=\"my-org\")\n write_client = client.write_api(write_options=SYNCHRONOUS)\n\n ...\n\n client.__del__()\n\nHow to efficiently import large dataset\n\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\n\n\n* sources - `import_data_set.py `_\n\n.. code-block:: python\n\n \"\"\"\n Import VIX - CBOE Volatility Index - from \"vix-daily.csv\" file into InfluxDB 2.0\n\n https://datahub.io/core/finance-vix#data\n \"\"\"\n\n from collections import OrderedDict\n from csv import DictReader\n from datetime import datetime\n\n import rx\n from rx import operators as ops\n\n from influxdb_client import InfluxDBClient, Point, WriteOptions\n\n def parse_row(row: OrderedDict):\n \"\"\"Parse row of CSV file into Point with structure:\n\n financial-analysis,type=ily close=18.47,high=19.82,low=18.28,open=19.82 1198195200000000000\n\n CSV format:\n Date,VIX Open,VIX High,VIX Low,VIX Close\\n\n 2004-01-02,17.96,18.68,17.54,18.22\\n\n 2004-01-05,18.45,18.49,17.44,17.49\\n\n 2004-01-06,17.66,17.67,16.19,16.73\\n\n 2004-01-07,16.72,16.75,15.5,15.5\\n\n 2004-01-08,15.42,15.68,15.32,15.61\\n\n 2004-01-09,16.15,16.88,15.57,16.75\\n\n ...\n\n :param row: the row of CSV file\n :return: Parsed csv row to [Point]\n \"\"\"\n return Point(\"financial-analysis\") \\\n .tag(\"type\", \"vix-daily\") \\\n .field(\"open\", float(row['VIX Open'])) \\\n .field(\"high\", float(row['VIX High'])) \\\n .field(\"low\", float(row['VIX Low'])) \\\n .field(\"close\", float(row['VIX Close'])) \\\n .time(datetime.strptime(row['Date'], '%Y-%m-%d'))\n\n\n \"\"\"\n Converts vix-daily.csv into sequence of datad point\n \"\"\"\n data = rx \\\n .from_iterable(DictReader(open('vix-daily.csv', 'r'))) \\\n .pipe(ops.map(lambda row: parse_row(row)))\n\n client = InfluxDBClient(url=\"http://localhost:9999\", token=\"my-token\", org=\"my-org\", debug=True)\n\n \"\"\"\n Create client that writes data in batches with 500 items.\n \"\"\"\n write_api = client.write_api(write_options=WriteOptions(batch_size=500, jitter_interval=1_000))\n\n \"\"\"\n Write data into InfluxDB\n \"\"\"\n write_api.write(org=\"my-org\", bucket=\"my-bucket\", record=data)\n write_api.__del__()\n\n \"\"\"\n Querying max value of CBOE Volatility Index\n \"\"\"\n query = 'from(bucket:\"my-bucket\")' \\\n ' |> range(start: 0, stop: now())' \\\n ' |> filter(fn: (r) => r._measurement == \"financial-analysis\")' \\\n ' |> max()'\n result = client.query_api().query(org=\"my-org\", query=query)\n\n \"\"\"\n Processing results\n \"\"\"\n print()\n print(\"=== results ===\")\n print()\n for table in result:\n for record in table.records:\n print('max {0:5} = {1}'.format(record.get_field(), record.get_value()))\n\n \"\"\"\n Close client\n \"\"\"\n client.__del__()\n\n.. marker-writes-end\n\n\nEfficiency write data from IOT sensor\n\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\n.. marker-iot-start\n\n* sources - `iot_sensor.py `_\n\n.. code-block:: python\n\n \"\"\"\n Efficiency write data from IOT sensor - write changed temperature every minute\n \"\"\"\n import atexit\n import platform\n from datetime import timedelta\n\n import psutil as psutil\n import rx\n from rx import operators as ops\n\n from influxdb_client import InfluxDBClient, WriteApi, WriteOptions\n\n def on_exit(db_client: InfluxDBClient, write_api: WriteApi):\n \"\"\"Close clients after terminate a script.\n\n :param db_client: InfluxDB client\n :param write_api: WriteApi\n :return: nothing\n \"\"\"\n write_api.__del__()\n db_client.__del__()\n\n\n def sensor_temperature():\n \"\"\"Read a CPU temperature. The [psutil] doesn't support MacOS so we use [sysctl].\n\n :return: actual CPU temperature\n \"\"\"\n os_name = platform.system()\n if os_name == 'Darwin':\n from subprocess import check_output\n output = check_output([\"sysctl\", \"machdep.xcpm.cpu_thermal_level\"])\n import re\n return re.findall(r'\\d+', str(output))[0]\n else:\n return psutil.sensors_temperatures()[\"coretemp\"][0]\n\n\n def line_protocol(temperature):\n \"\"\"Create a InfluxDB line protocol with structure:\n\n iot_sensor,hostname=mine_sensor_12,type=temperature value=68\n\n :param temperature: the sensor temperature\n :return: Line protocol to write into InfluxDB\n \"\"\"\n\n import socket\n return 'iot_sensor,hostname={},type=temperature value={}'.format(socket.gethostname(), temperature)\n\n\n \"\"\"\n Read temperature every minute; distinct_until_changed - produce only if temperature change\n \"\"\"\n data = rx\\\n .interval(period=timedelta(seconds=60))\\\n .pipe(ops.map(lambda t: sensor_temperature()),\n ops.distinct_until_changed(),\n ops.map(lambda temperature: line_protocol(temperature)))\n\n _db_client = InfluxDBClient(url=\"http://localhost:9999\", token=\"my-token\", org=\"my-org\", debug=True)\n\n \"\"\"\n Create client that writes data into InfluxDB\n \"\"\"\n _write_api = _db_client.write_api(write_options=WriteOptions(batch_size=1))\n _write_api.write(org=\"my-org\", bucket=\"my-bucket\", record=data)\n\n\n \"\"\"\n Call after terminate a script\n \"\"\"\n atexit.register(on_exit, _db_client, _write_api)\n\n input()\n\n.. marker-iot-end\n\nAdvanced Usage\n--------------\n\nGzip support\n^^^^^^^^^^^^\n.. marker-gzip-start\n\n``InfluxDBClient`` does not enable gzip compression for http requests by default. If you want to enable gzip to reduce transfer data's size, you can call:\n\n.. code-block:: python\n\n from influxdb_client import InfluxDBClient\n\n _db_client = InfluxDBClient(url=\"http://localhost:9999\", token=\"my-token\", org=\"my-org\", enable_gzip=True)\n\n.. marker-gzip-end\n\n", "description_content_type": "text/x-rst", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/influxdata/influxdb-client-python", "keywords": "InfluxDB,InfluxDB Python Client", "license": "", "maintainer": "", "maintainer_email": "", "name": "influxdb-client", "package_url": "https://pypi.org/project/influxdb-client/", "platform": "", "project_url": "https://pypi.org/project/influxdb-client/", "project_urls": { "Homepage": "https://github.com/influxdata/influxdb-client-python" }, "release_url": "https://pypi.org/project/influxdb-client/0.0.2/", "requires_dist": [ "rx (>=3.0.1)", "certifi (>=14.05.14)", "six (>=1.10)", "python-dateutil (>=2.5.3)", "setuptools (>=21.0.0)", "urllib3 (>=1.15.1)", "ciso8601 (>=2.1.1)", "pytz (>=2019.1)" ], "requires_python": ">=3.6", "summary": "InfluxDB 2.0 Python client library", "version": "0.0.2" }, "last_serial": 5891455, "releases": { "0.0.1": [ { "comment_text": "", "digests": { "md5": "90eea8dd4fa23c2afc0f5a6f1e7c30c1", "sha256": "2c301eb8a836e680d7115f6f501ea94876f275965806b03154dc020216158930" }, "downloads": -1, "filename": "influxdb_client-0.0.1-py3-none-any.whl", "has_sig": false, "md5_digest": "90eea8dd4fa23c2afc0f5a6f1e7c30c1", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6", "size": 473351, "upload_time": "2019-09-26T16:04:14", "url": "https://files.pythonhosted.org/packages/88/d3/03b3c6094236b5b79f371046b63c2297c02a08e5f37f9b1eda3a02167b6e/influxdb_client-0.0.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "bf8339c5753e3e9969add92ca38abc90", "sha256": "db331e0e93159dddeb65635e56f676390ff1f4de4f1b87c3584d71cfc213af98" }, "downloads": -1, "filename": "influxdb_client-0.0.1.tar.gz", "has_sig": false, "md5_digest": "bf8339c5753e3e9969add92ca38abc90", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6", "size": 173157, "upload_time": "2019-09-26T16:04:18", "url": "https://files.pythonhosted.org/packages/b4/7c/c6aa47811805f8225b416805452c8de62ced20bb5848e680030641d159f4/influxdb_client-0.0.1.tar.gz" } ], "0.0.2": [ { "comment_text": "", "digests": { "md5": "40f2bfc12f82dfc5aba45f404315134d", "sha256": "c8fee37aa08b572a0deabcdb194e3e049518d2be16784b59428225e1822cff0f" }, "downloads": -1, "filename": "influxdb_client-0.0.2-py3-none-any.whl", "has_sig": false, "md5_digest": "40f2bfc12f82dfc5aba45f404315134d", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6", "size": 473357, "upload_time": "2019-09-26T16:14:06", "url": "https://files.pythonhosted.org/packages/55/ce/f5c4ff5e7648ef3fdb12d0ec98ee1609078507e3098191c9948a54816d86/influxdb_client-0.0.2-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "a51bd941fef4ee16cb52f77cbc89fc69", "sha256": "46d5b09fb2d8a3144cb955ff3c15a3269fd394392af61dceae136d8fd30cae16" }, "downloads": -1, "filename": "influxdb_client-0.0.2.tar.gz", "has_sig": false, "md5_digest": "a51bd941fef4ee16cb52f77cbc89fc69", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6", "size": 173178, "upload_time": "2019-09-26T16:14:09", "url": "https://files.pythonhosted.org/packages/c5/b1/eda3629299689ed27685ae4011476aa1e1703a4e26f6c9c9142f20488f82/influxdb_client-0.0.2.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "40f2bfc12f82dfc5aba45f404315134d", "sha256": "c8fee37aa08b572a0deabcdb194e3e049518d2be16784b59428225e1822cff0f" }, "downloads": -1, "filename": "influxdb_client-0.0.2-py3-none-any.whl", "has_sig": false, "md5_digest": "40f2bfc12f82dfc5aba45f404315134d", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6", "size": 473357, "upload_time": "2019-09-26T16:14:06", "url": "https://files.pythonhosted.org/packages/55/ce/f5c4ff5e7648ef3fdb12d0ec98ee1609078507e3098191c9948a54816d86/influxdb_client-0.0.2-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "a51bd941fef4ee16cb52f77cbc89fc69", "sha256": "46d5b09fb2d8a3144cb955ff3c15a3269fd394392af61dceae136d8fd30cae16" }, "downloads": -1, "filename": "influxdb_client-0.0.2.tar.gz", "has_sig": false, "md5_digest": "a51bd941fef4ee16cb52f77cbc89fc69", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6", "size": 173178, "upload_time": "2019-09-26T16:14:09", "url": "https://files.pythonhosted.org/packages/c5/b1/eda3629299689ed27685ae4011476aa1e1703a4e26f6c9c9142f20488f82/influxdb_client-0.0.2.tar.gz" } ] }