Skip to main content

fish-edge-gateway-sdk (Python)

接入 apex-edge-gateway 的服务侧 SDK:manifest 声明与暴露、internal auth、trace 透传。协议契约见仓库 docs/contracts/。

安装(不发布 PyPI,直接 git 依赖)

# requirements.txt / pyproject dependency(锁 tag 或 commit,不要追 main)
fish-edge-gateway-sdk @ git+ssh://git@github.com/fishaudio/apex-edge-gateway.git@<tag-or-sha>#subdirectory=sdk-python
# 本地开发
pip install "fish-edge-gateway-sdk @ git+ssh://git@github.com/fishaudio/apex-edge-gateway.git@main#subdirectory=sdk-python"

# uv
uv add "fish-edge-gateway-sdk @ git+ssh://git@github.com/fishaudio/apex-edge-gateway.git@main#subdirectory=sdk-python"

# CI / Docker(https + token,避免挂 ssh key)
pip install "fish-edge-gateway-sdk @ git+https://${GITHUB_TOKEN}@github.com/fishaudio/apex-edge-gateway.git@<sha>#subdirectory=sdk-python"

版本锁定约定:SDK 变更打 sdk-python/vX.Y.Z 形式的 git tag,服务锁 tag 升级;紧急验证可锁 commit sha。

集成

from fastapi import Depends, FastAPI
from fish_edge_gateway_sdk import edge_route, mount_edge, require_gateway

app = FastAPI()

@app.post("/internal/asr", dependencies=[Depends(require_gateway)])
@edge_route(auth="internal")
async def asr(payload: dict) -> dict: ...

mount_edge(app, service="omni-asr")   # 挂载 GET /.edge/manifest

功能门禁(manifest 契约 §9B,仅 auth="api_key"):调用方 team 不具备要求的 feature 时,gateway 直接回 403 feature_required,请求不会下落到其它路由,handler 无需再判断。feature 名不超过 64 个字符,每条路由合计不超过 4096 个。带门禁的 manifest 自动声明 schema_version: 2:先升级 gateway 再发布(旧 gateway 会拒绝 v2 manifest,而不是不设门禁地服务它)。

@app.post("/v1/tts-pro")
@edge_route(auth="api_key", protocol="bytes",
            requires_features=["tts-pro"],                     # 全部需要
            requires_any_of=[["voice-clone", "enterprise"]])   # 每组至少一个
async def tts_pro(...): ...

k8s Service 侧标注(manifest 契约 §2.1):

metadata:
  annotations:
    fish.audio/edge-discovery: enable
    # 可选:manifest 端点与业务端口分离时
    # fish.audio/edge-discovery-port: "9090"
    # fish.audio/edge-discovery-url: /.edge/manifest

gateway 侧无需额外授权:发现 namespace 的成员资格就是信任边界(manifest 契约 §11),被发现的 manifest 其 route 直接编译。

形态按 Accept 协商的端点(protocol="negotiated")

一个端点这次回 SSE、下次回裸音频或 JSON 时声明 protocol="negotiated",gateway 按每个响应的 Content-Type 计费(manifest 契约 §9)。两条约束:

  • WebSocket 形态是独立的 ws 路由:FastAPI WebSocket 端点上只接受 protocol="ws"(negotiated 会在 mount_edge 时报错),且要放在不同的 path 上——同 path + GET 的两条声明只有先声明的生效。完整例子见 examples/negotiated_demo.py。
  • 免费形态显式报 0:不收费的响应发 usage_header(0);什么都不发 = usage 缺失,gateway 计入 gateway_usage_missing_total 并告警(usage 契约 §8)。

上线顺序:所有 DC 的 gateway 升级到支持 negotiated 的版本之后,服务才能发布带 negotiated 的 manifest——旧 gateway 会拒掉整份 manifest(manifest 契约 §9 Rollout)。

环境变量

变量 语义
FISH_EDGE_GATEWAY_TOKEN 期望的 x-fish-gateway-token。未设 = 观察模式(只记日志)
FISH_EDGE_REQUIRE_GATEWAY 1 时强制校验(403 拒绝非 gateway 流量)。P6 gateway 下发 token 后开启

开发

pip install -e "sdk-python[dev]"
pytest sdk-python/tests -q

Metadata

Release files for fish-edge-gateway-sdk 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fish-edge-gateway-sdk 0.2.0
File Size Uploaded Provenance
fish_edge_gateway_sdk-0.2.0.tar.gz 45.2 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for fish-edge-gateway-sdk 0.2.0
File Interpreter ABI Platform
fish_edge_gateway_sdk-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 66.2 kB

Release files / fish_edge_gateway_sdk-0.2.0.tar.gz

Download URL fish_edge_gateway_sdk-0.2.0.tar.gz
Size 45.2 kB
Tags Source
SHA-256 checksum
How to use checksums
94708c84cf6b01ecb39974dbe978448fe2988317bfceb1da6613d012084fb969
BLAKE2b-256 checksum
How to use checksums
91376feccbb0c61c8922008fd71efb7950f091de6e7494f799b36411ea50f574
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / fish_edge_gateway_sdk-0.2.0-py3-none-any.whl

Download URL fish_edge_gateway_sdk-0.2.0-py3-none-any.whl
Size 21.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
70f2d282e9e679f41e9deb6cfb0c7b478b18ad9a8f8673d06ad9f6ab114151d6
BLAKE2b-256 checksum
How to use checksums
453cde56813c76f1079c8ab1d9b805a1090fbe01716ee9d824c08817892dfa0e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for fish-edge-gateway-sdk 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page