TDengine Python Connector
taospy
is the official Python connector for TDengine. taospy
provides a rich set of APIs that makes it easy for Python applications to access TDengine. taospy
wraps both the native interface and REST interface of TDengine, which correspond to the taos
and taosrest
modules of the taospy
package, respectively.
In addition to wrapping the native and REST interfaces, taospy
also provides a set of programming interfaces that conforms to the Python Data Access Specification (PEP 249). It is easy to integrate taospy
with many third-party tools, such as SQLAlchemy and pandas.
The direct connection to the server using the native interface provided by the client driver is referred to hereinafter as a "native connection"; the connection to the server using the REST interface provided by taosAdapter is referred to hereinafter as a "REST connection".
The source code for the Python connector is hosted on GitHub.
Supported Platforms
- The supported platforms for the native connection are the same as the ones supported by the TDengine client.
- REST connections are supported on all platforms that can run Python.
Version selection
We recommend using the latest version of taospy
, regardless of the version of TDengine.
Supported features
- Native connections support all the core features of TDengine, including connection management, SQL execution, bind interface, subscriptions, and schemaless writing.
- REST connections support features such as connection management and SQL execution. (SQL execution allows you to: manage databases, tables, and supertables, write data, query data, create continuous queries, etc.).
Installation
Preparation
- Install Python. Python >= 3.6 is recommended. If Python is not available on your system, refer to the Python BeginnersGuide to install it.
- Install pip. In most cases, the Python installer comes with the pip utility. If not, please refer to pip documentation to install it.
If you use a native connection, you will also need to Install Client Driver. The client install package includes the TDengine client dynamic link library (libtaos.so
or taos.dll
) and the TDengine CLI.
Install via pip
Uninstalling an older version
If you have installed an older version of the Python Connector, please uninstall it beforehand.
pip3 uninstall taos taospy
Earlier TDengine client software includes the Python connector. If the Python connector is installed from the client package's installation directory, the corresponding Python package name is taos
. So the above uninstall command includes taos
, and it doesn't matter if it doesn't exist.
To install taospy
- Install from PyPI
- Install from GitHub
Install the latest version of:
pip3 install taospy
You can also specify a specific version to install:
pip3 install taospy==2.3.0
pip3 install git+https://github.com/taosdata/taos-connector-python.git
Installation verification
- native connection
- REST connection
For native connection, you need to verify that both the client driver and the Python connector itself are installed correctly. The client driver and Python connector have been installed properly if you can successfully import the taos
module. In the Python Interactive Shell, you can type.
import taos
For REST connections, verifying that the taosrest
module can be imported successfully can be done in the Python Interactive Shell by typing.
import taosrest
If you have multiple versions of Python on your system, you may have various pip
commands. Be sure to use the correct path for the pip
command. Above, we installed the pip3
command, which rules out the possibility of using the pip
corresponding to Python 2.x versions. However, if you have more than one version of Python 3.x on your system, you still need to check that the installation path is correct. The easiest way to verify this is to type pip3 install taospy
again in the command, and it will print out the exact location of taospy
, for example, on Windows.
C:\> pip3 install taospy
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Requirement already satisfied: taospy in c:\users\username\appdata\local\programs\python\python310\lib\site-packages (2.3.0)