Skip to main content

Typed Python client for Yandex Wiki API (sync + async)

Project description

ya-wiki-api

Типизированный Python-клиент для Yandex Wiki API. Синхронный и асинхронный. Все 21 эндпоинт покрыты и протестированы на реальном API.

Установка

pip install ya-wiki-api

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

from ya_wiki_api import WikiClient

with WikiClient(token="your-oauth-token", org_id="your-org-id") as client:
    # Страницы
    page = client.pages.create(
        page_type="wysiwyg",
        title="Моя страница",
        slug="path/to/page",
        content="Привет!",
    )
    page = client.pages.get(slug="path/to/page")
    page = client.pages.get_by_id(page.id, fields="attributes,content")
    client.pages.update(page.id, content="Обновлённый текст")
    client.pages.append_content(page.id, content="\nЕщё текст", location="bottom")

    # Динамические таблицы
    grid = client.grids.create(title="Моя таблица", page_id=page.id)
    client.grids.columns.add(grid.id, columns=[
        {"slug": "name", "title": "Имя", "type": "string", "required": False},
        {"slug": "score", "title": "Баллы", "type": "number", "required": False},
    ])
    client.grids.rows.add(grid.id, rows=[
        {"name": "Алиса", "score": 95},
        {"name": "Боб", "score": 87},
    ])
    client.grids.cells.update(grid.id, cells=[
        {"row_id": 1, "column_slug": "score", "value": 100},
    ])

    # Очистка
    client.grids.delete(grid.id)
    client.pages.delete(page.id)

Async

from ya_wiki_api import AsyncWikiClient

async with AsyncWikiClient(token="...", org_id="...") as client:
    page = await client.pages.get(slug="my/page")
    grid = await client.grids.get("grid-uuid")

Аутентификация

OAuth 2.0 (Яндекс 360 для бизнеса):

client = WikiClient(token="oauth-token", org_id="org-id")

IAM-токен (Yandex Cloud):

client = WikiClient(token="iam-token", cloud_org_id="cloud-org-id", is_iam=True)

Получение OAuth-токена:

  1. Создайте приложение на https://oauth.yandex.ru/
  2. Выберите «Для доступа к API или отладки»
  3. Добавьте права: wiki:write (полный доступ) или wiki:read (только чтение)
  4. Получите токен: https://oauth.yandex.ru/authorize?response_type=token&client_id=<ClientID>

Покрытие API

Страницы (client.pages)

Метод Эндпоинт
get(slug) GET /v1/pages?slug=...
get_by_id(id) GET /v1/pages/{id}
create(...) POST /v1/pages
update(id, ...) POST /v1/pages/{id}
delete(id) DELETE /v1/pages/{id}
clone(id, target) POST /v1/pages/{id}/clone
append_content(id, content) POST /v1/pages/{id}/append-content
get_grids(id) GET /v1/pages/{id}/grids
get_resources(id) GET /v1/pages/{id}/resources

Таблицы (client.grids)

Метод Эндпоинт
get(id) GET /v1/grids/{id}
create(...) POST /v1/grids
update(id, ...) POST /v1/grids/{id}
delete(id) DELETE /v1/grids/{id}
clone(id, target) POST /v1/grids/{id}/clone
rows.add(id, rows) POST /v1/grids/{id}/rows
rows.delete(id, row_ids) DELETE /v1/grids/{id}/rows
rows.move(id, row_id) POST /v1/grids/{id}/rows/move
columns.add(id, columns) POST /v1/grids/{id}/columns
columns.delete(id, slugs) DELETE /v1/grids/{id}/columns
columns.move(id, slug) POST /v1/grids/{id}/columns/move
cells.update(id, cells) POST /v1/grids/{id}/cells

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

from ya_wiki_api import WikiAPIError

try:
    client.pages.get(slug="nonexistent")
except WikiAPIError as e:
    print(e.status_code)  # 404
    print(e.detail)       # {"error_code": "...", "message": "..."}

Лицензия

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

ya_wiki_api-0.2.0.tar.gz (8.5 kB view details)

Uploaded Source

Built Distribution

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

ya_wiki_api-0.2.0-py3-none-any.whl (10.9 kB view details)

Uploaded Python 3

File details

Details for the file ya_wiki_api-0.2.0.tar.gz.

File metadata

  • Download URL: ya_wiki_api-0.2.0.tar.gz
  • Upload date:
  • Size: 8.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.13

File hashes

Hashes for ya_wiki_api-0.2.0.tar.gz
Algorithm Hash digest
SHA256 764c25a73a981393b783d3cd1f4d49f4f937688cca811e89483e47815f71ce93
MD5 345f793a16177045d3f5bdb9fa52aba7
BLAKE2b-256 b88c1fb4a47ef46e4828dca63a209f45665013edec6a5de8a6e9429255ccd13a

See more details on using hashes here.

File details

Details for the file ya_wiki_api-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for ya_wiki_api-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 90efeef448c2516e129216a3a93b698116d3b1d1b4e3a30a59c05e798bcb1152
MD5 96c0f4ca86b13df42bc27089d5d57af0
BLAKE2b-256 2354b49ce96f81983d961b6a777cec4832ae1b45291017b1904b7f966179b400

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