From f82b92ed1b8291852bc5a79e2d882fb9d6240571 Mon Sep 17 00:00:00 2001 From: menshibin Date: Thu, 1 Aug 2024 20:13:35 +0800 Subject: [PATCH] modify python api --- .../node/websocketexample/sql_example.js | 2 +- docs/examples/python/connect_example.py | 7 +-- .../08-develop/01-connect/_connect_python.mdx | 13 +----- docs/zh/08-develop/01-connect/index.md | 17 +++---- .../14-reference/05-connector/30-python.mdx | 46 ++++++++----------- 5 files changed, 31 insertions(+), 54 deletions(-) diff --git a/docs/examples/node/websocketexample/sql_example.js b/docs/examples/node/websocketexample/sql_example.js index 484559e2b3..836fb68829 100644 --- a/docs/examples/node/websocketexample/sql_example.js +++ b/docs/examples/node/websocketexample/sql_example.js @@ -1,6 +1,6 @@ +// ANCHOR: createConnect const taos = require("@tdengine/websocket"); -// ANCHOR: createConnect async function createConnect() { let dsn = 'ws://localhost:6041'; let conf = new taos.WSConfig(dsn); diff --git a/docs/examples/python/connect_example.py b/docs/examples/python/connect_example.py index 719af79fd1..c31e1cac51 100644 --- a/docs/examples/python/connect_example.py +++ b/docs/examples/python/connect_example.py @@ -1,19 +1,14 @@ import taos - def test_connection(): # all parameters are optional. - # if database is specified, - # then it must exist. conn = taos.connect(host="localhost", port=6030, user="root", - password="taosdata", - database="log") + password="taosdata") print('client info:', conn.client_info) print('server info:', conn.server_info) conn.close() - if __name__ == "__main__": test_connection() diff --git a/docs/zh/08-develop/01-connect/_connect_python.mdx b/docs/zh/08-develop/01-connect/_connect_python.mdx index 222c92fc0d..8b04088ac3 100644 --- a/docs/zh/08-develop/01-connect/_connect_python.mdx +++ b/docs/zh/08-develop/01-connect/_connect_python.mdx @@ -1,14 +1,3 @@ -```text -[+]://[[:@]:][/][?=[&=]] -|------------|---|-----------|-----------|------|------|------------|-----------------------| -| protocol | | username | password | host | port | database | params | -- **protocol**: Display using websocket protocol to establish connection. -- **username/password**: Database's username and password. -- **host/port**: Declare host and port. eg. `localhost:6041` -- **database**: Optional, use to specify database name. -- **params**: Other parameters. Like cloud Token. -``` - ```python -{{#include docs/examples/python/connect_websocket_examples.py:connect}} +{{#include docs/examples/python/connect_example.py}} ``` diff --git a/docs/zh/08-develop/01-connect/index.md b/docs/zh/08-develop/01-connect/index.md index d5678bff51..42da8b8352 100644 --- a/docs/zh/08-develop/01-connect/index.md +++ b/docs/zh/08-develop/01-connect/index.md @@ -379,10 +379,9 @@ URL 和 Properties 的详细参数说明和如何使用详见 [API 说明](../.. ``` - - ```python - {{#include docs/examples/python/connect_websocket_examples.py:connect}} - ``` +```python +{{#include docs/examples/python/connect_websocket_examples.py:connect}} +``` @@ -391,9 +390,9 @@ URL 和 Properties 的详细参数说明和如何使用详见 [API 说明](../.. - ```js - {{#include docs/examples/node/websocketexample/sql_example.js:createConnect}} - ``` +```js +{{#include docs/examples/node/websocketexample/sql_example.js:createConnect}} +``` @@ -452,7 +451,9 @@ URL 和 Properties 的详细参数说明和如何使用详见 [API 说明](../.. ``` - +```python +{{#include docs/examples/python/connect_rest_examples.py:connect}} +``` diff --git a/docs/zh/14-reference/05-connector/30-python.mdx b/docs/zh/14-reference/05-connector/30-python.mdx index 7f5897c021..cbc0436010 100644 --- a/docs/zh/14-reference/05-connector/30-python.mdx +++ b/docs/zh/14-reference/05-connector/30-python.mdx @@ -115,11 +115,6 @@ TDengine 目前支持时间戳、数字、字符、布尔类型,与 Python 对 1. https://stackoverflow.com/questions/10611328/parsing-datetime-strings-containing-nanoseconds 2. https://www.python.org/dev/peps/pep-0564/ - -## API 参考 - -- [taos](https://docs.taosdata.com/api/taospy/taos/) -- [taosrest](https://docs.taosdata.com/api/taospy/taosrest) ## 常见问题 @@ -127,10 +122,9 @@ TDengine 目前支持时间戳、数字、字符、布尔类型,与 Python 对 ## API 参考 - - +### WebSocket 连接 -### URL 规范 +#### URL 规范 ```text [+]://[[:@]:][/][?=[&=]] @@ -144,7 +138,7 @@ TDengine 目前支持时间戳、数字、字符、布尔类型,与 Python 对 - **database**: 数据库名称。 - **params**: 其他参数。 例如token。 -### 建立连接 +#### 建立连接 - `fn connect(dsn: Option<&str>, args: Option<&PyDict>) -> PyResult` - **接口说明**:建立 taosAdapter 连接。 @@ -163,7 +157,7 @@ TDengine 目前支持时间戳、数字、字符、布尔类型,与 Python 对 - **返回值**:数据库游标对象。 - **异常**:操作失败抛出 `ConnectionError` 异常。 -### 执行SQL +#### 执行SQL - `fn execute(&self, sql: &str) -> PyResult` - **接口说明**:执行 sql 语句。 @@ -192,7 +186,7 @@ TDengine 目前支持时间戳、数字、字符、布尔类型,与 Python 对 - **返回值**:`TaosResult` 数据集对象。 - **异常**:操作失败抛出 `QueryError` 异常。 -### 数据集 +#### 数据集 TaosResult 对象可以通过循环遍历获取查询到的数据。 @@ -203,7 +197,7 @@ TaosResult 对象可以通过循环遍历获取查询到的数据。 - **接口说明**:获取查询到的记录条数。 - **返回值**:`i32` 查询到的记录条数。 -### 无模式写入 +#### 无模式写入 - `fn schemaless_insert(&self, lines: Vec, protocol: PySchemalessProtocol, precision: PySchemalessPrecision, ttl: i32, req_id: u64) -> PyResult<()>` - **接口说明**:无模式写入。 - **参数说明**: @@ -223,7 +217,7 @@ TaosResult 对象可以通过循环遍历获取查询到的数据。 - `reqId`: 用于问题追踪。 - **异常**:操作失败抛出 `DataError` 或 `OperationalError` 异常。 -### 参数绑定 +#### 参数绑定 - `fn statement(&self) -> PyResult` - **接口说明**:使用 连接 对象创建 stmt 对象。 - **返回值**:stmt 对象。 @@ -261,7 +255,7 @@ TaosResult 对象可以通过循环遍历获取查询到的数据。 - `fn close(&self) -> PyResult<()>` - **接口说明**: 关闭 stmt 对象。 -### 数据订阅 +#### 数据订阅 - **创建消费者支持属性列表**: - host:主机地址。 - port:端口号。 @@ -327,10 +321,10 @@ TaosResult 对象可以通过循环遍历获取查询到的数据。 - `fn close(&mut self)` - **接口说明**:关闭 tmq 连接。 - **异常**:操作失败抛出 ConsumerException 异常。 - - -### 建立连接 +### Native 连接 + +#### 建立连接 - `def connect(*args, **kwargs):` - **接口说明**:建立 taosAdapter 连接。 @@ -348,8 +342,7 @@ TaosResult 对象可以通过循环遍历获取查询到的数据。 - **接口说明**:创建一个新的数据库游标对象,用于执行SQL命令和查询。 - **返回值**:数据库游标对象。 - -### 执行SQL +#### 执行SQL - `def execute(self, operation, req_id: Optional[int] = None)` - **接口说明**:执行 sql 语句。 @@ -366,7 +359,7 @@ TaosResult 对象可以通过循环遍历获取查询到的数据。 - **返回值**:`TaosResult` 数据集对象。 - **异常**:操作失败抛出 `ProgrammingError` 异常。 -### 数据集 +#### 数据集 TaosResult 对象可以通过循环遍历获取查询到的数据。 @@ -380,7 +373,7 @@ TaosResult 对象可以通过循环遍历获取查询到的数据。 - **接口说明**:将所有的记录转换为字典。 - **返回值**:返回字典列表。 -### 无模式写入 +#### 无模式写入 - `def schemaless_insert(&self, lines: List[str], protocol: SmlProtocol, precision: SmlPrecision, req_id: Optional[int] = None, ttl: Optional[int] = None) -> int:` - **接口说明**:无模式写入。 - **参数说明**: @@ -401,7 +394,7 @@ TaosResult 对象可以通过循环遍历获取查询到的数据。 - **返回值**:影响的条数。 - **异常**:操作失败抛出 `SchemalessError` 异常。 -### 参数绑定 +#### 参数绑定 - `def statement(self, sql=None)` - **接口说明**:使用连接对象创建 stmt 对象, 如果 sql 不空会进行调用 prepare。 - `sql`: 预编译的 SQL 语句。 @@ -447,7 +440,7 @@ TaosResult 对象可以通过循环遍历获取查询到的数据。 - `def close(&self)` - **接口说明**: 关闭 stmt 对象。 -### 数据订阅 +#### 数据订阅 - **创建消费者支持属性列表**: - td.connect.ip:主机地址。 - td.connect.port:端口号。 @@ -515,8 +508,9 @@ TaosResult 对象可以通过循环遍历获取查询到的数据。 - `def close(self)` - **接口说明**:关闭 tmq 连接。 - **异常**:操作失败抛出 TmqError 异常。 - - + +### REST 连接 + - `def connect(**kwargs) -> TaosRestConnection` - **接口说明**:建立 taosAdapter 连接。 - **参数说明**: @@ -562,5 +556,3 @@ TaosResult 对象可以通过循环遍历获取查询到的数据。 - `reqId`: 用于问题追踪。 - **返回值**:返回字典列表。 - **异常**:操作失败抛出 `ConnectError` 或 `HTTPError` 异常。 - -