Skip to main content

飞函官方 OpenAPI SDK for Python

Project description

飞函 IM OpenAPI SDK - Python

PyPI version CI Python License

English | 中文

飞函,是安全稳定的私有化一站式办公平台,功能包括即时通讯、组织架构、音视频会议、网盘等。

本项目是飞函服务端的 Python SDK,用于通过 OpenAPI 与飞函服务端进行交互。使用前需要先自行部署飞函服务端,部署教程请参考快速部署文档

安装

pip install feihan-sdk

快速开始

import asyncio
from feihan import FeihanClient, SendMessageReq, MessageContent, MessageText, MessageType_TEXT

async def main():
    client = await FeihanClient.create(
        "https://your-backend-url.com",
        "your-app-id",
        "your-app-secret",
    )

    # 可选:预热可提前获取访问凭证和同步服务端时间,减少首次调用的延迟
    await client.preheat()

    # 调用 API
    resp = await client.im.message.send_message(SendMessageReq(
        chat_id="chat-id",
        message_type=MessageType_TEXT,
        message_content=MessageContent(text=MessageText(content="飞函新版本发布!")),
    ))
    print(resp.message_id)

    # 使用完毕后关闭
    await client.close()

asyncio.run(main())

客户端配置

FeihanClient.create() 支持通过关键字参数配置客户端行为:

from feihan import FeihanClient, LogLevel

client = await FeihanClient.create(
    "https://your-backend-url.com",
    "your-app-id",
    "your-app-secret",
    log_level=LogLevel.DEBUG,         # 日志级别(默认: INFO)
    request_timeout=30.0,             # 请求超时秒数(默认: 60.0)
    enable_encryption=False,          # 启用请求加密(默认: True)
)

事件订阅

通过 WebSocket 接收实时事件推送:

from feihan import EventMessageReceive

def on_message(event: EventMessageReceive):
    print("收到消息:", event.body)

client.im.message.event.on_message_receive(on_message)

# 取消订阅
client.im.message.event.off_message_receive(on_message)

上下文管理器

支持 async with 语法自动关闭客户端:

async with await FeihanClient.create(...) as client:
    resp = await client.im.message.send_message(SendMessageReq(...))

环境要求

  • Python 3.9+

相关链接

许可证

Apache-2.0 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

feihan_sdk-0.28.108.tar.gz (24.1 kB view details)

Uploaded Source

Built Distribution

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

feihan_sdk-0.28.108-py3-none-any.whl (32.4 kB view details)

Uploaded Python 3

File details

Details for the file feihan_sdk-0.28.108.tar.gz.

File metadata

  • Download URL: feihan_sdk-0.28.108.tar.gz
  • Upload date:
  • Size: 24.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for feihan_sdk-0.28.108.tar.gz
Algorithm Hash digest
SHA256 940005953b3a7ea220ff92ed41c3795c528fee928fdeaeadb0bb86b0adb45858
MD5 a3faadd900fe306d79c5fbc8c6d91270
BLAKE2b-256 f4c0979f66ce219d01680a727ad6f45538d2a99da268fbdc41fabeb268f9c3a4

See more details on using hashes here.

Provenance

The following attestation bundles were made for feihan_sdk-0.28.108.tar.gz:

Publisher: publish.yaml on feihan-im/openapi-sdk-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file feihan_sdk-0.28.108-py3-none-any.whl.

File metadata

  • Download URL: feihan_sdk-0.28.108-py3-none-any.whl
  • Upload date:
  • Size: 32.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for feihan_sdk-0.28.108-py3-none-any.whl
Algorithm Hash digest
SHA256 8f29662e0dce8b044c6413f8d7d9006f269928f2272c0c64bcb547de6a0d037f
MD5 1e2b643ff8f06a10c2cb84dbf5537b10
BLAKE2b-256 c8bf8e6a954346325c17c351b46e6ea4b3b5f30a2c2d2155511b97b0a954e6b9

See more details on using hashes here.

Provenance

The following attestation bundles were made for feihan_sdk-0.28.108-py3-none-any.whl:

Publisher: publish.yaml on feihan-im/openapi-sdk-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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