A Python library for parsing API configuration files following the APICORE specification
Project description
介绍
APICORE_Python 是一个 Python 库,用于解析符合 APICORE 规范的 API 配置文件。
安装 (即将上架)
pip install APICORE_Python
功能特性
- 加载和验证 APICORE 配置文件
- 便捷访问配置参数
- 类型提示支持
- 完善的错误处理
- 可扩展的插件系统
使用方法
from APICORE import APICORE
# 加载并验证配置文件
cfg = APICORE("path/to/config.json").init()
# 访问配置项
print(cfg.friendly_name()) # API 友好名称
print(cfg.intro()) # API 介绍
print(cfg.icon()) # API 图标图片链接
print(cfg.link()) # API 端点URL
print(cfg.func()) # HTTP 方法
print(cfg.version()) # APICORE 版本
# 访问参数配置
for param in cfg.parameters():
print(param['friendly_name'])
# 访问响应配置
print(cfg.response().image()['path']) # 图片路径
for other in cfg.response().others():
for data in other['data']:
print(data['friendly_name'])
配置文件格式
APICORE 配置文件遵循特定的 JSON 格式,完整规范请参考 APICORE_Wiki.md。
插件开发指南
1. 插件位置
所有解析器插件应放置在 APICORE/parsers/ 目录下
2. 命名规范
- 插件文件名:
[解析类型].py(如image.py,video.py) - 解析函数名:
parse_[解析类型](如parse_image,parse_video)
3. 插件模板
from typing import Dict, Any
def parse_[解析类型](response_data: Dict[str, Any]) -> Dict[str, Any]:
"""
[解析类型] 响应解析器
参数:
response_data: 完整的响应数据字典
返回:
解析后的[解析类型]配置字典
"""
# 实现解析逻辑
return response_data.get('[解析类型]', {})
4. 示例插件 (image.py)
from typing import Dict, Any
def parse_image(response_data: Dict[str, Any]) -> Dict[str, Any]:
"""
图像响应解析器
从响应数据中提取图像配置
返回格式:
{
"content_type": "URL|BINARY",
"path": "数据路径",
"is_list": bool,
"is_base64": bool
}
"""
return {
'content_type': response_data.get('image', {}).get('content_type'),
'path': response_data.get('image', {}).get('path'),
'is_list': response_data.get('image', {}).get('is_list', False),
'is_base64': response_data.get('image', {}).get('is_base64', False)
}
5. 插件开发注意事项
- 必须包含类型提示
- 函数必须返回字典
- 做好错误处理,避免因字段缺失导致异常
- 保持函数纯净,不修改输入数据
- 文档字符串需清晰说明功能和返回格式
6. 插件注册
插件会自动注册为 response() 的方法,例如:
image.py→response().image()video.py→response().video()
许可证
MIT License
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
apicore_python-1.0.0.tar.gz
(5.3 kB
view details)
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 apicore_python-1.0.0.tar.gz.
File metadata
- Download URL: apicore_python-1.0.0.tar.gz
- Upload date:
- Size: 5.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d5902854f239a3ed7c70c2d2b5f25ae9c6cd75aa02eb923f2e2ec08a5218008e
|
|
| MD5 |
88202dd4b93c3e6ca779a66a95a83232
|
|
| BLAKE2b-256 |
824f599f81092d9ec1f5244a929d4d02c5ed08bb9a792cbca18280d0136e6c0f
|
File details
Details for the file apicore_python-1.0.0-py3-none-any.whl.
File metadata
- Download URL: apicore_python-1.0.0-py3-none-any.whl
- Upload date:
- Size: 5.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b1d3588a1e8ecc976d8515f1eb34ad6fcd6bb46a05b79567ea62ec0561d9b19e
|
|
| MD5 |
52cba0e945cf504ac984fbac2a2f86c4
|
|
| BLAKE2b-256 |
d352d48c77ce33b52589c9282dfd2e649e165f73c4af4f7c9f9bd01009096e3b
|