ftshare 1.0.9__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.
Files changed (58) hide show
  1. ftshare-1.0.9/.github/workflows/ci.yml +25 -0
  2. ftshare-1.0.9/.github/workflows/publish.yml +43 -0
  3. ftshare-1.0.9/.gitignore +46 -0
  4. ftshare-1.0.9/CHANGELOG.md +34 -0
  5. ftshare-1.0.9/CONTRIBUTING.md +40 -0
  6. ftshare-1.0.9/LICENSE +21 -0
  7. ftshare-1.0.9/PKG-INFO +256 -0
  8. ftshare-1.0.9/README.md +224 -0
  9. ftshare-1.0.9/README_EN.md +397 -0
  10. ftshare-1.0.9/SECURITY.md +16 -0
  11. ftshare-1.0.9/docs/API_REFERENCE.md +6680 -0
  12. ftshare-1.0.9/docs/assets/readme/ftshare-website.png +0 -0
  13. ftshare-1.0.9/docs/assets/readme/hero.svg +78 -0
  14. ftshare-1.0.9/docs/assets/wechat-group-20260929.png +0 -0
  15. ftshare-1.0.9/pyproject.toml +52 -0
  16. ftshare-1.0.9/src/ftshare/__init__.py +98 -0
  17. ftshare-1.0.9/src/ftshare/apis/__init__.py +29 -0
  18. ftshare-1.0.9/src/ftshare/apis/bond.py +443 -0
  19. ftshare-1.0.9/src/ftshare/apis/economic.py +1054 -0
  20. ftshare-1.0.9/src/ftshare/apis/etf.py +623 -0
  21. ftshare-1.0.9/src/ftshare/apis/forex.py +12 -0
  22. ftshare-1.0.9/src/ftshare/apis/fund.py +985 -0
  23. ftshare-1.0.9/src/ftshare/apis/futures.py +765 -0
  24. ftshare-1.0.9/src/ftshare/apis/hk.py +44 -0
  25. ftshare-1.0.9/src/ftshare/apis/index.py +499 -0
  26. ftshare-1.0.9/src/ftshare/apis/llm_corpus.py +308 -0
  27. ftshare-1.0.9/src/ftshare/apis/spot.py +69 -0
  28. ftshare-1.0.9/src/ftshare/apis/stock.py +4673 -0
  29. ftshare-1.0.9/src/ftshare/apis/us.py +117 -0
  30. ftshare-1.0.9/src/ftshare/base.py +478 -0
  31. ftshare-1.0.9/src/ftshare/client.py +74 -0
  32. ftshare-1.0.9/src/ftshare/config.py +56 -0
  33. ftshare-1.0.9/src/ftshare/dataframe.py +18 -0
  34. ftshare-1.0.9/src/ftshare/endpoints/__init__.py +35 -0
  35. ftshare-1.0.9/src/ftshare/endpoints/bond.py +89 -0
  36. ftshare-1.0.9/src/ftshare/endpoints/economic.py +178 -0
  37. ftshare-1.0.9/src/ftshare/endpoints/etf.py +143 -0
  38. ftshare-1.0.9/src/ftshare/endpoints/forex.py +9 -0
  39. ftshare-1.0.9/src/ftshare/endpoints/fund.py +136 -0
  40. ftshare-1.0.9/src/ftshare/endpoints/futures.py +143 -0
  41. ftshare-1.0.9/src/ftshare/endpoints/hk.py +32 -0
  42. ftshare-1.0.9/src/ftshare/endpoints/index.py +123 -0
  43. ftshare-1.0.9/src/ftshare/endpoints/llm_corpus.py +45 -0
  44. ftshare-1.0.9/src/ftshare/endpoints/spot.py +16 -0
  45. ftshare-1.0.9/src/ftshare/endpoints/stock.py +949 -0
  46. ftshare-1.0.9/src/ftshare/endpoints/types.py +40 -0
  47. ftshare-1.0.9/src/ftshare/endpoints/us.py +23 -0
  48. ftshare-1.0.9/src/ftshare/exceptions.py +59 -0
  49. ftshare-1.0.9/src/ftshare/fields.py +35 -0
  50. ftshare-1.0.9/src/ftshare/pagination.py +33 -0
  51. ftshare-1.0.9/src/ftshare/params.py +13 -0
  52. ftshare-1.0.9/src/ftshare/py.typed +1 -0
  53. ftshare-1.0.9/src/ftshare/response.py +69 -0
  54. ftshare-1.0.9/tests/conftest.py +62 -0
  55. ftshare-1.0.9/tests/endpoint_cases.py +357 -0
  56. ftshare-1.0.9/tests/test_client.py +1598 -0
  57. ftshare-1.0.9/tests/test_endpoint_contracts.py +138 -0
  58. ftshare-1.0.9/tests/test_integration_market.py +115 -0
