Skip to main content

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

Project description

welldungeon

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

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

Установка

pip install welldungeon

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

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.2.tar.gz (11.2 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.2-py3-none-any.whl (12.3 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for welldungeon-0.1.2.tar.gz
Algorithm Hash digest
SHA256 64c1c7c6fff6205f7c219ee11c084e62c34b231b43633e6cc1c8f2395d652174
MD5 69a6995014eeea9e194d895a2733abbd
BLAKE2b-256 bd1e518b3c2eea74268f01aa1ec4992c7496b83907a7c9d6a5e73df91f2920c1

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for welldungeon-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 474950855e4312dbe23eaa8fa571e9351a621900ab8e3b5841e3ee86a316cd12
MD5 72d4f7ff3241aa156ed412f3f44ef000
BLAKE2b-256 f387a7caa9f87aa24d64df2dd022aa94b479ddbf28ba2c3e05896086cf0bf43e

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