Skip to content

Commit 2a3de10

Browse files
committed
The tree model Python SDK supports SSL encryption
1 parent 723d61e commit 2a3de10

8 files changed

Lines changed: 753 additions & 0 deletions

File tree

src/UserGuide/Master/Tree/API/Programming-Python-Native-API.md

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ Notice: this RPC compression status of client must comply with that of IoTDB ser
9494
```python
9595
session.close()
9696
```
97+
9798
## 4. Managing Session through SessionPool
9899

99100
Utilizing SessionPool to manage sessions eliminates the need to worry about session reuse. When the number of session connections reaches the maximum capacity of the pool, requests for acquiring a session will be blocked, and you can set the blocking wait time through parameters. After using a session, it should be returned to the SessionPool using the `putBack` method for proper management.
@@ -131,6 +132,99 @@ session_pool.put_back(session)
131132
# When closing the sessionPool, all managed sessions will be closed as well
132133
session_pool.close()
133134
```
135+
### 4.4 SSL Connection
136+
137+
#### 4.4.1 Server Certificate Configuration
138+
139+
In the `conf/iotdb-system.properties` configuration file, locate or add the following configuration items:
140+
141+
```Java
142+
enable_thrift_ssl=true
143+
key_store_path=/path/to/your/server_keystore.jks
144+
key_store_pwd=your_keystore_password
145+
```
146+
147+
#### 4.4.2 Configure Python Client Certificate
148+
149+
- Set `use_ssl` to True to enable SSL.
150+
- Specify the client certificate path using the `ca_certs` parameter.
151+
152+
```Java
153+
use_ssl = True
154+
ca_certs = "/path/to/your/server.crt" # 或 ca_certs = "/path/to/your//ca_cert.pem"
155+
```
156+
**Example Code: Using SSL to Connect to IoTDB**
157+
158+
```Java
159+
# Licensed to the Apache Software Foundation (ASF) under one
160+
# or more contributor license agreements. See the NOTICE file
161+
# distributed with this work for additional information
162+
# regarding copyright ownership. The ASF licenses this file
163+
# to you under the Apache License, Version 2.0 (the
164+
# "License"); you may not use this file except in compliance
165+
# with the License. You may obtain a copy of the License at
166+
#
167+
# http://www.apache.org/licenses/LICENSE-2.0
168+
#
169+
# Unless required by applicable law or agreed to in writing,
170+
# software distributed under the License is distributed on an
171+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
172+
# KIND, either express or implied. See the License for the
173+
# specific language governing permissions and limitations
174+
# under the License.
175+
#
176+
177+
from iotdb.SessionPool import PoolConfig, SessionPool
178+
from iotdb.Session import Session
179+
180+
ip = "127.0.0.1"
181+
port_ = "6667"
182+
username_ = "root"
183+
password_ = "root"
184+
# Configure SSL enabled
185+
use_ssl = True
186+
# Configure certificate path
187+
ca_certs = "/path/server.crt"
188+
189+
190+
def get_data():
191+
session = Session(
192+
ip, port_, username_, password_, use_ssl=use_ssl, ca_certs=ca_certs
193+
)
194+
session.open(False)
195+
result = session.execute_query_statement("select * from root.eg.etth")
196+
df = result.todf()
197+
df.rename(columns={"Time": "date"}, inplace=True)
198+
session.close()
199+
return df
200+
201+
202+
def get_data2():
203+
pool_config = PoolConfig(
204+
host=ip,
205+
port=port_,
206+
user_name=username_,
207+
password=password_,
208+
fetch_size=1024,
209+
time_zone="UTC+8",
210+
max_retry=3,
211+
use_ssl=use_ssl,
212+
ca_certs=ca_certs,
213+
)
214+
max_pool_size = 5
215+
wait_timeout_in_ms = 3000
216+
session_pool = SessionPool(pool_config, max_pool_size, wait_timeout_in_ms)
217+
session = session_pool.get_session()
218+
result = session.execute_query_statement("select * from root.eg.etth")
219+
df = result.todf()
220+
df.rename(columns={"Time": "date"}, inplace=True)
221+
session_pool.put_back(session)
222+
session_pool.close()
223+
224+
225+
if __name__ == "__main__":
226+
df = get_data()
227+
```
134228

135229
## 5. Data Definition Interface (DDL Interface)
136230

src/UserGuide/V1.3.x/API/Programming-Python-Native-API.md

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,101 @@ session_pool.put_back(session)
131131
session_pool.close()
132132
```
133133

