Skip to main content

a sdk core for xfyun

Project description

xfyunsdkcore

xfyunsdkcore是讯飞开放平台Web API的核心Python SDK,提供HTTP客户端、签名生成和通用工具类,为其他业务模块提供基础支持。

功能特点

  • HTTP客户端:支持同步/异步请求,内置重试机制
  • 签名工具:提供多种签名算法实现,支持不同API认证需求
  • 通用工具:包含字符串处理、JSON转换和加密工具类

安装方法

pip install xfyunsdkcore

依赖说明

  • httpx: HTTP客户端库
  • websocket-client<2.0.0: WebSocket支持

快速开始

HTTP客户端使用

from xfyunsdkcore.http_client import HttpClient

# 初始化客户端
client = HttpClient(
    host_url="https://api.xfyun.cn",
    app_id="your_app_id",
    api_key="your_api_key",
    api_secret="your_api_secret",
    timeout=30,
    enable_retry=True
)

# 发送GET请求
response = client.get("/v1/service")
print(response.json())

# 发送POST请求
response = client.post("/v1/service", json={"key": "value"})
print(response.json())

异步请求示例

import asyncio
from xfyunsdkcore.http_client import HttpClient

async def main():
    client = HttpClient(host_url="https://api.xfyun.cn")
    response = await client.async_get("/v1/service")
    print(response.json())

asyncio.run(main())

签名生成

from xfyunsdkcore.signature import Signature

# 创建签名URL
api_url = "wss://ws-api.xfyun.cn/v1/iat"
signed_url = Signature.create_signed_url(
    api_url=api_url,
    api_key="your_api_key",
    api_secret="your_api_secret"
)
print(signed_url)

核心模块

HttpClient

提供HTTP请求的核心功能,支持:

  • 同步/异步请求
  • 超时控制
  • 重试机制
  • 文件上传

Signature

提供多种签名实现:

  • create_signed_url: WebSocket签名URL生成
  • get_signature_header: 请求头签名生成
  • get_digest_header: 摘要认证头生成

工具类

  • StringUtils: 字符串处理工具
  • JsonUtils: JSON序列化/反序列化
  • CryptTools: 加密工具,支持HMAC和MD5

许可证

请参见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

xfyunsdkcore-0.0.1.tar.gz (14.3 kB view details)

Uploaded Source

Built Distribution

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

xfyunsdkcore-0.0.1-py3-none-any.whl (15.8 kB view details)

Uploaded Python 3

File details

Details for the file xfyunsdkcore-0.0.1.tar.gz.

File metadata

  • Download URL: xfyunsdkcore-0.0.1.tar.gz
  • Upload date:
  • Size: 14.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.7.1

File hashes

Hashes for xfyunsdkcore-0.0.1.tar.gz
Algorithm Hash digest
SHA256 435bda184255ecde4ab3117ece413aebbc7c6c9fe46cd39aeabdf85b79f23707
MD5 2dccfddc972668ed205aa9420bcc5d19
BLAKE2b-256 bbbc4d45bc17127b9ed34fffee0b813f0c800394e44847625e49878bdf0e77d8

See more details on using hashes here.

File details

Details for the file xfyunsdkcore-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: xfyunsdkcore-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 15.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.7.1

File hashes

Hashes for xfyunsdkcore-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 32a1721fbf076a1ccc9cf38102ccf2dba3af8c72a2f592a8bcdd5ade535439e5
MD5 a8b4fb0744201d3543070c8e4885f27a
BLAKE2b-256 9ef34ef16d01f3937d00075a6713e56d75a528876430b35cd31041cc8cb99028

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