databull 0.1.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.
- databull-0.1.0/PKG-INFO +170 -0
- databull-0.1.0/README.md +148 -0
- databull-0.1.0/__init__.py +21 -0
- databull-0.1.0/__main__.py +15 -0
- databull-0.1.0/client.py +745 -0
- databull-0.1.0/databull.egg-info/PKG-INFO +170 -0
- databull-0.1.0/databull.egg-info/SOURCES.txt +16 -0
- databull-0.1.0/databull.egg-info/dependency_links.txt +1 -0
- databull-0.1.0/databull.egg-info/entry_points.txt +2 -0
- databull-0.1.0/databull.egg-info/requires.txt +5 -0
- databull-0.1.0/databull.egg-info/top_level.txt +1 -0
- databull-0.1.0/py.typed +0 -0
- databull-0.1.0/pyproject.toml +63 -0
- databull-0.1.0/setup.cfg +4 -0
databull-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: databull
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: DataBull 中国 A 股市场数据 API 官方 Python SDK(行情、财务、ETF、指数、板块、快讯)
|
|
5
|
+
Author-email: Yc <yccheni@163.com>
|
|
6
|
+
Project-URL: Homepage, https://www.databull.cn
|
|
7
|
+
Project-URL: Documentation, https://www.databull.cn/docs
|
|
8
|
+
Project-URL: Source, https://www.databull.cn/sdk
|
|
9
|
+
Project-URL: API Console, https://www.databull.cn/console
|
|
10
|
+
Keywords: databull,stock,a-share,china,finance,market-data,api,etf,index
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Intended Audience :: Financial and Insurance Industry
|
|
14
|
+
Classifier: Operating System :: OS Independent
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
17
|
+
Classifier: Topic :: Office/Business :: Financial :: Investment
|
|
18
|
+
Classifier: Typing :: Typed
|
|
19
|
+
Requires-Python: >=3.9
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
Provides-Extra: pandas
|
|
22
|
+
|
|
23
|
+
# databull — DataBull Python SDK
|
|
24
|
+
|
|
25
|
+
DataBull 中国 A 股市场数据 API 的官方 Python 客户端。覆盖**沪深个股日线与实时行情、财务报表、
|
|
26
|
+
ETF(含申赎清单与成分股)、指数清单/搜索/成分股权重、申万板块、市场情绪、财经快讯**,
|
|
27
|
+
共 28 个 REST 端点与 5 个 MCP 工具。
|
|
28
|
+
|
|
29
|
+
- 官网与文档:https://www.databull.cn/docs
|
|
30
|
+
- 免费注册并创建 API Key:https://www.databull.cn/console/register
|
|
31
|
+
|
|
32
|
+
## 安装
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
pip install databull # 仅 JSON 查询,依赖只有 requests
|
|
36
|
+
pip install "databull[pandas]" # 需要 *_history / fear_greed 返回 DataFrame 时
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
国内直连 PyPI 慢时,可从官网下载 wheel 安装:
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
pip install https://www.databull.cn/sdk/files/databull-0.1.0-py3-none-any.whl
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## 快速开始
|
|
46
|
+
|
|
47
|
+
```python
|
|
48
|
+
from databull import DataBull, DataBullError
|
|
49
|
+
|
|
50
|
+
client = DataBull("dbt_xxxxxxxx") # 也可只设环境变量 DATABULL_API_KEY
|
|
51
|
+
# 自建/代理时可指定基址:DataBull(api_key, base_url="https://api.example.com")
|
|
52
|
+
|
|
53
|
+
# 个股日线(返回带日期索引的 DataFrame)
|
|
54
|
+
df = client.get_stock_history("600519", "2026-01-01", "2026-09-01")
|
|
55
|
+
print(df.tail())
|
|
56
|
+
|
|
57
|
+
# 指数搜索与成分股权重
|
|
58
|
+
hits = client.search_index("沪深300", limit=5)
|
|
59
|
+
cons = client.get_index_constituents("000300", page_size=10)["data"]
|
|
60
|
+
|
|
61
|
+
# 申万一级行业涨跌
|
|
62
|
+
sectors = client.get_sector_data("sw1")
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
命令行也可以直接探接口(不用写代码):
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
export DATABULL_API_KEY=dbt_xxxxxxxx
|
|
69
|
+
python -m databull cn/index/search --params '{"keyword": "沪深300"}'
|
|
70
|
+
databull cn/stocks --params '{"q": "茅台"}' # 安装了就绪脚本
|
|
71
|
+
python -m databull --version
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## 出错与空结果
|
|
75
|
+
|
|
76
|
+
**出错不静默**:所有失败都抛 `DataBullError`,带上 HTTP 状态码与原始响应体。
|
|
77
|
+
不要用「返回 None」判断失败——本项目历史上就吃过这个亏。
|
|
78
|
+
|
|
79
|
+
```python
|
|
80
|
+
try:
|
|
81
|
+
client.get_stock_history("600519", "2026-01-01", "2026-09-01")
|
|
82
|
+
except DataBullError as e:
|
|
83
|
+
print(e.status, e) # 401=Key 无效 403=超出套餐额度 429=调用频率超限
|
|
84
|
+
print(e.body)
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
**空结果带原因**:接口在「没有数据」时返回空数组/空对象而不是报错,原因通过响应头
|
|
88
|
+
`X-Empty-Reason`(数组型)或体内 `empty_reason`(对象型)给出,SDK 把它挂到
|
|
89
|
+
`client.last_empty_reason`:
|
|
90
|
+
|
|
91
|
+
```python
|
|
92
|
+
data = client.get_index_constituents("801010")
|
|
93
|
+
if not data["data"]["items"]:
|
|
94
|
+
print(client.last_empty_reason) # constituents_not_synced = 该指数不在每日同步名单
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
常见取值:`index_not_found`、`no_data_in_range`、`calendar_not_loaded`、`no_match`、
|
|
98
|
+
`sector_data_not_collected`、`tick_not_uploaded`、`catalog_not_synced`、
|
|
99
|
+
`constituents_not_synced`。
|
|
100
|
+
|
|
101
|
+
## 参数与返回约定(容易踩的两点)
|
|
102
|
+
|
|
103
|
+
1. **代码一律用裸码**,不带交易所后缀:`600519` 而不是 `600519.SH`;市场由接口决定。
|
|
104
|
+
传后缀时个股会 400,指数**不报错但静默返回空数组**——SDK 已自动剥离后缀,
|
|
105
|
+
但你自己拼 URL 时要注意。
|
|
106
|
+
2. **日期写法都收**:`2026-08-01`、`20260801`、`2026/8/1` 都可以。服务端并不统一——
|
|
107
|
+
实测只有 `/cn/index/history` 严格要求 `YYYYMMDD`(传 `2026-08-01` 直接 400),
|
|
108
|
+
其余端点两种都收;SDK 在发请求前统一转换,所以你不必记这件事。
|
|
109
|
+
3. **`market` 有两种含义**:作为基址路径前缀时是 `cn` / `us` / `hk`;作为**指数清单的
|
|
110
|
+
过滤条件**时是 `SSE` / `SZSE` / `CSI` / `SW`。两者混用不会报错、只会筛不到。
|
|
111
|
+
SDK 把后者命名为 `index_market` 并会提前拦下错误取值。
|
|
112
|
+
|
|
113
|
+
**返回形态不统一**:多数方法返回 `{"code": 0, "data": ...}`,但少数接口直接返回数组
|
|
114
|
+
(例如 `get_sector_data` 返回 `[{...}, ...]`)。SDK 原样透传,不做包装——
|
|
115
|
+
按方法逐个确认一次,比被一层"透明"包装误导更好。
|
|
116
|
+
|
|
117
|
+
## 端点与方法对照
|
|
118
|
+
|
|
119
|
+
| 能力 | 方法 | 路径 |
|
|
120
|
+
| --- | --- | --- |
|
|
121
|
+
| 指数历史日线 | `get_index_history` | `GET /cn/index/history` |
|
|
122
|
+
| 指数清单(分页/过滤) | `get_index_list` | `GET /cn/index/list` |
|
|
123
|
+
| 指数搜索(相关度排序) | `search_index` | `GET /cn/index/search` |
|
|
124
|
+
| 指数成分股与权重 | `get_index_constituents` | `GET /cn/index/constituents` |
|
|
125
|
+
| A股/ETF/指数标的清单 | `get_stock_list` | `GET /cn/stocks` |
|
|
126
|
+
| 个股基本信息 | `get_stock_info` | `GET /cn/stock/info` |
|
|
127
|
+
| 公司简介 | `get_company_profile` | `GET /cn/stock/profile` |
|
|
128
|
+
| 个股历史行情 | `get_stock_history` | `GET /cn/stock/history` |
|
|
129
|
+
| 个股财务报表 | `get_stock_financial_data` | `GET /cn/stock/financial_data` |
|
|
130
|
+
| 美股基本信息 / 历史 | `get_us_stock_info` / `get_us_stock_history` | `GET /us/stock/info`, `/us/stock/history` |
|
|
131
|
+
| 港股基本信息 / 历史 | `get_hk_stock_info` / `get_hk_stock_history` | `GET /hk/stock/info`, `/hk/stock/history` |
|
|
132
|
+
| ETF 清单 | `get_etf_list` | `GET /cn/etfs/` |
|
|
133
|
+
| ETF 基本信息 | `get_etf_info` | `GET /cn/etfs/info` |
|
|
134
|
+
| ETF 申赎清单(PCF) | `get_etf_pcf` | `GET /cn/etfs/etf_pcf` |
|
|
135
|
+
| ETF 成分股 | `get_etf_composition` | `GET /cn/etfs/etf_composition` |
|
|
136
|
+
| ETF 历史净值/行情 | `get_etf_history` | `GET /cn/etf/history` |
|
|
137
|
+
| 财经快讯 | `get_news_flash` | `GET /v2/news/flash` |
|
|
138
|
+
| 快讯来源列表 | `get_news_flash_sources` | `GET /v2/news/flash/sources` |
|
|
139
|
+
| 市场新闻列表 / 详情 | `get_market_news` / `get_market_news_detail` | `GET /cn/market/news`, `/cn/market/news/{id}` |
|
|
140
|
+
| 恐惧与贪婪指数 | `get_fear_greed` | `GET /cn/market/fear_greed` |
|
|
141
|
+
| 申万板块涨跌幅 | `get_sector_data` | `GET /cn/market/sector_data/{sw1,sw2,sw3}` |
|
|
142
|
+
| 申万行业清单 | `get_sector_catalog` | `GET /cn/market/sector_catalog/{sw1,sw2,sw3}` |
|
|
143
|
+
| 个股实时 Tick | `get_realtime` | `GET /cn/stock/tick` |
|
|
144
|
+
| 全量 Tick 快照 | `get_tick_all` | `GET /cn/tick/tickall` |
|
|
145
|
+
| 交易日历 | `get_trading_calendar` | `GET /cn/tick/trading_calendar` |
|
|
146
|
+
| MCP 工具调用 | `call_mcp_tool` | `POST /mcp/call` |
|
|
147
|
+
|
|
148
|
+
MCP 已暴露的工具:`get_stock_list`、`get_stock_detail`、`get_stock_history`、
|
|
149
|
+
`get_index_history`、`get_financial_data`。
|
|
150
|
+
|
|
151
|
+
### 旧方法名(已废弃,仍可用)
|
|
152
|
+
|
|
153
|
+
从仓库内旧客户端迁移过来的方法名保留为别名,方便存量代码不改:
|
|
154
|
+
`get_history` → `get_stock_history`、`get_market_sector` → `get_sector_data`、
|
|
155
|
+
`get_company` → `get_company_profile`、`get_last_tick` → `get_realtime`、
|
|
156
|
+
`get_market_fear_greed` → `get_fear_greed`。
|
|
157
|
+
注意**出错语义已变**:旧版是「打印后返回 None」,现在是抛 `DataBullError`。
|
|
158
|
+
|
|
159
|
+
## 版本
|
|
160
|
+
|
|
161
|
+
版本号唯一源是 `databull/client.py` 的 `__version__`:
|
|
162
|
+
|
|
163
|
+
```python
|
|
164
|
+
import databull
|
|
165
|
+
print(databull.__version__)
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
## 版权
|
|
169
|
+
|
|
170
|
+
Copyright (c) 2025 yccheni@163.com. All rights reserved.
|
databull-0.1.0/README.md
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
# databull — DataBull Python SDK
|
|
2
|
+
|
|
3
|
+
DataBull 中国 A 股市场数据 API 的官方 Python 客户端。覆盖**沪深个股日线与实时行情、财务报表、
|
|
4
|
+
ETF(含申赎清单与成分股)、指数清单/搜索/成分股权重、申万板块、市场情绪、财经快讯**,
|
|
5
|
+
共 28 个 REST 端点与 5 个 MCP 工具。
|
|
6
|
+
|
|
7
|
+
- 官网与文档:https://www.databull.cn/docs
|
|
8
|
+
- 免费注册并创建 API Key:https://www.databull.cn/console/register
|
|
9
|
+
|
|
10
|
+
## 安装
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
pip install databull # 仅 JSON 查询,依赖只有 requests
|
|
14
|
+
pip install "databull[pandas]" # 需要 *_history / fear_greed 返回 DataFrame 时
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
国内直连 PyPI 慢时,可从官网下载 wheel 安装:
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
pip install https://www.databull.cn/sdk/files/databull-0.1.0-py3-none-any.whl
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## 快速开始
|
|
24
|
+
|
|
25
|
+
```python
|
|
26
|
+
from databull import DataBull, DataBullError
|
|
27
|
+
|
|
28
|
+
client = DataBull("dbt_xxxxxxxx") # 也可只设环境变量 DATABULL_API_KEY
|
|
29
|
+
# 自建/代理时可指定基址:DataBull(api_key, base_url="https://api.example.com")
|
|
30
|
+
|
|
31
|
+
# 个股日线(返回带日期索引的 DataFrame)
|
|
32
|
+
df = client.get_stock_history("600519", "2026-01-01", "2026-09-01")
|
|
33
|
+
print(df.tail())
|
|
34
|
+
|
|
35
|
+
# 指数搜索与成分股权重
|
|
36
|
+
hits = client.search_index("沪深300", limit=5)
|
|
37
|
+
cons = client.get_index_constituents("000300", page_size=10)["data"]
|
|
38
|
+
|
|
39
|
+
# 申万一级行业涨跌
|
|
40
|
+
sectors = client.get_sector_data("sw1")
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
命令行也可以直接探接口(不用写代码):
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
export DATABULL_API_KEY=dbt_xxxxxxxx
|
|
47
|
+
python -m databull cn/index/search --params '{"keyword": "沪深300"}'
|
|
48
|
+
databull cn/stocks --params '{"q": "茅台"}' # 安装了就绪脚本
|
|
49
|
+
python -m databull --version
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## 出错与空结果
|
|
53
|
+
|
|
54
|
+
**出错不静默**:所有失败都抛 `DataBullError`,带上 HTTP 状态码与原始响应体。
|
|
55
|
+
不要用「返回 None」判断失败——本项目历史上就吃过这个亏。
|
|
56
|
+
|
|
57
|
+
```python
|
|
58
|
+
try:
|
|
59
|
+
client.get_stock_history("600519", "2026-01-01", "2026-09-01")
|
|
60
|
+
except DataBullError as e:
|
|
61
|
+
print(e.status, e) # 401=Key 无效 403=超出套餐额度 429=调用频率超限
|
|
62
|
+
print(e.body)
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
**空结果带原因**:接口在「没有数据」时返回空数组/空对象而不是报错,原因通过响应头
|
|
66
|
+
`X-Empty-Reason`(数组型)或体内 `empty_reason`(对象型)给出,SDK 把它挂到
|
|
67
|
+
`client.last_empty_reason`:
|
|
68
|
+
|
|
69
|
+
```python
|
|
70
|
+
data = client.get_index_constituents("801010")
|
|
71
|
+
if not data["data"]["items"]:
|
|
72
|
+
print(client.last_empty_reason) # constituents_not_synced = 该指数不在每日同步名单
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
常见取值:`index_not_found`、`no_data_in_range`、`calendar_not_loaded`、`no_match`、
|
|
76
|
+
`sector_data_not_collected`、`tick_not_uploaded`、`catalog_not_synced`、
|
|
77
|
+
`constituents_not_synced`。
|
|
78
|
+
|
|
79
|
+
## 参数与返回约定(容易踩的两点)
|
|
80
|
+
|
|
81
|
+
1. **代码一律用裸码**,不带交易所后缀:`600519` 而不是 `600519.SH`;市场由接口决定。
|
|
82
|
+
传后缀时个股会 400,指数**不报错但静默返回空数组**——SDK 已自动剥离后缀,
|
|
83
|
+
但你自己拼 URL 时要注意。
|
|
84
|
+
2. **日期写法都收**:`2026-08-01`、`20260801`、`2026/8/1` 都可以。服务端并不统一——
|
|
85
|
+
实测只有 `/cn/index/history` 严格要求 `YYYYMMDD`(传 `2026-08-01` 直接 400),
|
|
86
|
+
其余端点两种都收;SDK 在发请求前统一转换,所以你不必记这件事。
|
|
87
|
+
3. **`market` 有两种含义**:作为基址路径前缀时是 `cn` / `us` / `hk`;作为**指数清单的
|
|
88
|
+
过滤条件**时是 `SSE` / `SZSE` / `CSI` / `SW`。两者混用不会报错、只会筛不到。
|
|
89
|
+
SDK 把后者命名为 `index_market` 并会提前拦下错误取值。
|
|
90
|
+
|
|
91
|
+
**返回形态不统一**:多数方法返回 `{"code": 0, "data": ...}`,但少数接口直接返回数组
|
|
92
|
+
(例如 `get_sector_data` 返回 `[{...}, ...]`)。SDK 原样透传,不做包装——
|
|
93
|
+
按方法逐个确认一次,比被一层"透明"包装误导更好。
|
|
94
|
+
|
|
95
|
+
## 端点与方法对照
|
|
96
|
+
|
|
97
|
+
| 能力 | 方法 | 路径 |
|
|
98
|
+
| --- | --- | --- |
|
|
99
|
+
| 指数历史日线 | `get_index_history` | `GET /cn/index/history` |
|
|
100
|
+
| 指数清单(分页/过滤) | `get_index_list` | `GET /cn/index/list` |
|
|
101
|
+
| 指数搜索(相关度排序) | `search_index` | `GET /cn/index/search` |
|
|
102
|
+
| 指数成分股与权重 | `get_index_constituents` | `GET /cn/index/constituents` |
|
|
103
|
+
| A股/ETF/指数标的清单 | `get_stock_list` | `GET /cn/stocks` |
|
|
104
|
+
| 个股基本信息 | `get_stock_info` | `GET /cn/stock/info` |
|
|
105
|
+
| 公司简介 | `get_company_profile` | `GET /cn/stock/profile` |
|
|
106
|
+
| 个股历史行情 | `get_stock_history` | `GET /cn/stock/history` |
|
|
107
|
+
| 个股财务报表 | `get_stock_financial_data` | `GET /cn/stock/financial_data` |
|
|
108
|
+
| 美股基本信息 / 历史 | `get_us_stock_info` / `get_us_stock_history` | `GET /us/stock/info`, `/us/stock/history` |
|
|
109
|
+
| 港股基本信息 / 历史 | `get_hk_stock_info` / `get_hk_stock_history` | `GET /hk/stock/info`, `/hk/stock/history` |
|
|
110
|
+
| ETF 清单 | `get_etf_list` | `GET /cn/etfs/` |
|
|
111
|
+
| ETF 基本信息 | `get_etf_info` | `GET /cn/etfs/info` |
|
|
112
|
+
| ETF 申赎清单(PCF) | `get_etf_pcf` | `GET /cn/etfs/etf_pcf` |
|
|
113
|
+
| ETF 成分股 | `get_etf_composition` | `GET /cn/etfs/etf_composition` |
|
|
114
|
+
| ETF 历史净值/行情 | `get_etf_history` | `GET /cn/etf/history` |
|
|
115
|
+
| 财经快讯 | `get_news_flash` | `GET /v2/news/flash` |
|
|
116
|
+
| 快讯来源列表 | `get_news_flash_sources` | `GET /v2/news/flash/sources` |
|
|
117
|
+
| 市场新闻列表 / 详情 | `get_market_news` / `get_market_news_detail` | `GET /cn/market/news`, `/cn/market/news/{id}` |
|
|
118
|
+
| 恐惧与贪婪指数 | `get_fear_greed` | `GET /cn/market/fear_greed` |
|
|
119
|
+
| 申万板块涨跌幅 | `get_sector_data` | `GET /cn/market/sector_data/{sw1,sw2,sw3}` |
|
|
120
|
+
| 申万行业清单 | `get_sector_catalog` | `GET /cn/market/sector_catalog/{sw1,sw2,sw3}` |
|
|
121
|
+
| 个股实时 Tick | `get_realtime` | `GET /cn/stock/tick` |
|
|
122
|
+
| 全量 Tick 快照 | `get_tick_all` | `GET /cn/tick/tickall` |
|
|
123
|
+
| 交易日历 | `get_trading_calendar` | `GET /cn/tick/trading_calendar` |
|
|
124
|
+
| MCP 工具调用 | `call_mcp_tool` | `POST /mcp/call` |
|
|
125
|
+
|
|
126
|
+
MCP 已暴露的工具:`get_stock_list`、`get_stock_detail`、`get_stock_history`、
|
|
127
|
+
`get_index_history`、`get_financial_data`。
|
|
128
|
+
|
|
129
|
+
### 旧方法名(已废弃,仍可用)
|
|
130
|
+
|
|
131
|
+
从仓库内旧客户端迁移过来的方法名保留为别名,方便存量代码不改:
|
|
132
|
+
`get_history` → `get_stock_history`、`get_market_sector` → `get_sector_data`、
|
|
133
|
+
`get_company` → `get_company_profile`、`get_last_tick` → `get_realtime`、
|
|
134
|
+
`get_market_fear_greed` → `get_fear_greed`。
|
|
135
|
+
注意**出错语义已变**:旧版是「打印后返回 None」,现在是抛 `DataBullError`。
|
|
136
|
+
|
|
137
|
+
## 版本
|
|
138
|
+
|
|
139
|
+
版本号唯一源是 `databull/client.py` 的 `__version__`:
|
|
140
|
+
|
|
141
|
+
```python
|
|
142
|
+
import databull
|
|
143
|
+
print(databull.__version__)
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
## 版权
|
|
147
|
+
|
|
148
|
+
Copyright (c) 2025 yccheni@163.com. All rights reserved.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"""databull —— DataBull 中国 A 股市场数据 API 的 Python SDK。
|
|
2
|
+
|
|
3
|
+
快速开始::
|
|
4
|
+
|
|
5
|
+
pip install databull
|
|
6
|
+
|
|
7
|
+
from databull import DataBull
|
|
8
|
+
|
|
9
|
+
client = DataBull("dbt_xxx") # 也可用环境变量 DATABULL_API_KEY
|
|
10
|
+
df = client.get_stock_history("600519", "2026-01-01", "2026-09-01")
|
|
11
|
+
print(df.head())
|
|
12
|
+
|
|
13
|
+
出错统一抛 :class:`DataBullError`(不静默返回 None);空结果的原因挂在
|
|
14
|
+
``client.last_empty_reason``。全部可用端点见 README 的端点表。
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
from __future__ import annotations
|
|
18
|
+
|
|
19
|
+
from .client import DataBull, DataBullError, __version__
|
|
20
|
+
|
|
21
|
+
__all__ = ["DataBull", "DataBullError", "__version__"]
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"""``python -m databull <endpoint> [--params JSON]`` —— 不写代码时快速探一个接口。
|
|
2
|
+
|
|
3
|
+
示例::
|
|
4
|
+
|
|
5
|
+
python -m databull cn/stocks --params '{"q": "茅台"}'
|
|
6
|
+
python -m databull cn/index/search --params '{"keyword": "沪深300"}'
|
|
7
|
+
python -m databull --version
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
12
|
+
from .client import _cli
|
|
13
|
+
|
|
14
|
+
if __name__ == "__main__":
|
|
15
|
+
raise SystemExit(_cli())
|