aibeta 0.3.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,54 @@
1
+ name: Publish to PyPI
2
+
3
+ # 只在推送 v 开头的 tag 时触发(例如 v0.3.0)
4
+ on:
5
+ push:
6
+ tags:
7
+ - "v*"
8
+
9
+ permissions:
10
+ contents: read
11
+
12
+ jobs:
13
+ build:
14
+ name: Build distributions
15
+ runs-on: ubuntu-latest
16
+ steps:
17
+ - uses: actions/checkout@v4
18
+
19
+ - name: Set up Python
20
+ uses: actions/setup-python@v5
21
+ with:
22
+ python-version: "3.10"
23
+
24
+ - name: Install build tool
25
+ run: python -m pip install --upgrade build
26
+
27
+ - name: Build sdist and wheel
28
+ run: python -m build
29
+
30
+ - name: Store distributions
31
+ uses: actions/upload-artifact@v4
32
+ with:
33
+ name: dist
34
+ path: dist/
35
+
36
+ publish:
37
+ name: Publish to PyPI
38
+ needs: build
39
+ runs-on: ubuntu-latest
40
+ # 环境名必须与 PyPI 上配置的 Trusted Publisher 一致
41
+ environment:
42
+ name: pypi
43
+ url: https://pypi.org/p/aibeta
44
+ permissions:
45
+ id-token: write # Trusted Publishing 必需
46
+ steps:
47
+ - name: Download distributions
48
+ uses: actions/download-artifact@v4
49
+ with:
50
+ name: dist
51
+ path: dist/
52
+
53
+ - name: Publish package distributions to PyPI
54
+ uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,38 @@
1
+ # ---- 虚拟环境(本机相关,勿提交)----
2
+ .venv/
3
+ venv/
4
+ env/
5
+
6
+ # ---- Python 缓存与编译产物 ----
7
+ __pycache__/
8
+ *.py[cod]
9
+ *.pyo
10
+ *.pyd
11
+ *.so
12
+
13
+ # ---- 本机锁文件 / 缓存标记 ----
14
+ .lock
15
+ CACHEDIR.TAG
16
+
17
+ # ---- 构建与打包产物 ----
18
+ dist/
19
+ build/
20
+ *.egg-info/
21
+ *.whl
22
+ *.tar.gz
23
+
24
+ # ---- 测试 / 类型检查 / 覆盖率缓存 ----
25
+ .pytest_cache/
26
+ .mypy_cache/
27
+ .ruff_cache/
28
+ .coverage
29
+ htmlcov/
30
+
31
+ # ---- IDE / 编辑器 ----
32
+ .idea/
33
+ .vscode/
34
+ *.swp
35
+
36
+ # ---- 操作系统 ----
37
+ .DS_Store
38
+ Thumbs.db
@@ -0,0 +1,199 @@
1
+ # 方案:将项目重构为可发布的 `aibeta` Python SDK
2
+
3
+ ## 一、概述(Summary)
4
+
5
+ 将当前「单文件客户端类 + 错误引用」的结构,重构为符合 `examples/import_script.py` 期望调用方式的**模块化 Python SDK**:
6
+
7
+ - 对外只暴露三个入口:`aibeta.configuration(...)`、`aibeta.theme_classification`、`aibeta.beta_indicator`。
8
+ - 隐藏 `IndicatorLibraryClient` 类,用户不再直接 `new` 客户端,而是通过模块级函数调用,由内部共享单例客户端完成取数。
9
+ - 保留现有全部业务逻辑(Token 管理、统一 API 调用、全量快照缓存等),仅调整文件结构与引用关系。
10
+
11
+ 目标调用方式(来自 `import_script.py`):
12
+
13
+ ```python
14
+ import aibeta
15
+
16
+ aibeta.configuration(app_key='XXX', secret_key='XXX')
17
+
18
+ from aibeta import theme_classification
19
+ theme_classification.get_theme_classification_framework_inc("2026-06-26")
20
+ # ... 其余主题分类接口
21
+
22
+ from aibeta import beta_indicator
23
+ beta_indicator.list_indicator_types()
24
+ beta_indicator.get_indicator_value_batch(indicator_id_list)
25
+ # ... 其余指标库接口
26
+ ```
27
+
28
+ ## 二、现状分析(Current State)
29
+
30
+ 当前文件结构:
31
+
32
+ ```
33
+ src/aibeta/__init__.py # 错误地使用绝对导入,且对外暴露了客户端类
34
+ src/aibeta/_beta_indicator_interface.py # 全部逻辑集中在一个类 IndicatorLibraryClient
35
+ examples/my_script.py # 旧式调用:直接实例化 IndicatorLibraryClient
36
+ examples/import_script.py # 期望调用方式(含一处笔误 client.)
37
+ ```
38
+
39
+ 关键问题:
40
+
41
+ 1. [__init__.py](file:///data/project/aibeta_sdk/src/aibeta/__init__.py#L3-L5) 使用 `from _beta_indicator_interface import IndicatorLibraryClient`,是绝对导入,作为包安装后会报 `ModuleNotFoundError`;且把 `IndicatorLibraryClient` 暴露到了公共命名空间。
42
+ 2. 客户端类承载了「网络 + Token + 缓存 + 业务接口」全部职责,但没有模块级封装,用户必须手动 `new` 客户端,与期望的模块级调用方式不符。
43
+ 3. [import_script.py](file:///data/project/aibeta_sdk/examples/import_script.py#L59) 末行 `client.get_indicator_value_batch(...)` 是笔误(未定义 `client`),应为 `beta_indicator.get_indicator_value_batch(...)`。
44
+ 4. [my_script.py](file:///data/project/aibeta_sdk/examples/my_script.py#L7) 引用 `beta_indicator_interface`(无下划线)与真实文件名不一致,且为旧式实例化方式。
45
+
46
+ ## 三、改动方案(Proposed Changes)
47
+
48
+ 最终目标结构:
49
+
50
+ ```
51
+ src/aibeta/
52
+ ├── __init__.py # 公共入口:configuration + 子模块导出(不暴露客户端类)
53
+ ├── _client.py # 内部客户端类(由 _beta_indicator_interface.py 重命名而来)
54
+ ├── _config.py # 全局共享客户端管理:configuration() / get_client()
55
+ ├── theme_classification.py # 主题分类模块级函数(薄封装,委托给共享客户端)
56
+ └── beta_indicator.py # 指标库模块级函数(薄封装,委托给共享客户端)
57
+ ```
58
+
59
+ ### 3.1 重命名:`_beta_indicator_interface.py` → `_client.py`
60
+
61
+ - 将文件重命名为 `src/aibeta/_client.py`。
62
+ - **保留** `IndicatorLibraryClient` 类的全部现有逻辑不变(Token 管理、`__call_api`、全量快照缓存、公开方法等),仅修改模块顶部 docstring 为「内部 API 客户端实现」。
63
+ - 类名保持 `IndicatorLibraryClient`(通过私有模块前缀 `_client` 及不在 `__init__` 中导出,实现「不对外暴露」)。
64
+ - 环境变量名**沿用现有**:`BETA_INDICATOR_API_APP_KEY` / `BETA_INDICATOR_API_SECRET_KEY`(用户已确认)。
65
+ - 该模块不需要任何相对导入改动(只依赖标准库 + pandas/requests/tqdm)。
66
+
67
+ ### 3.2 新增:`_config.py`(全局共享客户端 + 配置入口)
68
+
69
+ 内容(单一事实来源,集中管理共享客户端):
70
+
71
+ ```python
72
+ """SDK 全局配置与共享客户端管理。"""
73
+
74
+ from ._client import IndicatorLibraryClient
75
+
76
+ _client: IndicatorLibraryClient | None = None
77
+
78
+ def configuration(app_key: str | None = None, secret_key: str | None = None) -> None:
79
+ """临时配置 app_key / secret_key(对当前进程有效,会替换共享客户端)。"""
80
+ global _client
81
+ _client = IndicatorLibraryClient(app_key=app_key, secret_key=secret_key)
82
+
83
+ def get_client() -> IndicatorLibraryClient:
84
+ """获取全局共享客户端;未显式配置时,从环境变量读取凭证(懒加载)。"""
85
+ global _client
86
+ if _client is None:
87
+ _client = IndicatorLibraryClient()
88
+ return _client
89
+ ```
90
+
91
+ 设计要点:
92
+
93
+ - `configuration()` 每次调用都会**重建**共享客户端(支持运行期切换凭证)。
94
+ - `configuration()` 不传参时,等价于从环境变量读取凭证(`IndicatorLibraryClient` 已有此逻辑)。
95
+ - `get_client()` 懒加载,未调用 `configuration` 时自动读环境变量。
96
+ - 客户端内部的**类级全量缓存**(`__CACHE_DF`)跨实例共享,重建客户端不会导致缓存丢失或重复重建。
97
+
98
+ ### 3.3 新增:`theme_classification.py`(主题分类模块级函数)
99
+
100
+ 薄封装,每个函数委托给共享客户端,保持「业务逻辑集中在客户端、模块只做转发」:
101
+
102
+ ```python
103
+ """主题分类数据接口。"""
104
+
105
+ from ._config import get_client
106
+
107
+ def get_theme_classification_framework_inc(view_date: str):
108
+ """按 view_date 查询主题库日度增量数据。"""
109
+ return get_client().get_theme_classification_framework_inc(view_date)
110
+ # ... 同样封装其余 5 个方法:
111
+ # get_theme_classification_framework_daily
112
+ # get_theme_classification_portfolio_inc
113
+ # get_theme_classification_portfolio_daily
114
+ # get_theme_classification_index_inc
115
+ # get_theme_classification_index_by_id
116
+ ```
117
+
118
+ ### 3.4 新增:`beta_indicator.py`(指标库模块级函数)
119
+
120
+ 薄封装,同样委托给共享客户端:
121
+
122
+ ```python
123
+ """指标库数据接口。"""
124
+
125
+ from ._config import get_client
126
+
127
+ def list_indicator_types():
128
+ """读取所有指标类型。"""
129
+ return get_client().list_indicator_types()
130
+ # ... 同样封装其余 7 个方法:
131
+ # list_indicators(indicator_type)
132
+ # get_indicator_value(indicator_id)
133
+ # get_indicator_value_inc(view_date)
134
+ # list_sector_types()
135
+ # list_sectors(sector_type=None)
136
+ # list_indicators_by_sector(sector_code)
137
+ # get_indicator_value_batch(indicator_ids, max_workers=3)
138
+ ```
139
+
140
+ ### 3.5 重写:`__init__.py`(公共入口)
141
+
142
+ ```python
143
+ """板块指标库 API SDK。"""
144
+
145
+ from . import beta_indicator
146
+ from . import theme_classification
147
+ from ._config import configuration
148
+
149
+ __all__ = ["configuration", "theme_classification", "beta_indicator"]
150
+ __version__ = "0.1.0"
151
+ ```
152
+
153
+ - 不再导入 `IndicatorLibraryClient`,`__all__` 中不含该类 → 满足「不对外暴露」。
154
+ - `aibeta.configuration(...)`、`from aibeta import theme_classification`、`from aibeta import beta_indicator` 三种用法均可正常工作。
155
+
156
+ ### 3.6 更新示例脚本
157
+
158
+ - **`examples/my_script.py`**:改为新调用方式,保留现有 `_normalize_for_display` / `_print_demo_result` 辅助函数与全部演示调用,仅替换导入与实例化方式:
159
+
160
+ ```python
161
+ import aibeta
162
+ from aibeta import beta_indicator, theme_classification
163
+
164
+ # 默认从环境变量读取凭证;如需临时配置,取消注释并填入真实凭证:
165
+ # aibeta.configuration(app_key="XXX", secret_key="XXX")
166
+
167
+ framework_inc = theme_classification.get_theme_classification_framework_inc("2026-06-26")
168
+ # ... 其余调用
169
+ indicator_values_batch = beta_indicator.get_indicator_value_batch(indicator_id_list)
170
+ ```
171
+
172
+ - **`examples/import_script.py`**:修正第 59 行笔误 `client.get_indicator_value_batch(...)` → `beta_indicator.get_indicator_value_batch(...)`,其余保持不变。
173
+
174
+ ## 四、假设与决策(Assumptions & Decisions)
175
+
176
+ 1. **环境变量名**:沿用 `BETA_INDICATOR_API_APP_KEY` / `BETA_INDICATOR_API_SECRET_KEY`(用户已确认)。
177
+ 2. **示例文件**:同步更新为可运行示例,并修正 `import_script.py` 笔误(用户已确认)。
178
+ 3. **`configuration()` 签名**:仅接收 `app_key` / `secret_key`,不扩展 `base_url` / `timeout` 等参数(本次需求未涉及,保持最小改动)。
179
+ 4. **客户端类**:类名保持 `IndicatorLibraryClient`,通过私有模块 `_client.py` 与不导出实现隐藏;不重命名类。
180
+ 5. **缓存机制**:保持现有类级全量快照缓存(`__CACHE_DF`)不变,重建客户端时缓存复用。
181
+ 6. **`pyproject.toml`**:`packages = ["src/aibeta"]` 已正确指向包,无需改动。
182
+
183
+ ## 五、验证步骤(Verification)
184
+
185
+ 1. 以可编辑方式安装:`uv pip install -e .`(或 `pip install -e .`)。
186
+ 2. 校验公共命名空间:
187
+ ```bash
188
+ python -c "import aibeta; print(aibeta.__all__); print(aibeta.__version__); print(hasattr(aibeta, 'configuration')); print(hasattr(aibeta, 'IndicatorLibraryClient'))"
189
+ ```
190
+ 期望:`__all__` 含 `configuration/theme_classification/beta_indicator`;`hasattr(aibeta, 'IndicatorLibraryClient')` 为 `False`。
191
+ 3. 校验子模块可导入且函数存在:
192
+ ```bash
193
+ python -c "from aibeta import theme_classification, beta_indicator; print(callable(theme_classification.get_theme_classification_framework_inc)); print(callable(beta_indicator.get_indicator_value_batch))"
194
+ ```
195
+ 4. 校验 `configuration` 可正常配置(不发起真实网络请求,仅验证不抛错时需提供真实凭证):
196
+ ```bash
197
+ python -c "import aibeta; aibeta.configuration(app_key='XXX', secret_key='XXX')"
198
+ ```
199
+ 5. 在已配置环境变量的前提下,运行 `python examples/my_script.py`,确认所有接口按新方式正常取数。
aibeta-0.3.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 伍老师
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
aibeta-0.3.0/PKG-INFO ADDED
@@ -0,0 +1,101 @@
1
+ Metadata-Version: 2.5
2
+ Name: aibeta
3
+ Version: 0.3.0
4
+ Summary: 板块指标库 API SDK
5
+ Author: 伍老师
6
+ License-Expression: MIT
7
+ License-File: LICENSE
8
+ Keywords: aibeta,citics,indicator,research,sdk
9
+ Classifier: Operating System :: OS Independent
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Programming Language :: Python :: 3.10
12
+ Classifier: Programming Language :: Python :: 3.11
13
+ Classifier: Programming Language :: Python :: 3.12
14
+ Requires-Python: >=3.10
15
+ Requires-Dist: pandas>=2.2.0
16
+ Requires-Dist: pyarrow>=17.0.0
17
+ Requires-Dist: requests>=2.32.0
18
+ Requires-Dist: tqdm>=4.66.0
19
+ Description-Content-Type: text/markdown
20
+
21
+ # aibeta-sdk
22
+
23
+ 板块指标库 API SDK,提供主题分类与指标库数据的统一查询接口。
24
+
25
+ ## 安装
26
+
27
+ ```bash
28
+ pip install aibeta
29
+ ```
30
+
31
+ ## 配置凭证
32
+
33
+ SDK 需要 `app_key` / `secret_key` 两个凭证,二选一方式提供:
34
+
35
+ ```python
36
+ import aibeta
37
+ # 方式一:代码内配置(对当前进程有效)
38
+ aibeta.configuration(app_key="XXX", secret_key="XXX")
39
+ ```
40
+
41
+ 或通过环境变量配置(不调用 `configuration` 时自动读取):
42
+
43
+ ```bash
44
+ # 方式二:通过环境变量配置(长期有效)
45
+ export BETA_INDICATOR_API_APP_KEY="XXX"
46
+ export BETA_INDICATOR_API_SECRET_KEY="XXX"
47
+ ```
48
+
49
+ ## 快速使用
50
+
51
+ ```python
52
+ from aibeta import theme_classification, beta_indicator
53
+
54
+ # 指标库:读取所有指标类型
55
+ beta_indicator.list_indicator_types()
56
+ ```
57
+
58
+ 完整接口示例见 `examples/import_script.py`。
59
+
60
+ ## 接口说明
61
+
62
+ 数据类接口统一返回 `pandas.DataFrame`(`get_indicator_value_batch` 除外)。凭证配置见上方「配置凭证」。
63
+
64
+ ### 全局配置
65
+
66
+ | 接口 | 调用方式 | 功能简介 | 参数 |
67
+ | ----------------- | ----------------------------- | ---------------------------- | -------------------------------------------------- |
68
+ | `configuration` | `aibeta.configuration(...)` | 配置当前进程的凭证与超时参数 | `app_key` / `secret_key` / `timeout`,均可选 |
69
+
70
+ ### 主题分类 `theme_classification`
71
+
72
+ | 接口 | 调用方式 | 功能简介 | 参数 |
73
+ | -------------------------------------------- | ---------------------------------------------------------------------------- | -------------------------------- | ---------------------------- |
74
+ | `get_theme_classification_framework_inc` | `theme_classification.get_theme_classification_framework_inc(view_date)` | 主题库日度增量数据 | `view_date: str`,查询日期 |
75
+ | `get_theme_classification_framework_daily` | `theme_classification.get_theme_classification_framework_daily(view_date)` | 主题库日度截面数据 | `view_date: str`,查询日期 |
76
+ | `get_theme_classification_portfolio_inc` | `theme_classification.get_theme_classification_portfolio_inc(view_date)` | 主题成分股(标准池)日度增量数据 | `view_date: str`,查询日期 |
77
+ | `get_theme_classification_portfolio_daily` | `theme_classification.get_theme_classification_portfolio_daily(view_date)` | 主题成分股(标准池)日度截面数据 | `view_date: str`,查询日期 |
78
+ | `get_theme_classification_index_inc` | `theme_classification.get_theme_classification_index_inc(view_date)` | 主题指数点位日度增量数据 | `view_date: str`,查询日期 |
79
+ | `get_theme_classification_index_by_id` | `theme_classification.get_theme_classification_index_by_id(theme_id)` | 查询特定主题的历史指数点位 | `theme_id: str`,主题 ID |
80
+
81
+ ### 指标库 `beta_indicator`
82
+
83
+ | 接口 | 调用方式 | 功能简介 | 参数 |
84
+ | ----------------------------- | -------------------------------------------------------------------------- | ----------------------------------------------- | -------------------------------------------------------------------------------------------- |
85
+ | `list_indicator_types` | `beta_indicator.list_indicator_types()` | 读取所有指标类型(如市盈率 PE、市净率 PB 等) | 无 |
86
+ | `list_indicators` | `beta_indicator.list_indicators(indicator_type)` | 按指标类型读取指标列表 | `indicator_type: str`,指标类型名称 |
87
+ | `get_indicator_value` | `beta_indicator.get_indicator_value(indicator_id)` | 按指标 ID 读取该指标全部数值记录 | `indicator_id: str`,指标唯一标识 |
88
+ | `get_indicator_value_inc` | `beta_indicator.get_indicator_value_inc(view_date)` | 按日期增量读取所有指标值 | `view_date: str`,查询日期 |
89
+ | `list_sector_types` | `beta_indicator.list_sector_types()` | 读取所有板块类型(如 ETF 指数、中信证券行业等) | 无 |
90
+ | `list_sectors` | `beta_indicator.list_sectors(sector_type=None)` | 读取板块列表,可选按板块类型过滤 | `sector_type: str \| None`,传 `None` 返回全部 |
91
+ | `list_indicators_by_sector` | `beta_indicator.list_indicators_by_sector(sector_code)` | 按板块代码读取该板块全部指标列表 | `sector_code: str`,板块代码(如 `000001.SH`) |
92
+ | `get_indicator_value_batch` | `beta_indicator.get_indicator_value_batch(indicator_ids, max_workers=3)` | 并发批量读取多个指标的数值记录 | `indicator_ids: list[str]`,指标 ID 列表(≤30);`max_workers: int`,最大并发数,默认 3 |
93
+
94
+ > 返回类型:`get_indicator_value_batch` 返回 `dict[str, DataFrame | None]`(key 为指标 ID,读取失败对应 `None`),其余均返回 `DataFrame`。
95
+
96
+ ## 依赖
97
+
98
+ - Python >= 3.10
99
+ - pandas、pyarrow、requests、tqdm
100
+
101
+ > 缓存说明:SDK 会在用户缓存目录(`~/.cache/aibeta/`)维护指标库的全量快照缓存,默认每 3 天自动重建一次。
aibeta-0.3.0/README.md ADDED
@@ -0,0 +1,81 @@
1
+ # aibeta-sdk
2
+
3
+ 板块指标库 API SDK,提供主题分类与指标库数据的统一查询接口。
4
+
5
+ ## 安装
6
+
7
+ ```bash
8
+ pip install aibeta
9
+ ```
10
+
11
+ ## 配置凭证
12
+
13
+ SDK 需要 `app_key` / `secret_key` 两个凭证,二选一方式提供:
14
+
15
+ ```python
16
+ import aibeta
17
+ # 方式一:代码内配置(对当前进程有效)
18
+ aibeta.configuration(app_key="XXX", secret_key="XXX")
19
+ ```
20
+
21
+ 或通过环境变量配置(不调用 `configuration` 时自动读取):
22
+
23
+ ```bash
24
+ # 方式二:通过环境变量配置(长期有效)
25
+ export BETA_INDICATOR_API_APP_KEY="XXX"
26
+ export BETA_INDICATOR_API_SECRET_KEY="XXX"
27
+ ```
28
+
29
+ ## 快速使用
30
+
31
+ ```python
32
+ from aibeta import theme_classification, beta_indicator
33
+
34
+ # 指标库:读取所有指标类型
35
+ beta_indicator.list_indicator_types()
36
+ ```
37
+
38
+ 完整接口示例见 `examples/import_script.py`。
39
+
40
+ ## 接口说明
41
+
42
+ 数据类接口统一返回 `pandas.DataFrame`(`get_indicator_value_batch` 除外)。凭证配置见上方「配置凭证」。
43
+
44
+ ### 全局配置
45
+
46
+ | 接口 | 调用方式 | 功能简介 | 参数 |
47
+ | ----------------- | ----------------------------- | ---------------------------- | -------------------------------------------------- |
48
+ | `configuration` | `aibeta.configuration(...)` | 配置当前进程的凭证与超时参数 | `app_key` / `secret_key` / `timeout`,均可选 |
49
+
50
+ ### 主题分类 `theme_classification`
51
+
52
+ | 接口 | 调用方式 | 功能简介 | 参数 |
53
+ | -------------------------------------------- | ---------------------------------------------------------------------------- | -------------------------------- | ---------------------------- |
54
+ | `get_theme_classification_framework_inc` | `theme_classification.get_theme_classification_framework_inc(view_date)` | 主题库日度增量数据 | `view_date: str`,查询日期 |
55
+ | `get_theme_classification_framework_daily` | `theme_classification.get_theme_classification_framework_daily(view_date)` | 主题库日度截面数据 | `view_date: str`,查询日期 |
56
+ | `get_theme_classification_portfolio_inc` | `theme_classification.get_theme_classification_portfolio_inc(view_date)` | 主题成分股(标准池)日度增量数据 | `view_date: str`,查询日期 |
57
+ | `get_theme_classification_portfolio_daily` | `theme_classification.get_theme_classification_portfolio_daily(view_date)` | 主题成分股(标准池)日度截面数据 | `view_date: str`,查询日期 |
58
+ | `get_theme_classification_index_inc` | `theme_classification.get_theme_classification_index_inc(view_date)` | 主题指数点位日度增量数据 | `view_date: str`,查询日期 |
59
+ | `get_theme_classification_index_by_id` | `theme_classification.get_theme_classification_index_by_id(theme_id)` | 查询特定主题的历史指数点位 | `theme_id: str`,主题 ID |
60
+
61
+ ### 指标库 `beta_indicator`
62
+
63
+ | 接口 | 调用方式 | 功能简介 | 参数 |
64
+ | ----------------------------- | -------------------------------------------------------------------------- | ----------------------------------------------- | -------------------------------------------------------------------------------------------- |
65
+ | `list_indicator_types` | `beta_indicator.list_indicator_types()` | 读取所有指标类型(如市盈率 PE、市净率 PB 等) | 无 |
66
+ | `list_indicators` | `beta_indicator.list_indicators(indicator_type)` | 按指标类型读取指标列表 | `indicator_type: str`,指标类型名称 |
67
+ | `get_indicator_value` | `beta_indicator.get_indicator_value(indicator_id)` | 按指标 ID 读取该指标全部数值记录 | `indicator_id: str`,指标唯一标识 |
68
+ | `get_indicator_value_inc` | `beta_indicator.get_indicator_value_inc(view_date)` | 按日期增量读取所有指标值 | `view_date: str`,查询日期 |
69
+ | `list_sector_types` | `beta_indicator.list_sector_types()` | 读取所有板块类型(如 ETF 指数、中信证券行业等) | 无 |
70
+ | `list_sectors` | `beta_indicator.list_sectors(sector_type=None)` | 读取板块列表,可选按板块类型过滤 | `sector_type: str \| None`,传 `None` 返回全部 |
71
+ | `list_indicators_by_sector` | `beta_indicator.list_indicators_by_sector(sector_code)` | 按板块代码读取该板块全部指标列表 | `sector_code: str`,板块代码(如 `000001.SH`) |
72
+ | `get_indicator_value_batch` | `beta_indicator.get_indicator_value_batch(indicator_ids, max_workers=3)` | 并发批量读取多个指标的数值记录 | `indicator_ids: list[str]`,指标 ID 列表(≤30);`max_workers: int`,最大并发数,默认 3 |
73
+
74
+ > 返回类型:`get_indicator_value_batch` 返回 `dict[str, DataFrame | None]`(key 为指标 ID,读取失败对应 `None`),其余均返回 `DataFrame`。
75
+
76
+ ## 依赖
77
+
78
+ - Python >= 3.10
79
+ - pandas、pyarrow、requests、tqdm
80
+
81
+ > 缓存说明:SDK 会在用户缓存目录(`~/.cache/aibeta/`)维护指标库的全量快照缓存,默认每 3 天自动重建一次。
@@ -0,0 +1,59 @@
1
+ # 期待的python sdk调用方式
2
+
3
+ # aibeta模块 #######################################################################
4
+ import aibeta
5
+
6
+ # 配置app-key,app-secret (避免设置环境变量,对单次程序运行有效)
7
+ aibeta.configuration(app_key='XXX', secret_key='XXX')
8
+
9
+ # theme_classification模块 #######################################################################
10
+ from aibeta import theme_classification
11
+
12
+ # 读取主题库日度增量数据
13
+ theme_classification.get_theme_classification_framework_inc("2026-06-26")
14
+
15
+ # 读取主题库日度截面数据
16
+ theme_classification.get_theme_classification_framework_daily("2026-06-30")
17
+
18
+ # 读取主题标准池日度增量数据
19
+ theme_classification.get_theme_classification_portfolio_inc("2026-06-26")
20
+
21
+ # 读取主题标准池日度截面数据
22
+ theme_classification.get_theme_classification_portfolio_daily("2026-06-30")
23
+
24
+ # 读取主题指数点位增量数据
25
+ theme_classification.get_theme_classification_index_inc("2026-06-30")
26
+
27
+ # 读取特定主题指数点位
28
+ theme_classification.get_theme_classification_index_by_id("66f3c5b8562120df54e844485c9a1606b0d303d58427c7b28466789f7881ef14")
29
+
30
+ # beta_indicator 模块 #######################################################################
31
+ from aibeta import beta_indicator
32
+
33
+ # 读取所有指标类型
34
+ beta_indicator.list_indicator_types()
35
+
36
+ # 读取市盈率PE相关的所有板块指标
37
+ beta_indicator.list_indicators("市盈率PE")
38
+
39
+ # 读取指定板块指标值
40
+ beta_indicator.get_indicator_value("7023d2fa62ec5163b4d70dfb9f4ad3348beddf5580cf0118d97af7d7a838d76c")
41
+
42
+ # 按日期增量读取所有指标值
43
+ beta_indicator.get_indicator_value_inc("2026-06-30")
44
+
45
+ # 读取所有板块类型
46
+ beta_indicator.list_sector_types()
47
+
48
+ # 读取指定板块类型下的所有板块列表
49
+ beta_indicator.list_sectors("ETF指数")
50
+
51
+ # 读取指定板块相关的所有指标列表
52
+ beta_indicator.list_indicators_by_sector("000001.SH")
53
+
54
+ # 批量读取多个指标值
55
+ indicator_id_list = [
56
+ "f05d22906036b430fae3854635e8015b3384d04bcba38593c67c7e5d5b4aefee",
57
+ "831a95f5e39492edfd8a98397869a9c50496152faefba1e4bfbc0bab7abe227f",
58
+ ]
59
+ indicator_values_batch = beta_indicator.get_indicator_value_batch(indicator_id_list)