Skip to main content

Python SDK для API игры «Подземелья Колодца» (sync + async)

Project description

wd-api

Python SDK для API игры «Подземелья Колодца» с поддержкой синхронного и асинхронного режимов.

Документация API: https://welldungeon.online/gtdoc/api

Установка

pip install welldungeon

Из GitLab (если нужна версия из репозитория):

pip install git+https://gitlab.com/Racoonchik/wd-api.git

Для разработки:

pip install -e ".[dev]"

Быстрый старт

Токен можно получить на странице https://welldungeon.online/?act=tokens

Синхронный клиент

from welldungeon import Client

with Client(token="wd1_live_...") as client:
    info = client.get_character_info()
    print(f"{info.race}, уровень {info.level}")

    inventory = client.get_inventory()
    print(inventory.items)

Асинхронный клиент

import asyncio

from welldungeon import AsyncClient

async def main():
    async with AsyncClient(token="wd1_live_...") as client:
        token_info = await client.token_info()
        items = await client.lib_items()
        print(token_info.rights, len(items))

asyncio.run(main())

Переменная окружения

export WELL_DUNGEON_TOKEN=wd1_live_...
from welldungeon import Client

client = Client()  # токен из WELL_DUNGEON_TOKEN

Методы

Метод Python API Право токена
get_character_info() GetCharacterInfo character_info
get_inventory() GetInventory inventory_read
transfer_item_to_player(player_id, item_id, count=1) TransferItemToPlayer transfer_player_to_player
apply_social_effect_to_player(player_id, effect_type) ApplySocialEffectToPlayer social_effects_player_to_player
lib_items() LibItems
token_info() TokenInfo
get_log(start=0, limit=100) Log

Кэш справочника предметов

from welldungeon import Client, ItemsCache

with Client(token="...") as client:
    cache = ItemsCache.fetch_and_save(client, "items_cache.json")
    print(cache.get_title(13322))  # Золото

Обработка ошибок

from welldungeon import Client, InvalidTokenError, ConditionsNotMetError

try:
    client.token_info()
except InvalidTokenError as e:
    print(e.code, e.message)

Ограничения API

  • Не более 3 запросов в секунду с одного IP (в клиенте есть встроенный rate limiter).
  • Токен можно привязать к белому списку IP-адресов.
  • Храните токен в секрете.

Разработка

ruff check src tests
pytest -m "not integration"

Интеграционные тесты (нужен реальный токен):

WELL_DUNGEON_TOKEN=wd1_live_... pytest -m integration

Лицензия

MIT

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

welldungeon-0.1.0.tar.gz (11.6 kB view details)

Uploaded Source

Built Distribution

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

welldungeon-0.1.0-py3-none-any.whl (12.5 kB view details)

Uploaded Python 3

File details

Details for the file welldungeon-0.1.0.tar.gz.

File metadata

  • Download URL: welldungeon-0.1.0.tar.gz
  • Upload date:
  • Size: 11.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.13

File hashes

Hashes for welldungeon-0.1.0.tar.gz
Algorithm Hash digest
SHA256 b4c0d9143067b4b45bcc3a375bafbf16b7e67535fa516d1cb94e396139a630d4
MD5 d843081b35461d6381b7d8978469b0e1
BLAKE2b-256 7839a2415afcb766df55361908639b7b5e0b2875a7a383a6fa457dda7124593a

See more details on using hashes here.

File details

Details for the file welldungeon-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: welldungeon-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 12.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.13

File hashes

Hashes for welldungeon-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d9dbf5a0506bf4b20e30ea6053112fb46e1e6e2694a389c7d02d34f9917a8d98
MD5 4483428323ffb1ba3ef8f5551cef6fb1
BLAKE2b-256 55b4f766511b7bd85f8697f4795cfc6e942d03503b687b04a6bd8fa10d5af3ab

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