134+
### SSL Connection
135+
136+
#### Server Certificate Configuration
137+
138+
In the `conf/iotdb-system.properties` configuration file, locate or add the following configuration items:
139+
140+
```Java
141+
enable_thrift_ssl=true
142+
key_store_path=/path/to/your/server_keystore.jks
143+
key_store_pwd=your_keystore_password
144+
```
145+
146+
#### Configure Python Client Certificate
147+
148+
- Set `use_ssl` to True to enable SSL.
149+
- Specify the client certificate path using the `ca_certs` parameter.
150+
151+
```Java
152+
use_ssl = True
153+
ca_certs = "/path/to/your/server.crt" # 或 ca_certs = "/path/to/your//ca_cert.pem"
154+
```
155+
**Example Code: Using SSL to Connect to IoTDB**
156+
157+
```Java
158+
# Licensed to the Apache Software Foundation (ASF) under one
159+
# or more contributor license agreements. See the NOTICE file
160+
# distributed with this work for additional information
161+
# regarding copyright ownership. The ASF licenses this file
162+
# to you under the Apache License, Version 2.0 (the
163+
# "License"); you may not use this file except in compliance
164+
# with the License. You may obtain a copy of the License at
165+
#
166+
# http://www.apache.org/licenses/LICENSE-2.0
167+
#
168+
# Unless required by applicable law or agreed to in writing,
169+
# software distributed under the License is distributed on an
170+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
171+
# KIND, either express or implied. See the License for the
172+
# specific language governing permissions and limitations
173+
# under the License.
174+
#
175+
176+
from iotdb.SessionPool import PoolConfig, SessionPool
177+
from iotdb.Session import Session
178+
179+
ip = "127.0.0.1"
180+
port_ = "6667"
181+
username_ = "root"
182+
password_ = "root"
183+
# Configure SSL enabled
184+
use_ssl = True
185+
# Configure certificate path
186+
ca_certs = "/path/server.crt"
187+
188+
189+
def get_data():
190+
session = Session(
191+
ip, port_, username_, password_, use_ssl=use_ssl, ca_certs=ca_certs
192+
)
193+
session.open(False)
194+
result = session.execute_query_statement("select * from root.eg.etth")
195+
df = result.todf()
196+
df.rename(columns={"Time": "date"}, inplace=True)
197+
session.close()
198+
return df
199+
200+
201+
def get_data2():
202+
pool_config = PoolConfig(
203+
host=ip,
204+
port=port_,
205+
user_name=username_,
206+
password=password_,
207+
fetch_size=1024,
208+
time_zone="UTC+8",
209+
max_retry=3,
210+
use_ssl=use_ssl,
211+
ca_certs=ca_certs,
212+
)
213+
max_pool_size = 5
214+
wait_timeout_in_ms = 3000
215+
session_pool = SessionPool(pool_config, max_pool_size, wait_timeout_in_ms)
216+
session = session_pool.get_session()
217+
result = session.execute_query_statement("select * from root.eg.etth")
218+
df = result.todf()
219+
df.rename(columns={"Time": "date"}, inplace=True)
220+
session_pool.put_back(session)
221+
session_pool.close()
222+
223+
224+
if __name__ == "__main__":
225+
df = get_data()
226+
```
227+
228+
134229
## Data Definition Interface (DDL Interface)
135230

136231
### Database Management

src/UserGuide/dev-1.3/API/Programming-Python-Native-API.md

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,100 @@ session_pool.put_back(session)
131131
session_pool.close()
132132
```
133133

134+
### SSL Connection
135+
136+
#### Server Certificate Configuration
137+
138+
In the `conf/iotdb-system.properties` configuration file, locate or add the following configuration items:
139+
140+
```Java
141+
enable_thrift_ssl=true
142+
key_store_path=/path/to/your/server_keystore.jks
143+
key_store_pwd=your_keystore_password
144+
```
145+
146+
#### Configure Python Client Certificate
147+
148+
- Set `use_ssl` to True to enable SSL.
149+
- Specify the client certificate path using the `ca_certs` parameter.
150+
151+
```Java
152+
use_ssl = True
153+
ca_certs = "/path/to/your/server.crt" # 或 ca_certs = "/path/to/your//ca_cert.pem"
154+
```
155+
**Example Code: Using SSL to Connect to IoTDB**
156+
157+
```Java
158+
# Licensed to the Apache Software Foundation (ASF) under one
159+
# or more contributor license agreements. See the NOTICE file
160+
# distributed with this work for additional information
161+
# regarding copyright ownership. The ASF licenses this file
162+
# to you under the Apache License, Version 2.0 (the
163+
# "License"); you may not use this file except in compliance
164+
# with the License. You may obtain a copy of the License at
165+
#
166+
# http://www.apache.org/licenses/LICENSE-2.0
167+
#
168+
# Unless required by applicable law or agreed to in writing,
169+
# software distributed under the License is distributed on an
170+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
171+
# KIND, either express or implied. See the License for the
172+
# specific language governing permissions and limitations
173+
# under the License.
174+
#
175+
176+
from iotdb.SessionPool import PoolConfig, SessionPool
177+
from iotdb.Session import Session
178+
179+
ip = "127.0.0.1"
180+
port_ = "6667"
181+
username_ = "root"
182+
password_ = "root"
183+
# Configure SSL enabled
184+
use_ssl = True
185+
# Configure certificate path
186+
ca_certs = "/path/server.crt"
187+
188+
189+
def get_data():
190+
session = Session(
191+
ip, port_, username_, password_, use_ssl=use_ssl, ca_certs=ca_certs
192+
)
193+
session.open(False)
194+
result = session.execute_query_statement("select * from root.eg.etth")
195+
df = result.todf()
196+
df.rename(columns={"Time": "date"}, inplace=True)
197+
session.close()
198+
return df
199+
200+
201+
def get_data2():
202+
pool_config = PoolConfig(
203+
host=ip,
204+
port=port_,
205+
user_name=username_,
206+
password=password_,
207+
fetch_size=1024,
208+
time_zone="UTC+8",
209+
max_retry=3,
210+
use_ssl=use_ssl,
211+
ca_certs=ca_certs,
212+
)
213+
max_pool_size = 5
214+
wait_timeout_in_ms = 3000
215+
session_pool = SessionPool(pool_config, max_pool_size, wait_timeout_in_ms)
216+
session = session_pool.get_session()
217+
result = session.execute_query_statement("select * from root.eg.etth")
218+
df = result.todf()
219+
df.rename(columns={"Time": "date"}, inplace=True)
220+
session_pool.put_back(session)
221+
session_pool.close()
222+
223+
224+
if __name__ == "__main__":
225+
df = get_data()
226+
```
227+
134228
## Data Definition Interface (DDL Interface)
135229

136230
### Database Management

0 commit comments

Comments
 (0)