Client Libraries
TDengine TSDB provides a rich set of application development interfaces. To facilitate users in quickly developing applications, it supports connectors for multiple programming languages — among which the official ones include those for C/C++, Java, Python, Go, Node.js, C#, and Rust. Community developers have also contributed several unofficial connectors, such as the ADO.NET connector, Lua connector, and PHP connector. These connectors support connecting to the TDengine TSDB cluster via the native interface and WebSocket interface. Additionally, users can directly call the REST API interfaces provided by taosAdapter to access TDengine TSDB for data writing and query operations.
Connection Methods
The following is the architecture diagram of the connection methods between TDengine TSDB client and server:
As shown in the architecture diagram above, there are three ways to access TDengine TSDB:
- WebSocket connection: Establish a connection with taosd through the WebSocket API provided by the taosAdapter component using a connector. This connection method is referred to as "WebSocket connection" in the following text. WebSocket connection is recommended.
- Native connection: Establish a direct connection with the server program taosd through the client driver taosc using a connector. This connection method is referred to as "native connection" in the following text.
- REST API: Establish a connection with taosd by directly calling the REST API provided by the taosAdapter component using an HTTP client, without using a connector. This connection method is referred to as "REST API" in the following text.
Note: The client driver taosc includes C native and WebSocket connectors. Applications developed in C/C++ language must depend on the client driver taosc.
For both WebSocket connections and native connections, connectors provide the same or similar APIs for database operations. The only slight difference lies in the connection initialization methods, so users will not perceive any difference in usage.
For the support status of various connection methods and connectors for different languages, please refer to Connector Features.
The key differences are:
- When using a native connection, the version of the client driver taosc must be consistent with that of the server-side TDengine TSDB.
- When using a WebSocket connection, except for C/C++ and ODBC connectors, users do not need to install the client driver taosc. Even if the client driver taosc is required, there is no need to ensure its version is consistent with that of the server-side TDengine TSDB.
- To connect to a cloud service instance, a WebSocket connection must be used.
- REST API only provides the function of executing SQL, and does not support parameter binding or data subscription.
Supported Platforms
Currently, the connectors for TDengine TSDB support a wide range of platforms, including hardware platforms such as X64/X86/ARM64/ARM32/MIPS/LoongArch64 (or Loong64), and development environments such as Linux/Win64/Win32/macOS.
The compatibility matrix is as follows:
CPU | X64 64bit | X64 64bit | X64 64bit | ARM64 | ARM64 |
---|---|---|---|---|---|
OS | Linux | Win64 | macOS | Linux | macOS |
C/C++ | ● | ● | ● | ● | ● |
JDBC | ● | ● | ● | ● | ● |
Python | ● | ● | ● | ● | ● |
Go | ● | ● | ● | ● | ● |
NodeJs | ● | ● | ● | ● | ● |
C# | ● | ● | ○ | ○ | ○ |
Rust | ● | ● | ● | ○ | ● |
REST API | ● | ● | ● | ● | ● |
Note: ● indicates official testing and verification passed, ○ indicates non-official testing and verification passed, -- indicates not verified.
Version Support
TDengine version updates often add new features. The list below shows the best matching connector versions for each TDengine version.
TDengine Version | Java | Python | Go | C# | Node.js | Rust | C/C++ |
---|---|---|---|---|---|---|---|
3.3.0.0 and above | 3.3.0 and above | taospy 2.7.15 and above, taos-ws-py 0.3.2 and above | 3.5.5 and above | 3.1.3 and above | 3.1.0 and above | Current version | Same as TDengine version |
3.0.0.0 and above | 3.0.2 and above | Current version | 3.0 branch | 3.0.0 | 3.1.0 | Current version | Same as TDengine version |
2.4.0.14 and above | 2.0.38 | Current version | develop branch | 1.0.2 - 1.0.6 | 2.0.10 - 2.0.12 | Current version | Same as TDengine version |
2.4.0.4 - 2.4.0.13 | 2.0.37 | Current version | develop branch | 1.0.2 - 1.0.6 | 2.0.10 - 2.0.12 | Current version | Same as TDengine version |
2.2.x.x | 2.0.36 | Current version | master branch | n/a | 2.0.7 - 2.0.9 | Current version | Same as TDengine version |
2.0.x.x | 2.0.34 | Current version | master branch | n/a | 2.0.1 - 2.0.6 | Current version | Same as TDengine version |
Feature Support
The following table outlines the support for TDengine TSDB features across different connectors:
WebSocket/Native Connections
Feature | Java | Python | Go | C# | Node.js | Rust | C/C++ |
---|---|---|---|---|---|---|---|
Connection Management | Supported | Supported | Supported | Supported | Supported | Supported | Supported |
Execute SQL | Supported | Supported | Supported | Supported | Supported | Supported | Supported |
Parameter Binding | Supported | Supported | Supported | Supported | Supported | Supported | Supported |
Data Subscription (TMQ) | Supported | Supported | Supported | Supported | Supported | Supported | Supported |
Schema-less Write | Supported | Supported | Supported | Supported | Supported | Supported | Supported |
Note: The Node.js connector does not support native connections.
Due to differences in database framework specifications across programming languages, it does not mean that all C/C++ interfaces require corresponding encapsulation support.
- Regardless of the programming language connector used, for TDengine TSDB version 2.0 and above, it is recommended that each thread of a database application establishes an independent connection or creates a thread-based connection pool. This avoids mutual interference of the "USE statement" state within the connection between threads (however, the connection's query and write operations are thread-safe).
REST API
Supports Execute SQL
Install Client Driver
You only need to install the client driver if you are using a native interface connector on a system where the TDengine server software is not installed.
Installation Steps
- Linux
- Windows
- MacOS
- Download the client installation package
-
Unzip the software package
Place the package in any directory where the current user has read and write access, then execute the following command:
tar -xzvf TDengine-client-VERSION.tar.gz
Replace VERSION with the actual version string. -
Run the installation script
After unzipping the package, you will see the following files (directories) in the unzipped directory:
- install_client.sh: Installation script, used for applying the driver
- package.tar.gz: Application driver installation package
- driver: TDengine application driver
- examples: Sample programs for various programming languages (c/C#/go/JDBC/MATLAB/python/R) Run install_client.sh to install.
-
Configure taos.cfg
Edit the
taos.cfg
file (default path /etc/taos/taos.cfg), changefirstEP
to the End Point of the TDengine server, for example:h1.tdengine.com:6030
- If the TDengine service is not deployed on this machine and only the application driver is installed, then only
firstEP
needs to be configured intaos.cfg
, there is no need to configureFQDN
on this machine. - To prevent the "Unable to resolve FQDN" error when connecting to the server, it is recommended to ensure that the
/etc/hosts
file on your machine is configured with the correct FQDN value of the server, or that the DNS service is properly configured.
-
Download the client installation package
-
Run the installer, follow the prompts to select the default values, and complete the installation
-
Installation path
The default installation path is: C:\TDengine, which includes the following files (directories):
- taos.exe: TDengine CLI command line program
- taosadapter.exe: Server executable that provides RESTful services and accepts write requests from various other software
- taosBenchmark.exe: TDengine test program
- cfg: Configuration file directory
- driver: Application driver dynamic link library
- examples: Example programs for bash/C/C#/go/JDBC/Python/Node.js
- include: Header files
- log: Log files
- unins000.exe: Uninstallation program
-
Configure taos.cfg
Edit the taos.cfg file (default path C:\TDengine\cfg\taos.cfg), change firstEP to the End Point of the TDengine server, for example:
h1.tdengine.com:6030
.
- If using FQDN to connect to the server, ensure that the local network environment DNS is properly configured, or add FQDN addressing records in the hosts file, such as editing C:\Windows\system32\drivers\etc\hosts, adding records like:
192.168.1.99 h1.taos.com
- Uninstallation: Run unins000.exe to uninstall the TDengine application driver.
-
Download the client installation package
-
Run the installer and follow the prompts to select the default values to complete the installation. If the installation is blocked, you can right-click or press Ctrl and click on the installation package, then choose
Open
. -
Configure taos.cfg
Edit the
taos.cfg
file (default path /etc/taos/taos.cfg), and changefirstEP
to the End Point of the TDengine server, for example:h1.tdengine.com:6030
- If the TDengine service is not deployed on the local machine and only the application driver is installed, then only
firstEP
needs to be configured intaos.cfg
, there is no need to configureFQDN
on the local machine. - To prevent the “Unable to resolve FQDN” error when connecting to the server, it is recommended to ensure that the local
/etc/hosts
file has been configured with the correct FQDN value of the server, or that the DNS service has been properly set up.
Installation Verification
After completing the above installation and configuration, and confirming that the TDengine service has started running normally, you can now use the TDengine CLI tool to log in.
- Linux
- Windows
- MacOS
In the Linux shell, execute taos
directly to connect to the TDengine service, entering the TDengine CLI interface, as shown below:
$ taos
taos> show databases;
name |
=================================
information_schema |
performance_schema |
db |
Query OK, 3 rows in database (0.019154s)
taos>
In the cmd, navigate to the C:\TDengine directory and directly execute taos.exe
to connect to the TDengine service, entering the TDengine CLI interface. An example is shown below:
taos> show databases;
name | create_time | vgroups | ntables | replica | strict | duration | keep | buffer | pagesize | pages | minrows | maxrows | comp | precision | status | retention | single_stable | cachemodel | cachesize | wal_level | wal_fsync_period | wal_retention_period | wal_retention_size |
===============================================================================================================================================================================================================================================================================================================================================================================================================================
information_schema | NULL | NULL | 14 | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | ready | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL |
performance_schema | NULL | NULL | 3 | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | ready | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL |
test | 2022-08-04 16:46:40.506 | 2 | 0 | 1 | off | 14400m | 5256000m,5256000m,5256000m | 96 | 4 | 256 | 100 | 4096 | 2 | ms | ready | NULL | false | none | 1 | 1 | 3000 | 0 | 0 | 0 | 0 |
Query OK, 3 rows in database (0.123000s)
taos>
In the macOS shell, execute taos
directly to connect to the TDengine service, entering the TDengine CLI interface, as shown below:
$ taos
taos> show databases;
name |
=================================
information_schema |
performance_schema |
db |
Query OK, 3 rows in database (0.019154s)
taos>
📄️ C/C++
C/C++ developers can use the TDengine client driver (i.e., C/C++ connector) to develop their own applications to connect to the TDengine cluster to complete data storage, query, and other functions. The API of the TDengine client driver is similar to the C API of MySQL. When using the application, it is necessary to include the TDengine header file, which lists the function prototypes of the provided API; the application must also link to the corresponding dynamic library on the platform.
📄️ Java
taos-jdbcdriver is the official Java connector for TDengine, allowing Java developers to develop applications that access the TDengine database. taos-jdbcdriver implements the interfaces of the JDBC driver standard.
📄️ Go
driver-go is the official Go language connector for TDengine, implementing the interface of the Go language database/sql package. Go developers can use it to develop applications that access data in the TDengine cluster.
📄️ Rust
taos is the official Rust language connector for TDengine. Rust developers can use it to develop applications that access the TDengine database.
📄️ Python
taospy is the official TDengine python connector, which provides multiple access interfaces for database writing, querying, subscribing, etc.
📄️ Node.js
@tdengine/websocket is the official Node.js language connector for TDengine. Node.js developers can use it to develop applications that access the TDengine database.
📄️ C#
TDengine.Connector is the C# language connector provided by TDengine. C# developers can use it to develop C# applications that access data in the TDengine cluster.
📄️ R
The RJDBC library in R language can enable R language programs to access TDengine data. Here are the installation process, configuration process, and R language example code.
📄️ ODBC
TDengine ODBC is an ODBC driver implemented for TDengine, supporting applications on Windows systems (such as PowerBI and others) as well as user-customized applications to access TDengine databases locally, remotely, and via cloud services through the ODBC standard interface.
📄️ REST API
To support development on various types of platforms, TDengine offers an API that adheres to RESTful design standards, namely the REST API. To minimize the learning curve, unlike other databases' REST API design methods, TDengine operates the database directly through SQL statements contained in the BODY of an HTTP POST request, requiring only one URL.