Skip to main content

Python SDK for the JiETNG maimai DX (舞萌DX) score management API.

Project description

jietng — Python SDK

pip install jietng — Python 客户端,封装 JiETNG 舞萌DX 查分器的 HTTP API。

支持同步 / 异步两套客户端、覆盖全部 v2 端点(用户 / 权限 / 同步 / 搜歌 / 成绩图 / 导出 …)、类型注解齐全。

安装

pip install jietng

需要 Python ≥ 3.8、httpx ≥ 0.25。

获取 Token

JiETNG API 通过 Bearer Token 鉴权。申请方式见 https://jietng.matsuk1.com/developer-api —— 发邮件到 matsuk1@proton.me 索取。

快速开始

同步

from jietng import jietngClient

with jietngClient(token="your_token") as client:
    users = client.users.list()
    print(users["count"], "registered users")

    # 取 B50 成绩图(返回 PNG bytes)
    png = client.images.records("U1234567890", command="b50")
    with open("b50.png", "wb") as f:
        f.write(png)

    # 触发后台同步并等待完成
    task = client.users.trigger_sync_and_wait("U1234567890", timeout=300)
    print("sync status:", task["status"])

    # 导出成绩为 JSON / XML,文件名由服务端推荐(含玩家名 + 时间戳)
    path = client.exports.save("U1234567890", fmt="json")
    print("exported to", path)

异步

import asyncio
from jietng import AsyncjietngClient

async def main():
    async with AsyncjietngClient(token="your_token") as client:
        print(await client.songs.search("PANDORA", ver="jp", max_results=3))
        task = await client.users.trigger_sync_and_wait("U1234567890", timeout=300)
        print("sync status:", task["status"])

        png = await client.images.plate("U1234567890", title="真神")
        with open("plate.png", "wb") as f:
            f.write(png)

asyncio.run(main())

资源总览

命名空间 主要方法
client.users list / get / create / delete / trigger_sync / trigger_sync_and_wait / bind / update_bind / get_rebind_url / get_settings_url
client.permissions request / list_requests / accept / reject / revoke / revoke_self
client.songs search / info
client.tasks get / wait
client.versions list
client.dxdata get
client.images user_song / records / plate / achievement
client.exports download / save

所有方法的形参 / 返回结构与 JiETNG API 文档 一一对应。

错误处理

所有 HTTP 非 2xx 状态都会抛 APIError 子类。可以按需 catch 具体类型:

from jietng import jietngClient, NotFoundError, PermissionDeniedError, RateLimitedError, QueueFullError

try:
    png = client.images.records("U_unknown", command="b50")
except NotFoundError:
    print("user has no records yet")
except PermissionDeniedError:
    print("your token doesn't have access to this user")
except RateLimitedError:
    print("slow down")
except QueueFullError:
    print("server task queue is full, retry later")

完整异常层级:

jietngError                  # 基类
└─ APIError                  # 任意 HTTP 非 2xx
   ├─ ValidationError        # 400
   ├─ AuthenticationError    # 401
   ├─ PermissionDeniedError  # 403
   ├─ NotFoundError          # 404
   ├─ RateLimitedError       # 429
   ├─ ServerError            # 500
   └─ QueueFullError         # 503

每个异常实例都带 status_code / error / message / payload 字段,方便排查。

自定义

client = jietngClient(
    token="your_token",
    base_url="https://your-self-hosted.example.com/api/v2",   # 自托管时
    timeout=60.0,
    extra_headers={"X-App-Name": "MyBot"},
)

许可

MIT。代码:https://github.com/Matsuk1/JiETNG/tree/main/client

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

jietng-0.1.1.tar.gz (12.1 kB view details)

Uploaded Source

Built Distribution

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

jietng-0.1.1-py3-none-any.whl (13.4 kB view details)

Uploaded Python 3

File details

Details for the file jietng-0.1.1.tar.gz.

File metadata

  • Download URL: jietng-0.1.1.tar.gz
  • Upload date:
  • Size: 12.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for jietng-0.1.1.tar.gz
Algorithm Hash digest
SHA256 be7783e67f3eb985f3ebd4cb96d7c6978c1d4ebc5b607133ceb46a1745e27dc6
MD5 b3491e567bc92c0117779b74ba38fab1
BLAKE2b-256 a85c3b01ed7479919101ebe382c585515e8efc7ea65c2eff78de98386b5933f9

See more details on using hashes here.

File details

Details for the file jietng-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: jietng-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 13.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for jietng-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 da61aea4cf9a319fc9c5b9ecc39612e0e70685d05a5bd5e0e531f57144cb00c0
MD5 191037423795f2d54a8d228f017b13c9
BLAKE2b-256 f64e1dd5a832248cfdc7cd1d034ab3a8be3816ffb2ed5a07eff7d5c3665babf1

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