@@ -0,0 +1,25 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+ branches: [main]
8
+
9
+ jobs:
10
+ test:
11
+ runs-on: ubuntu-latest
12
+ strategy:
13
+ fail-fast: false
14
+ matrix:
15
+ python-version: ["3.9", "3.10", "3.11", "3.12"]
16
+ steps:
17
+ - uses: actions/checkout@v4
18
+ - name: Set up Python ${{ matrix.python-version }}
19
+ uses: actions/setup-python@v5
20
+ with:
21
+ python-version: ${{ matrix.python-version }}
22
+ - name: Install package and test dependencies
23
+ run: pip install -e ".[test]"
24
+ - name: Run tests
25
+ run: python -m pytest -q
@@ -0,0 +1,43 @@
1
+ name: Publish to PyPI
2
+
3
+ on:
4
+ release:
5
+ types: [published]
6
+
7
+ jobs:
8
+ build:
9
+ name: Build distribution
10
+ runs-on: ubuntu-latest
11
+ steps:
12
+ - uses: actions/checkout@v4
13
+ - name: Set up Python
14
+ uses: actions/setup-python@v5
15
+ with:
16
+ python-version: "3.12"
17
+ - name: Install build tooling
18
+ run: python -m pip install --upgrade build
19
+ - name: Build sdist and wheel
20
+ run: python -m build
21
+ - name: Upload distribution artifacts
22
+ uses: actions/upload-artifact@v4
23
+ with:
24
+ name: dist
25
+ path: dist/
26
+
27
+ publish:
28
+ name: Publish to PyPI
29
+ needs: build
30
+ runs-on: ubuntu-latest
31
+ environment:
32
+ name: pypi
33
+ url: https://pypi.org/p/ftshare
34
+ permissions:
35
+ id-token: write
36
+ steps:
37
+ - name: Download distribution artifacts
38
+ uses: actions/download-artifact@v4
39
+ with:
40
+ name: dist
41
+ path: dist/
42
+ - name: Publish to PyPI
43
+ uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,46 @@
1
+ # Python
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+ *.egg-info/
6
+ *.egg
7
+ build/
8
+ dist/
9
+ .eggs/
10
+
11
+ # Virtual environments
12
+ .venv/
13
+ venv/
14
+ env/
15
+
16
+ # Test / coverage
17
+ .pytest_cache/
18
+ .coverage
19
+ .coverage.*
20
+ htmlcov/
21
+ .tox/
22
+
23
+ # Type / lint caches
24
+ .mypy_cache/
25
+ .ruff_cache/
26
+ .pyre/
27
+
28
+ # IDE
29
+ .idea/
30
+ .vscode/
31
+ *.swp
32
+ .DS_Store
33
+
34
+ # Logs / runtime
35
+ *.log
36
+
37
+ # Local API documentation checkout used to regenerate SDK metadata
38
+ ftshare-doc/
39
+
40
+ # Local SDK verification workspace; not shipped with package releases
41
+ sdk_smoke_test/
42
+
43
+ # Secrets / env
44
+ .env
45
+ .env.local
46
+ *.pem
@@ -0,0 +1,34 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [Unreleased]
9
+
10
+ ### Fixed
11
+ - 24 paginated endpoints exposed only `page`/`page_size`; they now also accept `limit`, `all_pages`, and `max_pages`.
12
+ - `bse_mapping` endpoint metadata now records its `page`/`page_size` parameters and documented 500-row page cap.
13
+ - Documented per-endpoint `page_size` caps (up to 4000) are now validated client-side.
14
+ - `tdx_board_daily`/`tdx_board_index`/`tdx_board_members` exposed the dead parameters `idx_name`/`idx_type`/`idx_type_code`; they are now `board_name`/`board_type`/`board_type_code`, which the service actually honors. The three endpoints also document their full parameter set and enforce the documented 1000-row page cap.
15
+ - `limit_event_timeline_3s` exposed only `symbol`/`trade_date`; it now records its documented `page`/`page_size` parameters and accepts `limit`, `all_pages`, and `max_pages`, with the documented 200-row page cap.
16
+ - `etf_pcf_infos` referenced the non-existent doc `ETF-PCF信息.md`; corrected to `ETF申赎清单.md`.
17
+ - `ashare_rating_factor_snapshot` referenced the non-existent doc `A股相关性Top-K.md`; corrected to `A股相关性 Top-K.md`.
18
+ - `goodwill_industry` declared `page`/`page_size` although the service ignores both and returns every industry in one response, which made `all_pages=True` re-fetch the same rows forever. The endpoint now exposes only its documented `date` parameter.
19
+
20
+ ## [0.1.1] - 2026-06-29
21
+
22
+ ### Changed
23
+ - Default `base_url` changed from `https://market.ft.tech/data/` to `https://market.ft.tech/gateway/`.
24
+ - Endpoint and API mixin registries are now split by `ftshare-doc/api-doc` topic.
25
+ - SDK coverage updated to 179 market-data endpoints.
26
+
27
+ ## [0.1.0] - 2026-06-23
28
+
29
+ ### Added
30
+ - First public release of the `ftshare` Python SDK.
31
+ - Synchronous client (`ftshare.market_api`) returning pandas `DataFrame` by default.
32
+ - 176 market-data endpoints generated from the API documentation.
33
+ - Field selection (`fields`), pagination (`page`/`page_size`/`limit`/`all_pages`), and `raw`/`as_dataframe` return controls.
34
+ - MIT license and open-source project scaffolding (`.gitignore`, `CHANGELOG.md`, `CONTRIBUTING.md`, `SECURITY.md`, CI workflow).
@@ -0,0 +1,40 @@
1
+ # Contributing to ftshare
2
+
3
+ Thanks for your interest in contributing! This is a short guide to get you started.
4
+
5
+ ## Development setup
6
+
7
+ Clone the repository and install the package with its test dependencies in editable mode:
8
+
9
+ ```bash
10
+ git clone git@github.com:ftshare-lab/ftshare-python-sdk.git
11
+ cd ftshare-python-sdk
12
+ pip install -e ".[test]"
13
+ ```
14
+
15
+ > Replace the repository URL above with your fork once you have one.
16
+
17
+ ## Running tests
18
+
19
+ The unit test suite uses mocked HTTP and does not require network access:
20
+
21
+ ```bash
22
+ python3 -m pytest
23
+ ```
24
+
25
+ Real-API integration tests are skipped by default. To run them against a reachable FTShare service:
26
+
27
+ ```bash
28
+ FTSHARE_RUN_INTEGRATION=1 python3 -m pytest tests/test_integration_market.py
29
+ ```
30
+
31
+ ## Making changes
32
+
33
+ 1. Open an issue to discuss significant changes before starting work.
34
+ 2. Keep the public API surface stable unless an issue calls for a breaking change.
35
+ 3. Make sure `python3 -m pytest` passes.
36
+ 4. Submit a pull request with a clear description of the change and motivation.
37
+
38
+ ## Reporting issues
39
+
40
+ Use the issue tracker for bug reports and feature requests. For security-sensitive reports, see [SECURITY.md](SECURITY.md).
ftshare-1.0.9/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 FTShare contributors
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.
ftshare-1.0.9/PKG-INFO ADDED
@@ -0,0 +1,256 @@
1
+ Metadata-Version: 2.5
2
+ Name: ftshare
3
+ Version: 1.0.9
4
+ Summary: Python SDK for FTShare market data APIs.
5
+ Project-URL: Homepage, https://ftai.chat/ftshare
6
+ Project-URL: Documentation, https://market.ft.tech/
7
+ Project-URL: Source, https://github.com/ftshare-lab/ftshare-python-sdk
8
+ Project-URL: Issues, https://github.com/ftshare-lab/ftshare-python-sdk/issues
9
+ Project-URL: Changelog, https://github.com/ftshare-lab/ftshare-python-sdk/blob/main/CHANGELOG.md
10
+ Author-email: FTShare <liulei@ft.tech>
11
+ License-Expression: MIT
12
+ License-File: LICENSE
13
+ Keywords: finance,ftshare,market-data,sdk
14
+ Classifier: Development Status :: 3 - Alpha
15
+ Classifier: Intended Audience :: Developers
16
+ Classifier: Intended Audience :: Financial and Insurance Industry
17
+ Classifier: License :: OSI Approved :: MIT License
18
+ Classifier: Programming Language :: Python :: 3
19
+ Classifier: Programming Language :: Python :: 3.9
20
+ Classifier: Programming Language :: Python :: 3.10
21
+ Classifier: Programming Language :: Python :: 3.11
22
+ Classifier: Programming Language :: Python :: 3.12
23
+ Classifier: Typing :: Typed
24
+ Requires-Python: >=3.9
25
+ Requires-Dist: pandas>=1.5
26
+ Requires-Dist: requests>=2.31.0
27
+ Provides-Extra: dev
28
+ Requires-Dist: pytest>=7.0; extra == 'dev'
29
+ Provides-Extra: test
30
+ Requires-Dist: pytest>=7.0; extra == 'test'
31
+ Description-Content-Type: text/markdown
32
+
33
+ <p align="center">
34
+ <img src="./docs/assets/readme/hero.svg" width="100%" alt="FTShare Python SDK,用 Python 和 pandas 接入金融数据">
35
+ </p>
36
+
37
+ <p align="center">
38
+ <a href="https://github.com/FTShare-Lab/FTShare-python-sdk/releases/tag/v1.0.1"><img src="https://img.shields.io/badge/release-v1.0.1-3563E9" alt="FTShare Python SDK v1.0.1"></a>
39
+ <a href="https://www.python.org/downloads/"><img src="https://img.shields.io/badge/python-3.9%2B-111827" alt="Python 3.9 or later"></a>
40
+ <a href="https://github.com/FTShare-Lab/FTShare-python-sdk/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-MIT-667085" alt="MIT License"></a>
41
+ </p>
42
+
43
+ <p align="center">
44
+ <strong>让金融数据成为 AI 的可靠上下文。</strong><br>
45
+ FTShare 面向 AI Agent、量化研究和金融应用提供统一、可验证、可扩展的金融数据服务。
46
+ </p>
47
+
48
+ <p align="center">
49
+ <a href="https://ftai.chat/ftshare"><strong>FTShare 官网</strong></a>
50
+ · <a href="https://ftai.chat/me/profile">获取 API Key</a>
51
+ · <a href="https://market.ft.tech/gateway/doc">数据接口文档</a>
52
+ · <a href="https://github.com/FTShare-Lab/FTShare-python-sdk/issues">问题反馈</a>
53
+ </p>
54
+
55
+ > [!IMPORTANT]
56
+ > 使用托管数据服务前,请先登录 FTShare 获取 API Key,并通过环境变量 `FTSHARE_API_KEY` 或 `market_api(api_key=...)` 配置鉴权。
57
+
58
+ ## 先看它能做什么
59
+
60
+ `FTShare-python-sdk` 是 FTShare 的 Python 数据接入层。它将基础金融数据和 FTShare 特色因子统一成 Python 调用方式,默认返回 pandas `DataFrame`,可以直接进入分析、研究和应用开发流程。
61
+
62
+ <p align="center">
63
+ <a href="https://ftai.chat/ftshare"><img src="./docs/assets/readme/ftshare-website.png" width="100%" alt="FTShare 官网横幅,展示金融数据服务及 SDK、MCP、Skills 接入入口"></a>
64
+ </p>
65
+
66
+ <p align="center"><sub>FTShare 官网。点击图片进入产品与套餐页面。</sub></p>
67
+
68
+ ## 三步跑通第一次调用
69
+
70
+ ### 1. 获取 API Key
71
+
72
+ 登录 [FTShare 账号中心](https://ftai.chat/me/profile),获取当前账号的 API Key。
73
+
74
+ ### 2. 安装 SDK
75
+
76
+ 当前从 GitHub 源码安装:
77
+
78
+ ```bash
79
+ git clone https://github.com/FTShare-Lab/FTShare-python-sdk.git
80
+ cd FTShare-python-sdk
81
+ pip install -e .
82
+ ```
83
+
84
+ ### 3. 查询数据
85
+
86
+ ```bash
87
+ export FTSHARE_API_KEY="your_api_key"
88
+ ```
89
+
90
+ ```python
91
+ import ftshare as ft
92
+
93
+ market = ft.market_api()
94
+
95
+ df = market.ashare_news_sentiment_factors(
96
+ trade_code="600519.SH",
97
+ start_date="20260801",
98
+ end_date="20260831",
99
+ limit=5,
100
+ )
101
+
102
+ print(df.head())
103
+ ```
104
+
105
+ > [!NOTE]
106
+ > `ashare_news_sentiment_factors` 是 FTShare 的 A 股新闻情绪因子接口。它返回研究数据,不构成股票推荐或未来收益判断;具体字段和数据范围以当前接口文档与账号权限为准。
107
+
108
+ ## 选择适合你的 FTShare 接入方式
109
+
110
+ | 接入方式 | 适合场景 | 返回或调用形态 | 仓库 |
111
+ |---|---|---|---|
112
+ | **Python SDK** | Python 程序、数据分析、量化研究 | pandas `DataFrame`、Python rows、原始 JSON | 当前仓库 |
113
+ | **MCP** | 支持 MCP 的 AI 客户端与 Agent | 标准 MCP 工具、结构化结果 | [FTShare-MCP](https://github.com/FTShare-Lab/FTShare-MCP) |
114
+ | **Skill** | Claude Code、Codex、OpenClaw 等 Agent 运行时 | 自然语言到数据接口的路由 | [FTShare-skill](https://github.com/FTShare-Lab/FTShare-skill) |
115
+
116
+ 三种方式连接同一套 FTShare 金融数据服务。SDK 适合稳定编程,MCP 适合标准 Agent 工具调用,Skill 适合由 Agent 理解问题并选择数据接口。
117
+
118
+ ## 为什么使用 Python SDK
119
+
120
+ - **DataFrame-first:** 默认返回 pandas `DataFrame`,减少重复的数据转换工作。
121
+ - **统一入口:** 通过 `ft.market_api()` 创建客户端,同时接入基础金融数据与 FTShare 特色因子。
122
+ - **多种返回形态:** 支持 DataFrame、Python 行数据与原始 JSON。
123
+ - **字段与分页:** 支持字段筛选、分页和多页拉取。
124
+ - **明确异常:** 区分 HTTP、JSON 解析和服务端业务错误。
125
+ - **可复用底座:** 可用于研究脚本、数据应用、MCP 工具和 Agent 工作流的数据接入层。
126
+
127
+ ## 常用客户端配置
128
+
129
+ ```python
130
+ import ftshare as ft
131
+
132
+ # 默认从 FTSHARE_API_KEY 环境变量读取
133
+ market = ft.market_api(timeout=20)
134
+
135
+ # 也可以显式传入
136
+ market = ft.market_api(api_key="your_api_key", timeout=20)
137
+ ```
138
+
139
+ 自定义 Base URL:
140
+
141
+ ```python
142
+ market = ft.market_api(
143
+ base_url="https://market.ft.tech/gateway/",
144
+ timeout=20,
145
+ )
146
+ ```
147
+
148
+ ## 返回类型
149
+
150
+ 默认返回 DataFrame:
151
+
152
+ ```python
153
+ df = market.ashare_news_sentiment_factors(
154
+ trade_code="600519.SH",
155
+ limit=10,
156
+ )
157
+ ```
158
+
159
+ 返回 Python 行数据:
160
+
161
+ ```python
162
+ rows = market.ashare_news_sentiment_factors(
163
+ trade_code="600519.SH",
164
+ limit=10,
165
+ as_dataframe=False,
166
+ )
167
+ ```
168
+
169
+ 返回服务端完整 JSON:
170
+
171
+ ```python
172
+ payload = market.ashare_news_sentiment_factors(
173
+ trade_code="600519.SH",
174
+ limit=10,
175
+ raw=True,
176
+ )
177
+ ```
178
+
179
+ ## 分页与结果控制
180
+
181
+ ```python
182
+ df = market.ashare_news_sentiment_factors(
183
+ trade_code="600519.SH",
184
+ page=1,
185
+ page_size=20,
186
+ )
187
+ ```
188
+
189
+ ```python
190
+ df = market.ashare_news_sentiment_factors(
191
+ trade_code="600519.SH",
192
+ all_pages=True,
193
+ max_pages=3,
194
+ )
195
+ ```
196
+
197
+ 详细的接口参数、字段与专题说明请查看 [FTShare 数据接口文档](https://market.ft.tech/gateway/doc)。
198
+
199
+ ## 错误处理
200
+
201
+ ```python
202
+ from ftshare import (
203
+ FtshareAPIError,
204
+ FtshareDecodeError,
205
+ FtshareHTTPError,
206
+ )
207
+ ```
208
+
209
+ - `FtshareHTTPError`:HTTP 状态码不是 2xx。
210
+ - `FtshareDecodeError`:响应不是合法 JSON。
211
+ - `FtshareAPIError`:服务端返回业务错误。
212
+
213
+ ## 开发与测试
214
+
215
+ ```bash
216
+ git clone https://github.com/FTShare-Lab/FTShare-python-sdk.git
217
+ cd FTShare-python-sdk
218
+ pip install -e ".[test]"
219
+ python3 -m pytest
220
+ ```
221
+
222
+ 真实接口集成测试默认跳过:
223
+
224
+ ```bash
225
+ FTSHARE_RUN_INTEGRATION=1 python3 -m pytest tests/test_integration_market.py
226
+ ```
227
+
228
+ ## 开源代码与数据服务边界
229
+
230
+ 本仓库代码采用 MIT License。开源许可证覆盖本仓库代码,不自动包含 FTShare 托管数据服务的访问额度、数据授权、再分发权或商业数据使用权;相关范围以产品页面和服务条款为准。
231
+
232
+ ## 社区与反馈
233
+
234
+ - 使用问题与功能建议:[GitHub Issues](https://github.com/FTShare-Lab/FTShare-python-sdk/issues)
235
+ - 正式产品与套餐:[FTShare](https://ftai.chat/ftshare)
236
+ - API Key 管理:[账号中心](https://ftai.chat/me/profile)
237
+ - MCP 接入:[FTShare-MCP](https://github.com/FTShare-Lab/FTShare-MCP)
238
+ - Agent Skill:[FTShare-skill](https://github.com/FTShare-Lab/FTShare-skill)
239
+
240
+ ### 加入 FTShare 社区交流群
241
+
242
+ 欢迎加入 FTShare 社区交流群,讨论 Python SDK、特色因子、金融数据接口、MCP、Skill 和 Agent 使用。
243
+
244
+ <p align="center">
245
+ <img src="./docs/assets/wechat-group-20260929.png" width="320" alt="FTShare 微信社区交流群二维码,有效期至 2026 年 9 月 29 日">
246
+ </p>
247
+
248
+ > 群内用于交流使用经验和补充问题信息;Bug、功能需求和接口问题建议优先通过 GitHub Issues 提交,便于公开跟踪和沉淀。
249
+
250
+ **二维码有效期至 2026 年 9 月 29 日。** 如二维码失效,请在 Issues 中留言。
251
+
252
+ ---
253
+
254
+ <p align="center">
255
+ <strong>FTShare</strong> · 让金融数据成为 AI 的可靠上下文
256
+ </p>
@@ -0,0 +1,224 @@
1
+ <p align="center">
2
+ <img src="./docs/assets/readme/hero.svg" width="100%" alt="FTShare Python SDK,用 Python 和 pandas 接入金融数据">
3
+ </p>
4
+
5
+ <p align="center">
6
+ <a href="https://github.com/FTShare-Lab/FTShare-python-sdk/releases/tag/v1.0.1"><img src="https://img.shields.io/badge/release-v1.0.1-3563E9" alt="FTShare Python SDK v1.0.1"></a>
7
+ <a href="https://www.python.org/downloads/"><img src="https://img.shields.io/badge/python-3.9%2B-111827" alt="Python 3.9 or later"></a>
8
+ <a href="https://github.com/FTShare-Lab/FTShare-python-sdk/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-MIT-667085" alt="MIT License"></a>
9
+ </p>
10
+
11
+ <p align="center">
12
+ <strong>让金融数据成为 AI 的可靠上下文。</strong><br>
13
+ FTShare 面向 AI Agent、量化研究和金融应用提供统一、可验证、可扩展的金融数据服务。
14
+ </p>
15
+
16
+ <p align="center">
17
+ <a href="https://ftai.chat/ftshare"><strong>FTShare 官网</strong></a>
18
+ · <a href="https://ftai.chat/me/profile">获取 API Key</a>
19
+ · <a href="https://market.ft.tech/gateway/doc">数据接口文档</a>
20
+ · <a href="https://github.com/FTShare-Lab/FTShare-python-sdk/issues">问题反馈</a>
21
+ </p>
22
+
23
+ > [!IMPORTANT]
24
+ > 使用托管数据服务前,请先登录 FTShare 获取 API Key,并通过环境变量 `FTSHARE_API_KEY` 或 `market_api(api_key=...)` 配置鉴权。
25
+
26
+ ## 先看它能做什么
27
+
28
+ `FTShare-python-sdk` 是 FTShare 的 Python 数据接入层。它将基础金融数据和 FTShare 特色因子统一成 Python 调用方式,默认返回 pandas `DataFrame`,可以直接进入分析、研究和应用开发流程。
29
+
30
+ <p align="center">
31
+ <a href="https://ftai.chat/ftshare"><img src="./docs/assets/readme/ftshare-website.png" width="100%" alt="FTShare 官网横幅,展示金融数据服务及 SDK、MCP、Skills 接入入口"></a>
32
+ </p>
33
+
34
+ <p align="center"><sub>FTShare 官网。点击图片进入产品与套餐页面。</sub></p>
35
+
36
+ ## 三步跑通第一次调用
37
+
38
+ ### 1. 获取 API Key
39
+
40
+ 登录 [FTShare 账号中心](https://ftai.chat/me/profile),获取当前账号的 API Key。
41
+
42
+ ### 2. 安装 SDK
43
+
44
+ 当前从 GitHub 源码安装:
45
+
46
+ ```bash
47
+ git clone https://github.com/FTShare-Lab/FTShare-python-sdk.git
48
+ cd FTShare-python-sdk
49
+ pip install -e .
50
+ ```
51
+
52
+ ### 3. 查询数据
53
+
54
+ ```bash
55
+ export FTSHARE_API_KEY="your_api_key"
56
+ ```
57
+
58
+ ```python
59
+ import ftshare as ft
60
+
61
+ market = ft.market_api()
62
+
63
+ df = market.ashare_news_sentiment_factors(
64
+ trade_code="600519.SH",
65
+ start_date="20260801",
66
+ end_date="20260831",
67
+ limit=5,
68
+ )
69
+
70
+ print(df.head())
71
+ ```
72
+
73
+ > [!NOTE]
74
+ > `ashare_news_sentiment_factors` 是 FTShare 的 A 股新闻情绪因子接口。它返回研究数据,不构成股票推荐或未来收益判断;具体字段和数据范围以当前接口文档与账号权限为准。
75
+
76
+ ## 选择适合你的 FTShare 接入方式
77
+
78
+ | 接入方式 | 适合场景 | 返回或调用形态 | 仓库 |
79
+ |---|---|---|---|
80
+ | **Python SDK** | Python 程序、数据分析、量化研究 | pandas `DataFrame`、Python rows、原始 JSON | 当前仓库 |
81
+ | **MCP** | 支持 MCP 的 AI 客户端与 Agent | 标准 MCP 工具、结构化结果 | [FTShare-MCP](https://github.com/FTShare-Lab/FTShare-MCP) |
82
+ | **Skill** | Claude Code、Codex、OpenClaw 等 Agent 运行时 | 自然语言到数据接口的路由 | [FTShare-skill](https://github.com/FTShare-Lab/FTShare-skill) |
83
+
84
+ 三种方式连接同一套 FTShare 金融数据服务。SDK 适合稳定编程,MCP 适合标准 Agent 工具调用,Skill 适合由 Agent 理解问题并选择数据接口。
85
+
86
+ ## 为什么使用 Python SDK
87
+
88
+ - **DataFrame-first:** 默认返回 pandas `DataFrame`,减少重复的数据转换工作。
89
+ - **统一入口:** 通过 `ft.market_api()` 创建客户端,同时接入基础金融数据与 FTShare 特色因子。
90
+ - **多种返回形态:** 支持 DataFrame、Python 行数据与原始 JSON。
91
+ - **字段与分页:** 支持字段筛选、分页和多页拉取。
92
+ - **明确异常:** 区分 HTTP、JSON 解析和服务端业务错误。
93
+ - **可复用底座:** 可用于研究脚本、数据应用、MCP 工具和 Agent 工作流的数据接入层。
94
+
95
+ ## 常用客户端配置
96
+
97
+ ```python
98
+ import ftshare as ft
99
+
100
+ # 默认从 FTSHARE_API_KEY 环境变量读取
101
+ market = ft.market_api(timeout=20)
102
+
103
+ # 也可以显式传入
104
+ market = ft.market_api(api_key="your_api_key", timeout=20)
105
+ ```
106
+
107
+ 自定义 Base URL:
108
+
109
+ ```python
110
+ market = ft.market_api(
111
+ base_url="https://market.ft.tech/gateway/",
112
+ timeout=20,
113
+ )
114
+ ```
115
+
116
+ ## 返回类型
117
+
118
+ 默认返回 DataFrame:
119
+
120
+ ```python
121
+ df = market.ashare_news_sentiment_factors(
122
+ trade_code="600519.SH",
123
+ limit=10,
124
+ )
125
+ ```
126
+
127
+ 返回 Python 行数据:
128
+
129
+ ```python
130
+ rows = market.ashare_news_sentiment_factors(
131
+ trade_code="600519.SH",
132
+ limit=10,
133
+ as_dataframe=False,
134
+ )
135
+ ```
136
+
137
+ 返回服务端完整 JSON:
138
+
139
+ ```python
140
+ payload = market.ashare_news_sentiment_factors(
141
+ trade_code="600519.SH",
142
+ limit=10,
143
+ raw=True,
144
+ )
145
+ ```
146
+
147
+ ## 分页与结果控制
148
+
149
+ ```python
150
+ df = market.ashare_news_sentiment_factors(
151
+ trade_code="600519.SH",
152
+ page=1,
153
+ page_size=20,
154
+ )
155
+ ```
156
+
157
+ ```python
158
+ df = market.ashare_news_sentiment_factors(
159
+ trade_code="600519.SH",
160
+ all_pages=True,
161
+ max_pages=3,
162
+ )
163
+ ```
164
+
165
+ 详细的接口参数、字段与专题说明请查看 [FTShare 数据接口文档](https://market.ft.tech/gateway/doc)。
166
+
167
+ ## 错误处理
168
+
169
+ ```python
170
+ from ftshare import (
171
+ FtshareAPIError,
172
+ FtshareDecodeError,
173
+ FtshareHTTPError,
174
+ )
175
+ ```
176
+
177
+ - `FtshareHTTPError`:HTTP 状态码不是 2xx。
178
+ - `FtshareDecodeError`:响应不是合法 JSON。
179
+ - `FtshareAPIError`:服务端返回业务错误。
180
+
181
+ ## 开发与测试
182
+
183
+ ```bash
184
+ git clone https://github.com/FTShare-Lab/FTShare-python-sdk.git
185
+ cd FTShare-python-sdk
186
+ pip install -e ".[test]"
187
+ python3 -m pytest
188
+ ```
189
+
190
+ 真实接口集成测试默认跳过:
191
+
192
+ ```bash
193
+ FTSHARE_RUN_INTEGRATION=1 python3 -m pytest tests/test_integration_market.py
194
+ ```
195
+
196
+ ## 开源代码与数据服务边界
197
+
198
+ 本仓库代码采用 MIT License。开源许可证覆盖本仓库代码,不自动包含 FTShare 托管数据服务的访问额度、数据授权、再分发权或商业数据使用权;相关范围以产品页面和服务条款为准。
199
+
200
+ ## 社区与反馈
201
+
202
+ - 使用问题与功能建议:[GitHub Issues](https://github.com/FTShare-Lab/FTShare-python-sdk/issues)
203
+ - 正式产品与套餐:[FTShare](https://ftai.chat/ftshare)
204
+ - API Key 管理:[账号中心](https://ftai.chat/me/profile)
205
+ - MCP 接入:[FTShare-MCP](https://github.com/FTShare-Lab/FTShare-MCP)
206
+ - Agent Skill:[FTShare-skill](https://github.com/FTShare-Lab/FTShare-skill)
207
+
208
+ ### 加入 FTShare 社区交流群
209
+
210
+ 欢迎加入 FTShare 社区交流群,讨论 Python SDK、特色因子、金融数据接口、MCP、Skill 和 Agent 使用。
211
+
212
+ <p align="center">
213
+ <img src="./docs/assets/wechat-group-20260929.png" width="320" alt="FTShare 微信社区交流群二维码,有效期至 2026 年 9 月 29 日">
214
+ </p>
215
+
216
+ > 群内用于交流使用经验和补充问题信息;Bug、功能需求和接口问题建议优先通过 GitHub Issues 提交,便于公开跟踪和沉淀。
217
+
218
+ **二维码有效期至 2026 年 9 月 29 日。** 如二维码失效,请在 Issues 中留言。
219
+
220
+ ---
221
+
222
+ <p align="center">
223
+ <strong>FTShare</strong> · 让金融数据成为 AI 的可靠上下文
224
+ </p>