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.2.tar.gz (15.5 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.2-py3-none-any.whl (17.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: xfyunsdkcore-0.0.2.tar.gz
  • Upload date:
  • Size: 15.5 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.2.tar.gz
Algorithm Hash digest
SHA256 0abb4bca7908772fc02584bdf2560e6c247f6c67831c99a5d7e99decea6028d9
MD5 3a75591c864190f43cba0ccdda2f2404
BLAKE2b-256 8ca3cfbbeb63ac325f0e5e2bbb0573b244113ac294212be138d7f0485322a9c0

See more details on using hashes here.

File details

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

File metadata

  • Download URL: xfyunsdkcore-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 17.2 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 9b4f52cc43249998a692d09e2f3e3ee02a8918735e6aa4642824f89a9d3deba0
MD5 2569cf2fd6cd57446957ee607e917811
BLAKE2b-256 e9e4f00e5d030452860cdcff8f7a0850be3638dc2752bf6190df04733e8880dd

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