Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
0b09143f
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
0b09143f
编写于
3月 28, 2022
作者:
D
dingbo
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add python examples
上级
c39ae688
变更
11
隐藏空白更改
内联
并排
Showing
11 changed file
with
52 addition
and
18 deletion
+52
-18
docs-cn/06-insert-data/_py_sql.mdx
docs-cn/06-insert-data/_py_sql.mdx
+3
-0
docs-cn/06-insert-data/_py_stmt.mdx
docs-cn/06-insert-data/_py_stmt.mdx
+3
-0
docs-cn/07-query-data/_py.mdx
docs-cn/07-query-data/_py.mdx
+3
-0
docs-cn/07-query-data/_py_async.mdx
docs-cn/07-query-data/_py_async.mdx
+3
-0
docs-examples/python/async_query_example.py
docs-examples/python/async_query_example.py
+1
-0
docs-examples/python/bind_param_example.py
docs-examples/python/bind_param_example.py
+1
-0
docs-examples/python/json_protocol_example.py
docs-examples/python/json_protocol_example.py
+10
-6
docs-examples/python/line_protocol_example.py
docs-examples/python/line_protocol_example.py
+10
-6
docs-examples/python/native_insert_example.py
docs-examples/python/native_insert_example.py
+1
-0
docs-examples/python/query_example.py
docs-examples/python/query_example.py
+7
-0
docs-examples/python/telnet_line_protocol_example.py
docs-examples/python/telnet_line_protocol_example.py
+10
-6
未找到文件。
docs-cn/06-insert-data/_py_sql.mdx
浏览文件 @
0b09143f
```py
{{#include docs-examples/python/native_insert_example.py}}
```
docs-cn/06-insert-data/_py_stmt.mdx
浏览文件 @
0b09143f
```py
{{#include docs-examples/python/bind_param_example.py}}
```
\ No newline at end of file
docs-cn/07-query-data/_py.mdx
浏览文件 @
0b09143f
```py
{{#include docs-examples/python/query_example.py}}
```
docs-cn/07-query-data/_py_async.mdx
浏览文件 @
0b09143f
```py
{{#include docs-examples/python/async_query_example.py}}
```
docs-examples/python/async_query_example.py
0 → 100644
浏览文件 @
0b09143f
import
taos
\ No newline at end of file
docs-examples/python/bind_param_example.py
0 → 100644
浏览文件 @
0b09143f
import
taos
\ No newline at end of file
docs-examples/python/json_protocol_example.py
浏览文件 @
0b09143f
...
...
@@ -9,16 +9,18 @@ lines = [[{"metric": "meters.current", "timestamp": 1648432611249, "value": 10.3
{
"metric"
:
"meters.voltage"
,
"timestamp"
:
1648432611250
,
"value"
:
221
,
"tags"
:
{
"location"
:
"Beijing.Haidian"
,
"groupid"
:
1
}}]
]
# create connection use firstEP in taos.cfg.
conn
=
taos
.
connect
()
def
get_connection
():
# create connection use firstEp in taos.cfg.
return
taos
.
connect
()
def
create_database
():
def
create_database
(
conn
):
conn
.
execute
(
"create database test"
)
conn
.
execute
(
"use test"
)
def
insert_lines
():
def
insert_lines
(
conn
):
global
lines
lines
=
[
json
.
dumps
(
line
)
for
line
in
lines
]
print
(
lines
)
...
...
@@ -27,5 +29,7 @@ def insert_lines():
if
__name__
==
'__main__'
:
create_database
()
insert_lines
()
connection
=
get_connection
()
create_database
(
connection
)
insert_lines
(
connection
)
connection
.
close
()
docs-examples/python/line_protocol_example.py
浏览文件 @
0b09143f
...
...
@@ -11,21 +11,25 @@ lines = ["meters,location=Beijing.Chaoyang,groupid=2 current=10.3,voltage=219,ph
"meters,location=Beijing.Haidian,groupid=3 current=11.3,voltage=221,phase=0.35 1648432611249800"
,
]
# create connection use firstEP in taos.cfg.
conn
=
taos
.
connect
()
def
get_connection
():
# create connection use firstEP in taos.cfg.
return
taos
.
connect
()
def
create_database
():
def
create_database
(
conn
):
# the default precision is ms (microsecond), but we use us(microsecond) here.
conn
.
execute
(
"create database test precision 'us'"
)
conn
.
execute
(
"use test"
)
def
insert_lines
():
def
insert_lines
(
conn
):
affected_rows
=
conn
.
schemaless_insert
(
lines
,
SmlProtocol
.
LINE_PROTOCOL
,
SmlPrecision
.
MICRO_SECONDS
)
print
(
affected_rows
)
# 8
if
__name__
==
'__main__'
:
create_database
()
insert_lines
()
connection
=
get_connection
()
create_database
(
connection
)
insert_lines
(
connection
)
connection
.
close
()
docs-examples/python/native_insert_example.py
0 → 100644
浏览文件 @
0b09143f
import
taos
\ No newline at end of file
docs-examples/python/query_example.py
0 → 100644
浏览文件 @
0b09143f
import
taos
conn
=
taos
.
connect
()
def
print_all
():
result
=
conn
.
query
()
docs-examples/python/telnet_line_protocol_example.py
浏览文件 @
0b09143f
...
...
@@ -12,20 +12,24 @@ lines = ["meters.current 1648432611249 10.3 location=Beijing.Chaoyang groupid=2"
"meters.voltage 1648432611250 217 location=Beijing.Haidian groupid=3"
,
]
# create connection use firstEP in taos.cfg.
conn
=
taos
.
connect
()
# create connection use firstEp in taos.cfg.
def
get_connection
():
return
taos
.
connect
()
def
create_database
():
def
create_database
(
conn
):
conn
.
execute
(
"create database test"
)
conn
.
execute
(
"use test"
)
def
insert_lines
():
def
insert_lines
(
conn
):
affected_rows
=
conn
.
schemaless_insert
(
lines
,
SmlProtocol
.
TELNET_PROTOCOL
,
SmlPrecision
.
NOT_CONFIGURED
)
print
(
affected_rows
)
# 8
if
__name__
==
'__main__'
:
create_database
()
insert_lines
()
connection
=
get_connection
()
create_database
(
connection
)
insert_lines
(
connection
)
connection
.
close
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录