Skip to content

Commit e34df76

Browse files
author
liyan.90210
committed
feat auto update sdk
1 parent 9d20d7b commit e34df76

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+7915
-103
lines changed

Changelog

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
### Change log
22

3+
2026-01-08 Bumped to version v1.0.213
4+
- Updated apis for tls
5+
36
2025-12-25 Bumped to version v1.0.212
47
- Updated apis for tls
58

README.EN.MD

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
English | [中文](README.md)
2+
3+
<h1 align="center"><img src="https://iam.volccdn.com/obj/volcengine-public/pic/volcengine-icon.png"></h1>
4+
<h1 align="center">Volcengine SDK for Python</h1>
5+
6+
Welcome to Volcengine SDK for Python. This document explains how to obtain and use the SDK.
7+
8+
## Prerequisites
9+
10+
### Enable the service
11+
12+
Make sure the service you want to access is enabled. Go to the [Volcengine Console](https://console.volcengine.com/), select the service from the left navigation (or search it from the top bar), and complete the activation process in the service console.
13+
14+
### Obtain security credentials
15+
16+
Access Key is the credential used to access Volcengine services. It consists of Access Key ID (AK) and Secret Access Key (SK).
17+
18+
Log in to the [Volcengine Console](https://console.volcengine.com/), then go to [IAM](https://console.volcengine.com/iam) -> [Access Keys](https://console.volcengine.com/iam/keymanage/) to create and manage your Access Keys. For more information, see the [Access Key documentation](https://www.volcengine.com/docs/6291/65568).
19+
20+
### Environment check
21+
22+
Python version must be **3.7** or later.
23+
24+
## Install
25+
26+
Install the SDK via pip:
27+
28+
```bash
29+
pip install --user volcengine
30+
```
31+
32+
If `volcengine` is already installed, upgrade it with:
33+
34+
```bash
35+
pip install --upgrade volcengine
36+
```
37+
38+
## Configuration
39+
40+
### Credential configuration
41+
42+
Volcengine SDK for Python supports the following credential loading methods.
43+
44+
*Note: Replace `Your AK` and `Your SK` in the code with your actual AK and SK.*
45+
46+
**Method 1**: Set AK/SK on the client **(recommended)**
47+
48+
```python
49+
iam_service = IamService()
50+
iam_service.set_ak('Your AK')
51+
iam_service.set_sk('Your SK')
52+
```
53+
54+
**Method 2**: Load AK/SK from environment variables
55+
56+
```bash
57+
VOLC_ACCESSKEY="Your AK"
58+
VOLC_SECRETKEY="Your SK"
59+
```
60+
61+
**Method 3**: Load AK/SK from a file under HOME
62+
63+
Add the following content to `~/.volc/config`:
64+
65+
```json
66+
{
67+
"ak": "Your AK",
68+
"sk": "Your SK"
69+
}
70+
```
71+
72+
## Other resources
73+
74+
### Some service directories and examples
75+
76+
- [Visual Intelligence](volcengine/visual/README.md)
77+
- [NLP](volcengine/nlp/README.md)

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
中文 | [English](README.EN.MD)
2+
13
<h1 align="center"><img src="https://iam.volccdn.com/obj/volcengine-public/pic/volcengine-icon.png"></h1>
24
<h1 align="center">火山引擎SDK for Python</h1>
35
欢迎使用火山引擎SDK for Python,本文档为您介绍如何获取及调用SDK。

volcengine/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# coding:utf-8
2-
VERSION='v1.0.212'
2+
VERSION='v1.0.213'
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# coding=utf-8
2+
from __future__ import absolute_import
3+
from __future__ import division
4+
from __future__ import print_function
5+
6+
import os
7+
import time
8+
9+
from volcengine.tls.TLSService import TLSService
10+
from volcengine.tls.tls_requests import *
11+
12+
13+
if __name__ == "__main__":
14+
# 初始化客户端,推荐通过环境变量动态获取火山引擎密钥等身份认证信息,
15+
# 以免AccessKey硬编码引发数据安全风险。详细说明请参考
16+
# https://www.volcengine.com/docs/6470/1166455
17+
# 使用STS时,ak和sk均使用临时密钥,且设置VOLCENGINE_TOKEN;不使用STS时,VOLCENGINE_TOKEN部分传空
18+
endpoint = os.environ["VOLCENGINE_ENDPOINT"]
19+
region = os.environ["VOLCENGINE_REGION"]
20+
access_key_id = os.environ["VOLCENGINE_ACCESS_KEY_ID"]
21+
access_key_secret = os.environ["VOLCENGINE_ACCESS_KEY_SECRET"]
22+
23+
# 实例化TLS客户端
24+
tls_service = TLSService(endpoint, access_key_id, access_key_secret, region)
25+
now = str(int(time.time()))
26+
27+
# 创建日志项目
28+
create_project_request = CreateProjectRequest(project_name="project-name-" + now, region=region,
29+
description="project-description")
30+
create_project_response = tls_service.create_project(create_project_request)
31+
project_id = create_project_response.get_project_id()
32+
33+
# 创建源日志主题
34+
create_source_topic_request = CreateTopicRequest(
35+
topic_name="source-topic-name-" + now,
36+
project_id=project_id,
37+
ttl=3650,
38+
description="source-topic-description",
39+
shard_count=2,
40+
)
41+
create_source_topic_response = tls_service.create_topic(create_source_topic_request)
42+
source_topic_id = create_source_topic_response.get_topic_id()
43+
44+
# 创建目标日志主题
45+
create_target_topic_request = CreateTopicRequest(
46+
topic_name="target-topic-name-" + now,
47+
project_id=project_id,
48+
ttl=3650,
49+
description="target-topic-description",
50+
shard_count=2,
51+
)
52+
create_target_topic_response = tls_service.create_topic(create_target_topic_request)
53+
target_topic_id = create_target_topic_response.get_topic_id()
54+
55+
# 创建ETL任务
56+
# 请根据您的需要,填写相关参数
57+
# CreateETLTask API的请求参数规范请参阅相关文档
58+
create_etl_task_request = CreateETLTaskRequest(
59+
dsl_type="NORMAL",
60+
name="etl-task-name-" + now,
61+
description="etl-task-description",
62+
enable=True,
63+
source_topic_id=source_topic_id,
64+
script='f_set("key", "value")',
65+
task_type="Resident",
66+
target_resources=[
67+
{
68+
"alias": "test",
69+
"topic_id": target_topic_id,
70+
"region": region
71+
}
72+
]
73+
)
74+
create_etl_task_response = tls_service.create_etl_task(create_etl_task_request)
75+
etl_task_id = create_etl_task_response.get_task_id()
76+
77+
print(f"ETL Task created successfully, task_id: {etl_task_id}")
78+
79+
# 删除日志主题
80+
delete_source_topic_request = DeleteTopicRequest(source_topic_id)
81+
tls_service.delete_topic(delete_source_topic_request)
82+
83+
delete_target_topic_request = DeleteTopicRequest(target_topic_id)
84+
tls_service.delete_topic(delete_target_topic_request)
85+
86+
# 删除日志项目
87+
delete_project_request = DeleteProjectRequest(project_id=project_id)
88+
tls_service.delete_project(delete_project_request)
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
# coding=utf-8
2+
import os
3+
import time
4+
import uuid
5+
6+
from volcengine.tls.TLSService import TLSService
7+
from volcengine.tls.tls_requests import *
8+
9+
10+
if __name__ == "__main__":
11+
# 初始化客户端,需要设置AccessKey ID/AccessKey Secret,以及服务地域
12+
endpoint = os.environ["VOLCENGINE_ENDPOINT"]
13+
region = os.environ["VOLCENGINE_REGION"]
14+
access_key_id = os.environ["VOLCENGINE_ACCESS_KEY_ID"]
15+
access_key_secret = os.environ["VOLCENGINE_ACCESS_KEY_SECRET"]
16+
17+
# 创建TLS客户端
18+
tls_service = TLSService(endpoint, access_key_id, access_key_secret, region)
19+
20+
# 创建项目和主题用于测试
21+
project_name = f"tls-python-sdk-schedule-project-{uuid.uuid4().hex}"
22+
source_topic_name = f"tls-python-sdk-schedule-source-topic-{uuid.uuid4().hex}"
23+
dest_topic_name = f"tls-python-sdk-schedule-dest-topic-{uuid.uuid4().hex}"
24+
25+
# 创建项目
26+
create_project_request = CreateProjectRequest(
27+
project_name=project_name,
28+
region=region,
29+
)
30+
create_project_response = tls_service.create_project(create_project_request)
31+
project_id = create_project_response.get_project_id()
32+
print(f"Created project: {project_id}")
33+
34+
# 创建源主题
35+
create_source_topic_request = CreateTopicRequest(
36+
project_id=project_id,
37+
topic_name=source_topic_name,
38+
shard_count=1,
39+
ttl=1,
40+
)
41+
create_source_topic_response = tls_service.create_topic(create_source_topic_request)
42+
source_topic_id = create_source_topic_response.get_topic_id()
43+
print(f"Created source topic: {source_topic_id}")
44+
45+
# 创建目标主题
46+
create_dest_topic_request = CreateTopicRequest(
47+
project_id=project_id,
48+
topic_name=dest_topic_name,
49+
shard_count=1,
50+
ttl=1,
51+
)
52+
create_dest_topic_response = tls_service.create_topic(create_dest_topic_request)
53+
dest_topic_id = create_dest_topic_response.get_topic_id()
54+
print(f"Created dest topic: {dest_topic_id}")
55+
56+
# 为源主题创建索引
57+
create_index_request = CreateIndexRequest(
58+
topic_id=source_topic_id,
59+
full_text=FullTextInfo(
60+
delimiter=",; ",
61+
case_sensitive=False,
62+
include_chinese=False,
63+
),
64+
)
65+
create_index_response = tls_service.create_index(create_index_request)
66+
print(f"Created index for source topic: {create_index_response.get_request_id()}")
67+
68+
# 创建定时SQL任务
69+
current_time = int(time.time())
70+
task_name = f"tls-python-sdk-schedule-task-{uuid.uuid4().hex}"
71+
create_schedule_sql_task_request = CreateScheduleSqlTaskRequest(
72+
task_name=task_name,
73+
topic_id=source_topic_id,
74+
dest_topic_id=dest_topic_id,
75+
process_start_time=current_time + 3600, # 1小时后开始
76+
process_time_window="@m-15m,@m",
77+
query="* | select count(*) as count",
78+
request_cycle=RequestCycle(
79+
cycle_type="Period",
80+
time=60, # 每60分钟执行一次
81+
),
82+
status=0, # 关闭任务,后续需手动启动
83+
description="测试定时SQL任务",
84+
process_sql_delay=60,
85+
)
86+
87+
create_schedule_sql_task_response = tls_service.create_schedule_sql_task(
88+
create_schedule_sql_task_request)
89+
task_id = create_schedule_sql_task_response.get_task_id()
90+
print(f"Created schedule SQL task: {task_id}")
91+
92+
# 清理资源
93+
print("Cleaning up resources...")
94+
# 删除目标主题
95+
delete_dest_topic_request = DeleteTopicRequest(topic_id=dest_topic_id)
96+
tls_service.delete_topic(delete_dest_topic_request)
97+
print(f"Deleted dest topic: {dest_topic_id}")
98+
99+
# 删除源主题
100+
delete_source_topic_request = DeleteTopicRequest(topic_id=source_topic_id)
101+
tls_service.delete_topic(delete_source_topic_request)
102+
print(f"Deleted source topic: {source_topic_id}")
103+
104+
# 删除项目
105+
delete_project_request = DeleteProjectRequest(project_id=project_id)
106+
tls_service.delete_project(delete_project_request)
107+
print(f"Deleted project: {project_id}")
108+
109+
print("Example completed successfully!")

0 commit comments

Comments
 (0)