Skip to main content

ECAPI SDK for Python

Project description

ecapi-sdk (Python)

ECAPI 的 Python SDK,封装了常用接口,并内置两种鉴权方式:

  • X-API-Key(IAM API Key)
  • X-App-Session-Token(App Session Token)

安装

pip install ecapi-sdk

快速开始

from ecapi_sdk import ECAPIClient

client = ECAPIClient(
    auth={"type": "apiKey", "apiKey": "ec_xxx"},
)

me = client.user.get_me()
player = client.player.get_info({"name": "player123"})
wallet = client.player.get_wallet(ecid="player-ecid")

切换为 App Session Token:

client.set_app_session_token("your_app_session_token")

客户端能力

  • 默认 base_urlhttps://console.easecation.net/apiv2
  • 统一请求入口:client.request(method, path, ...)
  • 默认超时:15 秒(timeout_seconds 可覆盖)
  • 支持 per-request 覆盖鉴权:auth=...
  • 非 2xx 响应抛出 ECAPIError(包含 statuspayloadurl

参数传递(必填/可选)

  • 所有带查询参数的接口都支持两种写法:
    • 推荐:关键字参数(更直观)client.player.get_wallet(ecid="...")
    • 兼容:字典参数 client.player.get_wallet({"ecid": "..."})
  • 哪些字段必填、哪些可选,请直接看完整参考文档:API_REFERENCE.md
  • 该参考文档由后端 OpenAPI 自动生成,和服务端校验保持一致

IDE 强类型提示

  • 包内提供 client.pyi,IDE 会在悬停和参数填写时显示方法级必填/可选信息
  • 查询参数支持两种输入方式:
    • query 结构化参数(会有 TypedDict 提示)
    • 关键字参数(例如 ecid=...

API 覆盖

SDK 已封装主要高频接口;其余接口可用 client.request(...) 直调。

用户

  • client.user.get_me()GET /user/me
  • client.user.login_by_password(payload)POST /user/auth
  • client.user.login_by_oauth2(payload)POST /user/oauth2
  • client.user.refresh_token(payload)POST /user/refresh
  • client.user.get_openid()GET /user/openid
  • client.user.list_all()GET /user/all
  • client.user.update_permissions(payload)PUT /user/permissions
  • client.user.get_by_id(id)GET /user/:id

玩家

  • client.player.get_info() / search_ecid() / get_user_data() / query_netease()
  • client.player.set_rank_level(payload) / clear_respack_cache()
  • client.player.get_wallet() / list_gaming_tags() / operate_gaming_tag(payload)
  • client.player.get_last_played() / get_stage_record()
  • client.player.get_headicon() / get_skin()(返回 bytes
  • client.player.batch_netease_nicknames(payload)
  • client.player.get_binding() / reset_binding(payload) / update_binding(payload)
  • client.player.update_user_data(nick, payload)
  • client.player.update_password(ecid, payload) / get_password_hash(ecid)

玩家子模块

  • client.player.score.*/player/score*
  • client.player.tasks.*/player/:ecid/tasks*
  • client.player.merchandise.*/player/:ecid/merchandise*
  • client.player.year_summary.*/player/year-summary/*
  • client.player.vote.process_rewards()GET /player/vote

管理与处罚

  • client.admin.*/admin/*
  • client.punish.*/punish/*
  • client.ban.*/ban/*
  • client.permission.*/permission

日志与审计

  • client.log.*/log/*
  • client.audit.*/audit/*

配置与内容

  • client.stage.*(含 stage.logs.*)→ /stage/*
  • client.item.get_commodity()/item/commodity
  • client.cfglang.*/cfglang*
  • client.globalkv.*/globalkv*
  • client.broadcast.*/broadcast*
  • client.pull_config.pull()/pull-config

运营与系统

  • client.order.*/order/*
  • client.count.*/count/*
  • client.servers.*/servers*
  • client.lobby.list()/lobby/list
  • client.easechat.*/easechat/*
  • client.monitor.spam_detector.*/monitor/spam-detector/*
  • client.system.get_health()/health

完整 API 参考

  • API_REFERENCE.md

更新命令(在 easecation-api 根目录执行):

python3 sdk/generate_sdk_api_reference.py

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

ecapi_sdk-0.1.3.tar.gz (16.1 kB view details)

Uploaded Source

Built Distribution

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

ecapi_sdk-0.1.3-py3-none-any.whl (14.6 kB view details)

Uploaded Python 3

File details

Details for the file ecapi_sdk-0.1.3.tar.gz.

File metadata

  • Download URL: ecapi_sdk-0.1.3.tar.gz
  • Upload date:
  • Size: 16.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for ecapi_sdk-0.1.3.tar.gz
Algorithm Hash digest
SHA256 58390ce4ed3586661dd565cea5e897152ff94814ae65ff557eed80562cb96a19
MD5 81612040cddc257f8e6147cca287e91f
BLAKE2b-256 6bac274556f27ba8bf79ac1308c5201f519a6db1b5e03310240d4f736d086acf

See more details on using hashes here.

File details

Details for the file ecapi_sdk-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: ecapi_sdk-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 14.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for ecapi_sdk-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 f8ac8033b8662ec2ef4dc5c060bf6bcf2978a127300afb2bf7e42aed539fb269
MD5 a2a4728c304bfb55e5d1d90db341867d
BLAKE2b-256 6d30ac2eccfe49ef93bfdb199e921d223ad02c7f26e888ea6a9dc9f62a00f466

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