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

Релиз на PyPI

  1. Поднимите версию в pyproject.toml (например 0.1.1).
  2. Закоммитьте и создайте тег:
    git tag v0.1.1
    git push origin main --tags
    
  3. GitLab CI соберёт пакет и опубликует его на PyPI.

Для автопубликации в GitLab нужна CI-переменная PYPI_TOKEN (masked, protected): Settings → CI/CD → Variables — значение API-токена PyPI.

Тег должен совпадать с форматом vX.Y.Z (например v0.1.1).

Лицензия

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.1.tar.gz (11.9 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.1-py3-none-any.whl (12.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: welldungeon-0.1.1.tar.gz
  • Upload date:
  • Size: 11.9 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.1.tar.gz
Algorithm Hash digest
SHA256 cba59748e7dfe0df59f74e4f318640cf0bbb2c30a07f482f507ec93419d24cd5
MD5 af19912e1762a8b0de203a1a161e0a1e
BLAKE2b-256 d8a212c3a4b5be0b460e1964c98f444d4e34e8f55fc9b8162b8fe77fe104f896

See more details on using hashes here.

File details

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

File metadata

  • Download URL: welldungeon-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 12.7 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 cf4eb105db88243b78f75b31bf407db2c727d7978fe27ed38d35c6704b0ad217
MD5 9f6c3fdb8f7982349595d824919346b9
BLAKE2b-256 efc3fcc518e8fba4791ef1f8b3a171dcc707537140bf29737a6ab8d50150e01e

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