Skip to main content

A Python library for parsing API configuration files following the APICORE specification

Project description

APICORE_Python

Version

APICORE access framework for Python

Main Repo

介绍

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. 插件开发注意事项

  1. 必须包含类型提示
  2. 函数必须返回字典
  3. 做好错误处理,避免因字段缺失导致异常
  4. 保持函数纯净,不修改输入数据
  5. 文档字符串需清晰说明功能和返回格式

6. 插件注册

插件会自动注册为 response() 的方法,例如:

  • image.pyresponse().image()
  • video.pyresponse().video()

许可证

MIT License

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

apicore_python-1.0.1.tar.gz (5.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

apicore_python-1.0.1-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

Details for the file apicore_python-1.0.1.tar.gz.

File metadata

  • Download URL: apicore_python-1.0.1.tar.gz
  • Upload date:
  • Size: 5.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.6

File hashes

Hashes for apicore_python-1.0.1.tar.gz
Algorithm Hash digest
SHA256 8bbfcac95044b53dc7a5b10947b036248ad7437ffa86486f5d208d27125e3161
MD5 e26085767c7c8c3323137f796d7022bb
BLAKE2b-256 4b0c46f54c8782000a17c5465a4521816b8793234799c9a732f187b61de4c00e

See more details on using hashes here.

File details

Details for the file apicore_python-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: apicore_python-1.0.1-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.10.6

File hashes

Hashes for apicore_python-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 639bb5a262b37c1a392753b4355bca6541202b1b3cce88689bea46306e9b00f6
MD5 2a0961b90e49d2a62a85dfadf187e27d
BLAKE2b-256 a610c269b83eedfe18791c75ef549fef8349f24f5fcda02e1977df23d623689f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page