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.1.0.tar.gz (8.3 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.1.0-py3-none-any.whl (10.7 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for ya_wiki_api-0.1.0.tar.gz
Algorithm Hash digest
SHA256 5b181108ba6021a43ba66d24015222133ffd3a595043488cbbbc3f9bfb5919eb
MD5 b7276533bbdce4236bc1f033732486fc
BLAKE2b-256 393ce1a5b36446379a44dafa72bfd41645e5ad65981997c01c210f2e64548e70

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ya_wiki_api-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8fbf16103876932d38709dd4aa6518ed1c818e0e7b970e7b4cabb2efc64edfa9
MD5 f0e208fc6a18518b81e369879d03af82
BLAKE2b-256 c8ee32a6d6604ce164dc27e84bed9855e73fb7f41953cbc5a62d6df9e8ebce33

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