{"id":3728,"date":"2023-08-09T09:13:32","date_gmt":"2023-08-09T06:13:32","guid":{"rendered":"https:\/\/www.virtono.com\/community\/?p=3728"},"modified":"2023-08-09T09:13:49","modified_gmt":"2023-08-09T06:13:49","slug":"how-to-use-influxdb-with-python-on-ubuntu-22-04","status":"publish","type":"post","link":"https:\/\/www.virtono.com\/community\/tutorial-how-to\/how-to-use-influxdb-with-python-on-ubuntu-22-04\/","title":{"rendered":"How to use InfluxDB with Python on Ubuntu 22.04"},"content":{"rendered":"<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"422\" data-attachment-id=\"3740\" data-permalink=\"https:\/\/www.virtono.com\/community\/tutorial-how-to\/how-to-use-influxdb-with-python-on-ubuntu-22-04\/attachment\/how-to-use-influxdb-with-python-on-ubuntu\/\" data-orig-file=\"https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2023\/08\/How-to-use-InfluxDB-with-Python-on-Ubuntu.png?fit=1920%2C1080&amp;ssl=1\" data-orig-size=\"1920,1080\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"How-to-use-InfluxDB-with-Python-on-Ubuntu\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2023\/08\/How-to-use-InfluxDB-with-Python-on-Ubuntu.png?fit=750%2C422&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2023\/08\/How-to-use-InfluxDB-with-Python-on-Ubuntu.png?resize=750%2C422&#038;ssl=1\" alt=\"How to use InfluxDB with Python on Ubuntu 22.04\" class=\"wp-image-3740\" srcset=\"https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2023\/08\/How-to-use-InfluxDB-with-Python-on-Ubuntu.png?resize=1024%2C576&amp;ssl=1 1024w, https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2023\/08\/How-to-use-InfluxDB-with-Python-on-Ubuntu.png?resize=300%2C169&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2023\/08\/How-to-use-InfluxDB-with-Python-on-Ubuntu.png?resize=768%2C432&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2023\/08\/How-to-use-InfluxDB-with-Python-on-Ubuntu.png?resize=1536%2C864&amp;ssl=1 1536w, https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2023\/08\/How-to-use-InfluxDB-with-Python-on-Ubuntu.png?w=1920&amp;ssl=1 1920w\" sizes=\"auto, (max-width: 750px) 100vw, 750px\" \/><\/figure>\n<\/div>\n\n\n<p><\/p>\n\n\n\n<p>This tutorial will walk you through installing and configuring InfluxDB with Python on a VPS running Ubuntu 22.04.<\/p>\n\n\n\n<p>InfluxDB is an open-source time-series database (TSDB) developed by InfluxData. It&#8217;s written in Go and optimized for fast, high-availability storage and retrieval of time series data in fields such as operations monitoring, application metrics, Internet of Things sensor data, and real-time analytics.<\/p>\n\n\n\n<p>Python, a high-level, interpreted programming language with dynamic semantics, is known for its easy readability with great design principles. When you combine Python&#8217;s power with InfluxDB&#8217;s efficiency, you get a potent tool for your data analytics needs.<\/p>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_73 counter-hierarchy ez-toc-counter ez-toc-light-blue ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/www.virtono.com\/community\/tutorial-how-to\/how-to-use-influxdb-with-python-on-ubuntu-22-04\/#Step_1_Update_and_Upgrade_Your_System\" title=\"Step 1: Update and Upgrade Your System\">Step 1: Update and Upgrade Your System<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/www.virtono.com\/community\/tutorial-how-to\/how-to-use-influxdb-with-python-on-ubuntu-22-04\/#Step_2_Install_InfluxDB_with_Python\" title=\"Step 2: Install InfluxDB with Python\">Step 2: Install InfluxDB with Python<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/www.virtono.com\/community\/tutorial-how-to\/how-to-use-influxdb-with-python-on-ubuntu-22-04\/#Step_3_Configure_and_Start_InfluxDB\" title=\"Step 3: Configure and Start InfluxDB\">Step 3: Configure and Start InfluxDB<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/www.virtono.com\/community\/tutorial-how-to\/how-to-use-influxdb-with-python-on-ubuntu-22-04\/#Step_4_Install_Python_and_InfluxDB_Python_Client\" title=\"Step 4: Install Python and InfluxDB Python Client\">Step 4: Install Python and InfluxDB Python Client<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/www.virtono.com\/community\/tutorial-how-to\/how-to-use-influxdb-with-python-on-ubuntu-22-04\/#Step_5_Create_a_Database_and_User_in_InfluxDB\" title=\"Step 5: Create a Database and User in InfluxDB\">Step 5: Create a Database and User in InfluxDB<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/www.virtono.com\/community\/tutorial-how-to\/how-to-use-influxdb-with-python-on-ubuntu-22-04\/#Step_6_Write_a_Python_Script_to_Interact_with_InfluxDB\" title=\"Step 6: Write a Python Script to Interact with InfluxDB\">Step 6: Write a Python Script to Interact with InfluxDB<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/www.virtono.com\/community\/tutorial-how-to\/how-to-use-influxdb-with-python-on-ubuntu-22-04\/#Summary\" title=\"Summary\">Summary<\/a><\/li><\/ul><\/nav><\/div>\n<h3 class=\"wp-block-heading has-accent-color has-text-color\"><span class=\"ez-toc-section\" id=\"Step_1_Update_and_Upgrade_Your_System\"><\/span>Step 1: Update and Upgrade Your System<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Before we get started, it&#8217;s a good idea to update and upgrade your <a href=\"https:\/\/virtono.com\/cloud-vps\" target=\"_blank\" rel=\"noopener\">Ubuntu 22.04 VPS<\/a> system packages and repositories.<\/p>\n\n\n\n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background\"><code>sudo apt update &amp;&amp; sudo apt upgrade -y<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading has-accent-color has-text-color\"><span class=\"ez-toc-section\" id=\"Step_2_Install_InfluxDB_with_Python\"><\/span>Step 2: Install InfluxDB with Python<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>You can use the official <a href=\"https:\/\/www.virtono.com\/community\/tutorial-how-to\/how-to-deploy-influxdb-on-kubernetes\/\">InfluxData<\/a> repository to install InfluxDB on Ubuntu 22.04. First, add the InfluxData repository using the commands below:<\/p>\n\n\n\n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background\"><code># wget -qO- https:\/\/repos.influxdata.com\/influxdb.key | sudo apt-key add -\n\n# sudo echo \"deb https:\/\/repos.influxdata.com\/ubuntu bionic stable\" | sudo tee \/etc\/apt\/sources.list.d\/influxdb.list<\/code><\/pre>\n\n\n\n<p><strong>Then, install InfluxDB:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background\"><code>apt install influxdb influxdb-client -y<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading has-accent-color has-text-color\"><span class=\"ez-toc-section\" id=\"Step_3_Configure_and_Start_InfluxDB\"><\/span>Step 3: Configure and Start InfluxDB<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Once InfluxDB is installed, you need to enable and start the InfluxDB service:<\/p>\n\n\n\n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background\"><code>sudo systemctl enable --now influxdb<\/code><\/pre>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"83\" data-attachment-id=\"3735\" data-permalink=\"https:\/\/www.virtono.com\/community\/tutorial-how-to\/how-to-use-influxdb-with-python-on-ubuntu-22-04\/attachment\/screenshot-2023-08-08-at-13-56-59\/\" data-orig-file=\"https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2023\/08\/Screenshot-2023-08-08-at-13.56.59.png?fit=1173%2C130&amp;ssl=1\" data-orig-size=\"1173,130\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Screenshot-2023-08-08-at-13.56.59\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2023\/08\/Screenshot-2023-08-08-at-13.56.59.png?fit=750%2C83&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2023\/08\/Screenshot-2023-08-08-at-13.56.59.png?resize=750%2C83&#038;ssl=1\" alt=\"How to use InfluxDB with Python on Ubuntu 22.04\" class=\"wp-image-3735\" srcset=\"https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2023\/08\/Screenshot-2023-08-08-at-13.56.59.png?resize=1024%2C113&amp;ssl=1 1024w, https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2023\/08\/Screenshot-2023-08-08-at-13.56.59.png?resize=300%2C33&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2023\/08\/Screenshot-2023-08-08-at-13.56.59.png?resize=768%2C85&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2023\/08\/Screenshot-2023-08-08-at-13.56.59.png?w=1173&amp;ssl=1 1173w\" sizes=\"auto, (max-width: 750px) 100vw, 750px\" \/><\/figure>\n<\/div>\n\n\n<p><\/p>\n\n\n\n<p>You can check the status of the InfluxDB service with:<\/p>\n\n\n\n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background\"><code>sudo systemctl status influxdb<\/code><\/pre>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"168\" data-attachment-id=\"3736\" data-permalink=\"https:\/\/www.virtono.com\/community\/tutorial-how-to\/how-to-use-influxdb-with-python-on-ubuntu-22-04\/attachment\/screenshot-2023-08-09-at-08-53-21\/\" data-orig-file=\"https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2023\/08\/Screenshot-2023-08-09-at-08.53.21.png?fit=1976%2C444&amp;ssl=1\" data-orig-size=\"1976,444\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Screenshot-2023-08-09-at-08.53.21\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2023\/08\/Screenshot-2023-08-09-at-08.53.21.png?fit=750%2C168&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2023\/08\/Screenshot-2023-08-09-at-08.53.21.png?resize=750%2C168&#038;ssl=1\" alt=\"How to use InfluxDB with Python on Ubuntu 22.04\" class=\"wp-image-3736\" srcset=\"https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2023\/08\/Screenshot-2023-08-09-at-08.53.21.png?resize=1024%2C230&amp;ssl=1 1024w, https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2023\/08\/Screenshot-2023-08-09-at-08.53.21.png?resize=300%2C67&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2023\/08\/Screenshot-2023-08-09-at-08.53.21.png?resize=768%2C173&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2023\/08\/Screenshot-2023-08-09-at-08.53.21.png?resize=1536%2C345&amp;ssl=1 1536w, https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2023\/08\/Screenshot-2023-08-09-at-08.53.21.png?w=1976&amp;ssl=1 1976w\" sizes=\"auto, (max-width: 750px) 100vw, 750px\" \/><\/figure>\n<\/div>\n\n\n<p><\/p>\n\n\n\n<h3 class=\"wp-block-heading has-accent-color has-text-color\"><span class=\"ez-toc-section\" id=\"Step_4_Install_Python_and_InfluxDB_Python_Client\"><\/span>Step 4: Install Python and InfluxDB Python Client<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Next, execute the commands listed below to install Python and pip (Python&#8217;s package installer):<\/p>\n\n\n\n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background\"><code>sudo apt install python3 python3-pip -y<\/code><\/pre>\n\n\n\n<p>Now, install the InfluxDB client for Python:<\/p>\n\n\n\n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background\"><code>pip3 install influxdb<\/code><\/pre>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"204\" data-attachment-id=\"3737\" data-permalink=\"https:\/\/www.virtono.com\/community\/tutorial-how-to\/how-to-use-influxdb-with-python-on-ubuntu-22-04\/attachment\/screenshot-2023-08-09-at-08-58-21\/\" data-orig-file=\"https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2023\/08\/Screenshot-2023-08-09-at-08.58.21.png?fit=2038%2C556&amp;ssl=1\" data-orig-size=\"2038,556\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Screenshot-2023-08-09-at-08.58.21\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2023\/08\/Screenshot-2023-08-09-at-08.58.21.png?fit=750%2C204&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2023\/08\/Screenshot-2023-08-09-at-08.58.21.png?resize=750%2C204&#038;ssl=1\" alt=\"InfluxDB with Python\" class=\"wp-image-3737\" srcset=\"https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2023\/08\/Screenshot-2023-08-09-at-08.58.21.png?resize=1024%2C279&amp;ssl=1 1024w, https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2023\/08\/Screenshot-2023-08-09-at-08.58.21.png?resize=300%2C82&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2023\/08\/Screenshot-2023-08-09-at-08.58.21.png?resize=768%2C210&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2023\/08\/Screenshot-2023-08-09-at-08.58.21.png?resize=1536%2C419&amp;ssl=1 1536w, https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2023\/08\/Screenshot-2023-08-09-at-08.58.21.png?w=2038&amp;ssl=1 2038w\" sizes=\"auto, (max-width: 750px) 100vw, 750px\" \/><\/figure>\n<\/div>\n\n\n<p><\/p>\n\n\n\n<h3 class=\"wp-block-heading has-accent-color has-text-color\"><span class=\"ez-toc-section\" id=\"Step_5_Create_a_Database_and_User_in_InfluxDB\"><\/span>Step 5: Create a Database and User in InfluxDB<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Access the InfluxDB shell:<\/p>\n\n\n\n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background\"><code>influx<\/code><\/pre>\n\n\n\n<p>Create a new database and user with the following commands:<\/p>\n\n\n\n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background\"><code>CREATE DATABASE mydb<br>CREATE USER \"myuser\" WITH PASSWORD 'mypassword' WITH ALL PRIVILEGES<br>Exit the InfluxDB shell by typing exit.<\/code><\/pre>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"112\" data-attachment-id=\"3738\" data-permalink=\"https:\/\/www.virtono.com\/community\/tutorial-how-to\/how-to-use-influxdb-with-python-on-ubuntu-22-04\/attachment\/screenshot-2023-08-09-at-09-00-38\/\" data-orig-file=\"https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2023\/08\/Screenshot-2023-08-09-at-09.00.38.png?fit=1932%2C288&amp;ssl=1\" data-orig-size=\"1932,288\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Screenshot-2023-08-09-at-09.00.38\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2023\/08\/Screenshot-2023-08-09-at-09.00.38.png?fit=750%2C112&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2023\/08\/Screenshot-2023-08-09-at-09.00.38.png?resize=750%2C112&#038;ssl=1\" alt=\"InfluxDB with Python database\" class=\"wp-image-3738\" srcset=\"https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2023\/08\/Screenshot-2023-08-09-at-09.00.38.png?resize=1024%2C153&amp;ssl=1 1024w, https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2023\/08\/Screenshot-2023-08-09-at-09.00.38.png?resize=300%2C45&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2023\/08\/Screenshot-2023-08-09-at-09.00.38.png?resize=768%2C114&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2023\/08\/Screenshot-2023-08-09-at-09.00.38.png?resize=1536%2C229&amp;ssl=1 1536w, https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2023\/08\/Screenshot-2023-08-09-at-09.00.38.png?w=1932&amp;ssl=1 1932w\" sizes=\"auto, (max-width: 750px) 100vw, 750px\" \/><\/figure>\n<\/div>\n\n\n<p><\/p>\n\n\n\n<h3 class=\"wp-block-heading has-accent-color has-text-color\"><span class=\"ez-toc-section\" id=\"Step_6_Write_a_Python_Script_to_Interact_with_InfluxDB\"><\/span>Step 6: Write a Python Script to Interact with InfluxDB<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>The next step is to create a Python script that connects to the InfluxDB server, writes data, queries data, and reads the outcome. Put your database&#8217;s name, username, and password in the spaces provided:<\/p>\n\n\n\n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background\"><code>from influxdb import InfluxDBClient\n\n# Connect to InfluxDB server\nclient = InfluxDBClient(host='localhost', port=8086, username='myuser', password='mypassword')\n\n# Switch to the created database\nclient.switch_database('mydb')\n\n# Data to be written\njson_body = &#91;\n    {\n        \"measurement\": \"cpu_load_short\",\n        \"tags\": {\n            \"host\": \"server01\",\n            \"region\": \"us-test\"\n        },\n        \"fields\": {\n            \"value\": 0.64\n        }\n    }\n]\n\n# Write data\nclient.write_points(json_body)\n\n# Query data\nresult = client.query('SELECT \"value\" FROM \"cpu_load_short\" WHERE \"region\"=\\'us-west\\'')\n\n# Print result\nprint(\"Result: {0}\".format(result))<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p>Then enter the following command to execute the script:<\/p>\n\n\n\n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background\"><code>python3 influxdb_python.py<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading has-accent-color has-text-color\"><span class=\"ez-toc-section\" id=\"Summary\"><\/span>Summary<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>This guide has provided a step-by-step overview of how to set up and use InfluxDB with Python on an Ubuntu 22.04 VPS, and how to access your application using an external IPv4. With this setup, you can efficiently store, retrieve, and analyze your time-series data.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This tutorial will walk you through installing and configuring InfluxDB with Python on a VPS running Ubuntu 22.04. InfluxDB is an open-source time-series database (TSDB) developed by InfluxData. It&#8217;s written in Go and optimized for fast, high-availability storage and retrieval of time series data in fields such as operations monitoring,<\/p>\n","protected":false},"author":8,"featured_media":3742,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[3],"tags":[629,625,611,632,631,630,633,605,624],"class_list":["post-3728","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorial-how-to","tag-data-analytics","tag-database-management","tag-influxdb","tag-influxdb-ubuntu","tag-influxdb-ubuntu-22-04","tag-influxdb-with-python","tag-python-influxdb","tag-time-series-database","tag-web-application"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2023\/08\/How-to-use-InfluxDB-with-Python-on-Ubuntu-22-04.png?fit=360%2C240&ssl=1","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p7ISfL-Y8","jetpack_likes_enabled":true,"jetpack-related-posts":[{"id":3717,"url":"https:\/\/www.virtono.com\/community\/tutorial-how-to\/how-to-deploy-influxdb-on-kubernetes\/","url_meta":{"origin":3728,"position":0},"title":"How to Deploy InfluxDB on Kubernetes","author":"George B.","date":"August 4, 2023","format":false,"excerpt":"InfluxDB has become a popular choice for time-series databases, especially for DevOps monitoring, real-time analytics, and IoT applications. In this guide, we will explore how to deploy InfluxDB on Kubernetes cluster using K3s and Helm. We will assume that you already have K3s installed and Helm configured.\u00a0If K3s and Helm\u2026","rel":"","context":"In &quot;Tutorials&quot;","block_context":{"text":"Tutorials","link":"https:\/\/www.virtono.com\/community\/category\/tutorial-how-to\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2023\/08\/Deploy-InfluxDB-on-Kubernetes.png?fit=360%2C240&ssl=1&resize=350%2C200","width":350,"height":200},"classes":[]},{"id":3897,"url":"https:\/\/www.virtono.com\/community\/tutorial-how-to\/how-to-install-neo4j-on-ubuntu-22-04\/","url_meta":{"origin":3728,"position":1},"title":"How to install Neo4j on Ubuntu 22.04","author":"George B.","date":"September 19, 2023","format":false,"excerpt":"This article will guide you through the process of installing Neo4j on Ubuntu 22.04. We'll break down each step, ensuring you have a smooth and successful installation. When it comes to graph databases, Neo4j stands out as a leading platform, providing a reliable and effective way to manage and query\u2026","rel":"","context":"In &quot;Tutorials&quot;","block_context":{"text":"Tutorials","link":"https:\/\/www.virtono.com\/community\/category\/tutorial-how-to\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2023\/09\/How-to-install-Neo4j-on-Ubuntu-22.04.png?fit=360%2C240&ssl=1&resize=350%2C200","width":350,"height":200},"classes":[]},{"id":3752,"url":"https:\/\/www.virtono.com\/community\/tutorial-how-to\/how-to-install-postgresql-on-ubuntu-22-04\/","url_meta":{"origin":3728,"position":2},"title":"How to install PostgreSQL on Ubuntu 22.04","author":"George B.","date":"August 21, 2023","format":false,"excerpt":"This tutorial will take you step-by-step through the installation of PostgreSQL on Ubuntu 22.04, explaining all necessary setup steps along the way. It will also show you how to create and manage your first PostgreSQL database. PostgreSQL, also known as Postgres, is an open-source relational database management system (RDBMS) that\u2026","rel":"","context":"In &quot;Tutorials&quot;","block_context":{"text":"Tutorials","link":"https:\/\/www.virtono.com\/community\/category\/tutorial-how-to\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2023\/08\/How-to-install-PostgreSQL-on-Ubuntu-22.04.png?fit=360%2C240&ssl=1&resize=350%2C200","width":350,"height":200},"classes":[]},{"id":3870,"url":"https:\/\/www.virtono.com\/community\/tutorial-how-to\/how-to-install-couchdb-on-ubuntu-22-04\/","url_meta":{"origin":3728,"position":3},"title":"How to Install CouchDB on Ubuntu 22.04","author":"George B.","date":"September 14, 2023","format":false,"excerpt":"In this article, we will provide a detailed guide on how to install CouchDB on Ubuntu 22.04. Data management is now one of the most important aspects of any business, especially with the advent of the digital age. This is where database management systems like CouchDB are useful. The Apache\u2026","rel":"","context":"In &quot;Tutorials&quot;","block_context":{"text":"Tutorials","link":"https:\/\/www.virtono.com\/community\/category\/tutorial-how-to\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2023\/09\/How-to-Install-CouchDB-on-Ubuntu-22-04.png?fit=360%2C240&ssl=1&resize=350%2C200","width":350,"height":200},"classes":[]},{"id":3438,"url":"https:\/\/www.virtono.com\/community\/tutorial-how-to\/how-to-install-apache-spark-on-ubuntu-22-04-and-centos\/","url_meta":{"origin":3728,"position":4},"title":"How to install Apache Spark on Ubuntu 22.04 and CentOS","author":"George B.","date":"June 1, 2023","format":false,"excerpt":"We will guide you through the process of installing Apache Spark on Ubuntu 22.04, 20.04, and CentOS, ensuring you have all the necessary tools to leverage this incredible technology. Apache Spark is a powerful open-source framework for distributed computing that has become a go-to solution for big data processing. With\u2026","rel":"","context":"In &quot;Tutorials&quot;","block_context":{"text":"Tutorials","link":"https:\/\/www.virtono.com\/community\/category\/tutorial-how-to\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2023\/05\/How-to-install-Apache-Spark-on-Ubuntu-22.04-and-CentOS.png?fit=600%2C330&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2023\/05\/How-to-install-Apache-Spark-on-Ubuntu-22.04-and-CentOS.png?fit=600%2C330&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2023\/05\/How-to-install-Apache-Spark-on-Ubuntu-22.04-and-CentOS.png?fit=600%2C330&ssl=1&resize=525%2C300 1.5x"},"classes":[]},{"id":3442,"url":"https:\/\/www.virtono.com\/community\/tutorial-how-to\/how-to-install-grafana-on-ubuntu-22-04-for-advanced-data-visualization\/","url_meta":{"origin":3728,"position":5},"title":"How to Install Grafana on Ubuntu 22.04 for Advanced Data Visualization","author":"George B.","date":"June 2, 2023","format":false,"excerpt":"We will walk you through the step-by-step process of installing Grafana on Ubuntu 22.04. Grafana, an open-source platform, has become a popular choice for data visualization and monitoring. With its user-friendly dashboards and extensive plugin ecosystem, Grafana empowers users to derive valuable insights from their data. Whether you're a data\u2026","rel":"","context":"In &quot;Tutorials&quot;","block_context":{"text":"Tutorials","link":"https:\/\/www.virtono.com\/community\/category\/tutorial-how-to\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2023\/05\/How-to-Install-Grafana-on-Ubuntu-22.04.png?fit=600%2C330&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2023\/05\/How-to-Install-Grafana-on-Ubuntu-22.04.png?fit=600%2C330&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.virtono.com\/community\/wp-content\/uploads\/2023\/05\/How-to-Install-Grafana-on-Ubuntu-22.04.png?fit=600%2C330&ssl=1&resize=525%2C300 1.5x"},"classes":[]}],"_links":{"self":[{"href":"https:\/\/www.virtono.com\/community\/wp-json\/wp\/v2\/posts\/3728","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.virtono.com\/community\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.virtono.com\/community\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.virtono.com\/community\/wp-json\/wp\/v2\/users\/8"}],"replies":[{"embeddable":true,"href":"https:\/\/www.virtono.com\/community\/wp-json\/wp\/v2\/comments?post=3728"}],"version-history":[{"count":3,"href":"https:\/\/www.virtono.com\/community\/wp-json\/wp\/v2\/posts\/3728\/revisions"}],"predecessor-version":[{"id":3741,"href":"https:\/\/www.virtono.com\/community\/wp-json\/wp\/v2\/posts\/3728\/revisions\/3741"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.virtono.com\/community\/wp-json\/wp\/v2\/media\/3742"}],"wp:attachment":[{"href":"https:\/\/www.virtono.com\/community\/wp-json\/wp\/v2\/media?parent=3728"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.virtono.com\/community\/wp-json\/wp\/v2\/categories?post=3728"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.virtono.com\/community\/wp-json\/wp\/v2\/tags?post=3728"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}