Quick Install on Docker
Instruction: https://docs.tdengine.com/get-started/docker/
If Docker is already installed on your computer, pull the latest TDengine Docker container image:
docker pull tdengine/tdengine:latest
Or the container image of specific version:
docker pull tdengine/tdengine:3.0.1.4
And then run the following command:
docker run -d -p 6030:6030 -p 6041:6041 -p 6043-6049:6043-6049 -p 6043-6049:6043-6049/udp tdengine/tdengine
Note that TDengine Server 3.0 uses TCP port 6030. Port 6041 is used by taosAdapter for the REST API service. Ports 6043 through 6049 are used by taosAdapter for other connectors. You can open these ports as needed.
Run the following command to ensure that your container is running:
docker ps
Enter the container and open the bash shell:
docker exec -it <container name> bash
Install driver
wget https://tdengine.com/assets-download/3.0/TDengine-client-3.0.3.0-Linux-x64.tar.gz
wget https://tdengine.com/assets-download/3.0/TDengine-server-3.0.3.0-Linux-x64.deb
Used with pandas
Instruction: https://docs.tdengine.com/reference/connector/python/#installation
Install taos
pip3 install taospy
import taos
conn: taos.TaosConnection = taos.connect(host="localhost",
user="root",
password="taosdata",
database="test",
port=6030,
config="/etc/taos", # for windows the default value is C:\TDengine\cfg
timezone="Asia/Shanghai") # default your host's timezone
server_version = conn.server_info
print("server_version", server_version)
client_version = conn.client_info
print("client_version", client_version) # 3.0.0.0
conn.close()
# possible output:
# 3.0.0.0
# 3.0.0.0
Native connection with pandas
# use rest api
import pandas
from sqlalchemy import create_engine, text
engine = create_engine("taosrest://root:taosdata@localhost:6041")
conn = engine.connect()
df: pandas.DataFrame = pandas.read_sql(text("SELECT * FROM power.meters"), conn)
conn.close()
# print index
print(df.index)
# print data type of element in ts column
print(type(df.ts[0]))
print(df.head(3))
# use native connection
import taos
import pandas as pd
conn = taos.connect(host='localhost:6041', user='root', password='taosdata')
cursor = conn.cursor()
sql = "SHOW DATABASES"
dataframe = pd.read_sql(sql, conn)
print(dataframe)
# build into image
from taosrest import connect, TaosRestConnection, TaosRestCursor
conn = connect(url="http://192.168.1.132:6041",
user="root",
password="taosdata",
timeout=30)
cursor = conn.cursor()
sql = "SHOW DATABASES"
cursor.execute(sql)
data = cursor.fetchall()
for row in data:
print(row)
import requests
import json
url = "http://192.168.1.132:8080/device/command/set?key=1"
payload = json.dumps({
"deviceName": "m0",
"command": "ON_OFF_Write",
"data": {
"ON_OFF_Write": "1"
}
})
headers = {
'Authorization': f'{token}',
'User-Agent': 'Apifox/1.0.0 (https://www.apifox.cn)',
'Content-Type': 'application/json'
}
response = requests.request("PUT", url, headers=headers, data=payload)
print(response.text)