API aggregator core runtime with registry, scheduler, local persistence, and dashboard.
Project description
api-aggregator
中文 | English
面向机器人/自动化场景的 API 聚合运行时,提供 API 池与站点池管理、远程拉取与解析、本地去重持久化、定时触发、Web Dashboard 管理。
目录
核心能力
- API/站点池管理
- 统一在 SQLite 中持久化,支持增删改查、排序、筛选、分页。
- 批量测试与可见化结果
- 通过 NDJSON 流实时返回测试进度,自动回写 API
valid状态。
- 通过 NDJSON 流实时返回测试进度,自动回写 API
- 远程数据拉取与解析
- 支持
text/image/video/audio四类结果,支持 JSON 路径提取与 HTML 纯文本提取。
- 支持
- 本地去重与回退
- 远程成功时写入本地(文本/二进制去重);远程失败时可回退读取本地随机历史数据。
- Dashboard 运维能力
- 池导入导出、批量删除、本地数据浏览与删除、系统重启、代码更新。
安装
推荐 Python 3.10+。
pip install -r requirements.txt
或安装当前项目包:
pip install .
说明:
- 发布包名:
api-aggregator - 导入名:
api_aggregator
Docker 部署
完整说明见:docs/zh-CN/docker.md
方式一:直接使用 Docker
构建镜像:
docker build -t api-aggregator:latest .
运行容器:
docker run -d \
--name api-aggregator \
-p 4141:4141 \
-v "$(pwd)/data:/app/data" \
-v "$(pwd)/pool_files:/app/pool_files" \
--restart unless-stopped \
api-aggregator:latest
方式二:使用 Docker Compose
docker compose up -d --build
停止并移除容器:
docker compose down
说明:
- Dashboard 地址:
http://127.0.0.1:4141 - 持久化目录:
./data->/app/data./pool_files->/app/pool_files
快速开始
直接启动:
python start.py
常用参数:
python start.py --dashboard-host 127.0.0.1 --dashboard-port 4141
python start.py --no-dashboard
代码方式接入:
import asyncio
from api_aggregator import APICoreApp
async def main() -> None:
app = APICoreApp()
await app.start()
try:
await asyncio.Event().wait()
finally:
await app.stop()
asyncio.run(main())
运行与配置
默认运行目录(相对仓库根目录):
data/api_aggregator.db:站点池/API 池持久化数据库data/local/:本地缓存数据(text/image/video/audio)pool_files/:池导入导出默认目录
默认配置(代码内置):
- Dashboard:
0.0.0.0:4141 - 默认请求超时:
60s - 默认请求头:
User-Agent+Accept: */*
注意:当前版本的 APIConfig 以代码默认值为主,data/app_config.json 并非核心配置来源。
项目结构
api-aggregator/
src/api_aggregator/
dashboard/ # Web UI 与 HTTP API
data_service/ # 远程请求、本地缓存、聚合数据服务
entry/ # API/站点实体与管理器
service/ # 测试、导入导出、重启、更新等服务
database.py # SQLite 持久化
main.py # APICoreApp 生命周期
pool_files/ # 池导入导出默认目录
data/ # 运行时数据目录
docs/
Dashboard 与 HTTP API 文档
- 中文:
docs/zh-CN/dashboard-http-api.md - English:
docs/en/dashboard-http-api.md - 数据结构说明:
docs/zh-CN/api-data-schema.md - Docker 部署:
docs/zh-CN/docker.md
Dashboard 默认地址:http://127.0.0.1:4141
与机器人框架集成
建议按三层对接:
- 生命周期:框架启动时
await app.start(),关闭时await app.stop()。 - 消息匹配:
api_mgr.match_entries(...)找命中 API,再data_service.fetch(...)拉取。 - 定时触发:
set_cron_entry_handler(...)注册回调,回调中调用fetch_cron_data(...)。
最小适配器:
from api_aggregator import APICoreApp, APIEntry
class BotFrameworkAdapter:
def __init__(self) -> None:
self.app = APICoreApp()
self.app.set_cron_entry_handler(self.on_cron_entry)
async def on_framework_start(self) -> None:
await self.app.start()
async def on_framework_stop(self) -> None:
await self.app.stop()
async def on_message(self, text: str) -> list[str]:
replies: list[str] = []
matched = self.app.api_mgr.match_entries(text, only_enabled=True)
for entry in matched:
data = await self.app.data_service.fetch(entry, use_local=True)
if data and data.final_text:
replies.append(data.final_text)
return replies
async def on_cron_entry(self, entry: APIEntry) -> None:
data = await self.app.fetch_cron_data(entry, use_local=True)
if data and data.final_text:
print(f"[cron] {entry.name}: {data.final_text}")
开发与发布
本地检查:
python -m compileall src tests
python -m unittest discover -s tests -p "test_*.py"
uv run ruff check .
构建:
uv build
Star History
Project details
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 api_aggregator-0.1.3.tar.gz.
File metadata
- Download URL: api_aggregator-0.1.3.tar.gz
- Upload date:
- Size: 212.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c14807236638a4b823bf9f1381ccac6c03439c6e1d5f30a9db9a22d2e71a3c0c
|
|
| MD5 |
99d6866cbb37b853902ff5bef29afe5a
|
|
| BLAKE2b-256 |
cff967102f4022212cd13ffdae1177ff57f7771d2ba269c1bba2ffc9f296c36b
|
Provenance
The following attestation bundles were made for api_aggregator-0.1.3.tar.gz:
Publisher:
release.yml on Zhalslar/api-aggregator
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
api_aggregator-0.1.3.tar.gz -
Subject digest:
c14807236638a4b823bf9f1381ccac6c03439c6e1d5f30a9db9a22d2e71a3c0c - Sigstore transparency entry: 970381767
- Sigstore integration time:
-
Permalink:
Zhalslar/api-aggregator@9b420ee37164ac76a99a0c0964d7a1efc1c61906 -
Branch / Tag:
refs/tags/v0.1.3 - Owner: https://github.com/Zhalslar
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@9b420ee37164ac76a99a0c0964d7a1efc1c61906 -
Trigger Event:
release
-
Statement type:
File details
Details for the file api_aggregator-0.1.3-py3-none-any.whl.
File metadata
- Download URL: api_aggregator-0.1.3-py3-none-any.whl
- Upload date:
- Size: 223.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
09137aa6ad5c5d39d43119dec9a485ab78d8a904bcae64d932ed40b496378416
|
|
| MD5 |
21908a81852a8b9a9b4b6cc8b900d9e1
|
|
| BLAKE2b-256 |
264caaa7988feeae6e1103878e77659fee43fdd4c78bbaa2464f5ff8741e719f
|
Provenance
The following attestation bundles were made for api_aggregator-0.1.3-py3-none-any.whl:
Publisher:
release.yml on Zhalslar/api-aggregator
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
api_aggregator-0.1.3-py3-none-any.whl -
Subject digest:
09137aa6ad5c5d39d43119dec9a485ab78d8a904bcae64d932ed40b496378416 - Sigstore transparency entry: 970381795
- Sigstore integration time:
-
Permalink:
Zhalslar/api-aggregator@9b420ee37164ac76a99a0c0964d7a1efc1c61906 -
Branch / Tag:
refs/tags/v0.1.3 - Owner: https://github.com/Zhalslar
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@9b420ee37164ac76a99a0c0964d7a1efc1c61906 -
Trigger Event:
release
-
Statement type: