通用数据查询 SDK — 远程客户端,零外部依赖
Project description
spts
通用数据查询 SDK(远程客户端),零外部依赖,仅需 Python 标准库。
指向已部署的查询服务即可获取金融数据,无需数据库密码或 Tushare token。
安装
pip install spts
快速上手
from spts import RemoteClient
client = RemoteClient("https://your-server.com")
result = client.query(
api_name="daily_basic",
ts_code="000001.SZ",
start_date="20180101",
end_date="20181231",
limit=100,
)
print(result["source"]) # "database" 或 "tushare"
print(result["columns"]) # ["ts_code", "trade_date", "close", ...]
print(result["rows"]) # [[...], ...]
print(result["row_count"]) # 行数
也可以使用预置的默认客户端和快捷函数:
from spts import set_default_base_url, query_remote
set_default_base_url("https://your-server.com")
result = query_remote(api_name="daily_basic", ts_code="000001.SZ", ...)
支持的接口
| api_name | 说明 |
|---|---|
stock_basic |
股票基础信息列表 |
daily |
股票日线行情 |
daily_basic |
股票每日指标 |
moneyflow_dc |
个股资金流向(DC) |
fina_indicator |
财务指标数据 |
income |
利润表 |
balancesheet |
资产负债表 |
cashflow |
现金流量表 |
fina_audit |
财务审计意见 |
API 参考
RemoteClient(base_url, timeout=30)
| 参数 | 类型 | 说明 |
|---|---|---|
base_url |
str |
查询服务地址,如 "http://your-server.com" |
timeout |
int |
请求超时秒数,默认 30 |
query(api_name, fields=None, params=None, limit=None, **kwargs) → dict
调用远程 GET /api/new_query 查询数据。
| 参数 | 类型 | 说明 |
|---|---|---|
api_name |
str |
接口/表名,如 "daily", "cashflow" |
fields |
str | list | None |
返回字段,逗号分隔或列表 |
params |
dict | None |
过滤参数字典 |
limit |
int | None |
返回行数上限 |
**kwargs |
Any |
其他关键字参数作为过滤条件传入 |
返回结构:
{
"api_name": "daily_basic",
"source": "database", # "database" | "tushare"
"fields": None,
"columns": ["ts_code", ...],
"rows": [[...], ...],
"row_count": 100,
# "fallback_reason": "..." # 仅降级到 Tushare 时出现
}
两种传参方式等价:
# 方式 1:直接传 **kwargs
client.query(api_name="daily", ts_code="000001.SZ", start_date="20240101")
# 方式 2:用 params 字典
client.query(api_name="daily", params={"ts_code": "000001.SZ", "start_date": "20240101"})
ping() → bool
检测远程服务是否可达。
set_default_base_url(url)
设置模块级默认服务地址,之后 query_remote() 无需每次传入 base_url。
query_remote(api_name, fields=None, params=None, limit=None, base_url=None) → dict
模块级快捷查询函数,参数同 RemoteClient.query()。
client
模块级默认 RemoteClient 实例,初始指向 http://localhost:9000。可通过 from spts import client 直接使用:
from spts import client
result = client.query(api_name="daily", ts_code="000001.SZ")
数据分级策略
服务端采用数据库优先 → Tushare 降级策略:
- 优先以
api_name作为表名在 PostgreSQL 中查询 - 若结果为空或查询异常,自动降级调用 Tushare API 获取数据
返回结果的 source 字段指示实际数据来源("database" 或 "tushare")。
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file spts-0.1.0.tar.gz.
File metadata
- Download URL: spts-0.1.0.tar.gz
- Upload date:
- Size: 5.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
af58847d8648bebf4c86853cb4253ee5baeeac88f43d4b131d8009cd94db9113
|
|
| MD5 |
d1f1f1e36c95c2125921a443316956b1
|
|
| BLAKE2b-256 |
7376efe719b261cc49d413a47e7861c5ff81969ad64047081521162287f3a8f9
|
File details
Details for the file spts-0.1.0-py3-none-any.whl.
File metadata
- Download URL: spts-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
498a8701f66457bfc230a504776da18389c04bd841264df896a2da5454d9050c
|
|
| MD5 |
5eacde04500a20a7cd6bd4329e938f6b
|
|
| BLAKE2b-256 |
ad8c46b897c9f183139b0e3151200589dbec8f38d73d36f23e01a2f1310a4859
|