{"id":10608,"date":"2023-11-30T00:18:26","date_gmt":"2023-11-30T08:18:26","guid":{"rendered":"https:\/\/tdengine.com\/?p=10608"},"modified":"2025-03-30T23:25:43","modified_gmt":"2025-03-31T06:25:43","slug":"client-libraries","status":"publish","type":"post","link":"https:\/\/tdengine.com\/client-libraries\/","title":{"rendered":"TDengine Concepts: Client Libraries"},"content":{"rendered":"\n<p>TDengine makes it easy to get data in and out by providing a variety of client libraries that you can use to interact with its <a href=\"https:\/\/tdengine.com\/what-is-a-time-series-database\/\">time-series database<\/a> (TSDB). When you create your applications, you can use these client libraries &#8212; including sample code that you can copy into your application &#8212; to establish a connection to your TDengine cluster and perform query and insert operations as needed.<\/p>\n\n\n\n<p>TDengine provides a REST API and a set of native libraries for specific programming languages. These client libraries are discussed in depth in this article.<\/p>\n\n\n\n<figure class=\"gb-block-image gb-block-image-41f82cfa\"><img decoding=\"async\" width=\"6022\" height=\"2078\" class=\"gb-image gb-image-41f82cfa\" src=\"https:\/\/eujqw4hwudm.exactdn.com\/wp-content\/uploads\/22.144-01-workflow.png?strip=all&sharp=1\" alt=\"\" title=\"22.144-01-workflow\" srcset=\"https:\/\/eujqw4hwudm.exactdn.com\/wp-content\/uploads\/22.144-01-workflow.png?strip=all&amp;sharp=1 6022w, https:\/\/eujqw4hwudm.exactdn.com\/wp-content\/uploads\/22.144-01-workflow-300x104.png?strip=all&amp;sharp=1 300w, https:\/\/eujqw4hwudm.exactdn.com\/wp-content\/uploads\/22.144-01-workflow-1024x353.png?strip=all&amp;sharp=1 1024w, https:\/\/eujqw4hwudm.exactdn.com\/wp-content\/uploads\/22.144-01-workflow-768x265.png?strip=all&amp;sharp=1 768w, https:\/\/eujqw4hwudm.exactdn.com\/wp-content\/uploads\/22.144-01-workflow-1536x530.png?strip=all&amp;sharp=1 1536w, https:\/\/eujqw4hwudm.exactdn.com\/wp-content\/uploads\/22.144-01-workflow-2048x707.png?strip=all&amp;sharp=1 2048w, https:\/\/eujqw4hwudm.exactdn.com\/wp-content\/uploads\/22.144-01-workflow.png?strip=all&amp;sharp=1&amp;w=1204 1204w, https:\/\/eujqw4hwudm.exactdn.com\/wp-content\/uploads\/22.144-01-workflow.png?strip=all&amp;sharp=1&amp;w=2408 2408w, https:\/\/eujqw4hwudm.exactdn.com\/wp-content\/uploads\/22.144-01-workflow.png?strip=all&amp;sharp=1&amp;w=3613 3613w, https:\/\/eujqw4hwudm.exactdn.com\/wp-content\/uploads\/22.144-01-workflow.png?strip=all&amp;sharp=1&amp;w=4817 4817w, https:\/\/eujqw4hwudm.exactdn.com\/wp-content\/uploads\/22.144-01-workflow.png?strip=all&amp;sharp=1&amp;w=450 450w, https:\/\/eujqw4hwudm.exactdn.com\/wp-content\/uploads\/22.144-01-workflow.png?strip=all&amp;sharp=1&amp;w=1920 1920w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" \/>\n<figcaption class=\"gb-headline gb-headline-71df5d35 gb-headline-text\">Workflow between clients and TDengine<\/figcaption>\n<\/figure>\n\n\n\n<h2 class=\"gb-headline gb-headline-f6ddb7bb gb-headline-text\">REST API<\/h2>\n\n\n\n<p>The REST API is easiest to use, requiring only network connectivity to the TDengine cluster and that the development language of the application support HTTP. With the REST API, it is not necessary to install TDengine or any TDengine libraries on the machine running your application. However, ensure that the taosAdapter component is running on your TDengine Server.<\/p>\n\n\n\n<p>The first step to using the REST API is to obtain an authorization token. To do so, send a request to taosAdapter as follows, filling in the FQDN of the TDengine Server, the port on which taosAdapter is running (6041 by default), and valid user credentials for the TDengine cluster.<\/p>\n\n\n\n<pre class=\"wp-block-code language-shell\"><code class=\"\" data-line=\"\">curl &lt;&lt;em&gt;server-fqdn&lt;\/em&gt;&gt;:&lt;&lt;em&gt;taosadapter-port&lt;\/em&gt;&gt;\/rest\/login\/&lt;&lt;em&gt;username&lt;\/em&gt;&gt;\/&lt;&lt;em&gt;password&lt;\/em&gt;&gt;<\/code><\/pre>\n\n\n\n<p>With the authorization token, you can begin to perform operations on your databases over the REST API. Note that you must always specify the database on which you want to perform operations (for example, <code class=\"\" data-line=\"\">&lt;databasename&gt;.&lt;tablename&gt;<\/code>); the <code class=\"\" data-line=\"\">USE<\/code> command is not operational in this scenario. Unlike similar APIs in other products, the TDengine REST API allows you to perform database operations by inserting SQL commands in the body of an HTTP POST request, for example:<\/p>\n\n\n\n<pre class=\"wp-block-code language-shell\"><code class=\"\" data-line=\"\">curl -L -H &quot;Authorization: Taosd &lt;&lt;em&gt;token&lt;\/em&gt;&gt;&quot; -d &quot;SELECT * FROM test.d100&quot; &lt;&lt;em&gt;server-fqdn&lt;\/em&gt;&gt;:&lt;&lt;em&gt;taosadapter-port&lt;\/em&gt;&gt;\/rest\/sql<\/code><\/pre>\n\n\n\n<p>This request returns all records from the <code class=\"\" data-line=\"\">d100<\/code> table in the <code class=\"\" data-line=\"\">test<\/code> database. In this way, the REST API is a simple and lightweight but powerful method for connecting your application to a TDengine time-series database.<\/p>\n\n\n\n<p>For more information about the REST API, see the <a href=\"https:\/\/docs.tdengine.com\/tdengine-reference\/client-libraries\/rest-api\/\">official documentation<\/a>.<\/p>\n\n\n\n<h2 class=\"gb-headline gb-headline-2aaac716 gb-headline-text\">TDengine Client Libraries<\/h2>\n\n\n\n<p>In addition to the REST API, TDengine provides client libraries for C, C++, Java, Go, Rust, Python, Node.js, and C#. These libraries enable native connections in addition to HTTP interfaces (REST or WebSocket). With native connections, your application can access the full performance and complete feature set of TDengine. Note that to use a native connection, you must install the TDengine Client on the machine that runs your application.<\/p>\n\n\n\n<p>Each client library includes appropriate packages for the programming language for which it is designed. For example, to use the Python client library, you install the <code class=\"\" data-line=\"\">taospy<\/code> package, which includes the <code class=\"\" data-line=\"\">taos<\/code> module for native connections and the <code class=\"\" data-line=\"\">taosrest<\/code> module for RESTful connections.<\/p>\n\n\n\n<p>After importing a module, you can use the APIs it includes to connect to and perform operations on a TDengine cluster. For example, the following code uses the Python client library to establish a native connection to a TDengine cluster and then prints the version information for the TDengine Server and the local TDengine Client:<\/p>\n\n\n\n<pre class=\"wp-block-code language-python\"><code class=\"\" data-line=\"\">import taos\n\nconn: taos.TaosConnection = taos.connect(host=&quot;localhost&quot;,\n                                         user=&quot;root&quot;,\n                                         password=&quot;taosdata&quot;,\n                                         database=&quot;test&quot;,\n                                         port=6030,\n                                         config=&quot;\/etc\/taos&quot;\n                                         timezone=&quot;Asia\/Shanghai&quot;)\n\nserver_version = conn.server_info\nprint(&quot;server_version&quot;, server_version)\nclient_version = conn.client_info\nprint(&quot;client_version&quot;, client_version)\n\nconn.close()<\/code><\/pre>\n\n\n\n<p>To use this code, simply replace the values with the information for your cluster.<\/p>\n\n\n\n<p>Once you have established a connection, you can use the <code class=\"\" data-line=\"\">execute()<\/code> method to run SQL statements on the cluster, for example:<\/p>\n\n\n\n<pre class=\"wp-block-code language-python\"><code class=\"\" data-line=\"\">conn.execute(&quot;CREATE DATABASE test&quot;)<\/code><\/pre>\n\n\n\n<p>The libraries for other programming languages operate in a similar manner. TDengine client libraries make it easy to develop applications that make use of the time-series data stored in TDengine and offer the flexibility that you need to deal with various protocols and usage scenarios. In addition, a wealth of sample code and programs are provided in our official documentation that you can use with minor modifications for your own projects.<\/p>\n\n\n\n<p>For detailed descriptions of each client library and related code, see the <a href=\"https:\/\/docs.tdengine.com\/tdengine-reference\/client-libraries\/\">official documentation<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>When creating applications, you can use client libraries to establish a connection to your TDengine cluster and perform query and insert operations.<\/p>\n","protected":false},"author":48,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"content-type":"","footnotes":""},"categories":[21],"tags":[],"ppma_author":[100],"class_list":["post-10608","post","type-post","status-publish","format-standard","hentry","category-engineering"],"authors":[{"term_id":100,"user_id":48,"is_guest":0,"slug":"sangshuduo","display_name":"Shuduo Sang","avatar_url":{"url":"https:\/\/tdengine.com\/wp-content\/uploads\/29.04-28-sdsang.jpg","url2x":"https:\/\/tdengine.com\/wp-content\/uploads\/29.04-28-sdsang.jpg"},"1":"","2":"","3":"","4":"","5":"","6":"","7":"","8":""}],"_links":{"self":[{"href":"https:\/\/tdengine.com\/wp-json\/wp\/v2\/posts\/10608","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tdengine.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tdengine.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tdengine.com\/wp-json\/wp\/v2\/users\/48"}],"replies":[{"embeddable":true,"href":"https:\/\/tdengine.com\/wp-json\/wp\/v2\/comments?post=10608"}],"version-history":[{"count":14,"href":"https:\/\/tdengine.com\/wp-json\/wp\/v2\/posts\/10608\/revisions"}],"predecessor-version":[{"id":24705,"href":"https:\/\/tdengine.com\/wp-json\/wp\/v2\/posts\/10608\/revisions\/24705"}],"wp:attachment":[{"href":"https:\/\/tdengine.com\/wp-json\/wp\/v2\/media?parent=10608"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tdengine.com\/wp-json\/wp\/v2\/categories?post=10608"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tdengine.com\/wp-json\/wp\/v2\/tags?post=10608"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/tdengine.com\/wp-json\/wp\/v2\/ppma_author?post=10608"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}