YooKassa Client¶
Основной клиент для работы с API YooKassa.
- class aioyookassa.core.client.YooKassa(api_key: str, shop_id: int | str, timeout: ClientTimeout | None = None, connector: TCPConnector | None = None, proxy: str | None = None, enable_logging: bool = False, logger: Logger | None = None)[source]¶
Bases:
BaseAPIClientYooKassa API Client.
Main client for interacting with YooKassa payment system. Provides access to all available API modules: - payments: Payment operations - payment_methods: Payment method management - invoices: Invoice operations - refunds: Refund operations - receipts: Fiscal receipt operations - payouts: Payout operations - self_employed: Self-employed operations - sbp_banks: SBP participant banks operations - personal_data: Personal data operations - deals: Safe Deal operations - webhooks: Webhook operations (requires OAuth token)
Initialize Base API Client.
- Parameters:
api_key – YooKassa API key
shop_id – YooKassa shop ID
timeout – Custom timeout configuration. Defaults to 30s total, 5s connect, 25s read.
connector – Custom TCP connector. Defaults to optimized connection pooling.
proxy – Proxy URL (e.g., “http://proxy.example.com:8080”)
enable_logging – Enable request/response logging
logger – Custom logger instance. If not provided, uses default logger.
- __init__(api_key: str, shop_id: int | str, timeout: ClientTimeout | None = None, connector: TCPConnector | None = None, proxy: str | None = None, enable_logging: bool = False, logger: Logger | None = None)[source]¶
Initialize Base API Client.
- Parameters:
api_key – YooKassa API key
shop_id – YooKassa shop ID
timeout – Custom timeout configuration. Defaults to 30s total, 5s connect, 25s read.
connector – Custom TCP connector. Defaults to optimized connection pooling.
proxy – Proxy URL (e.g., “http://proxy.example.com:8080”)
enable_logging – Enable request/response logging
logger – Custom logger instance. If not provided, uses default logger.
- async get_me(on_behalf_of: str | None = None) Settings[source]¶
Get shop or gateway settings information.
- Parameters:
on_behalf_of (Optional[str]) – Shop ID for Split payments. Only for those who use Split payments.
- Returns:
Settings object with shop or gateway information.
- Return type:
Settings
- Seealso:
Примеры использования¶
Инициализация клиента¶
from aioyookassa import YooKassa
# С API ключом и ID магазина
client = YooKassa(api_key="your_api_key", shop_id=12345)
# С строковым ID магазина
client = YooKassa(api_key="your_api_key", shop_id="12345")
Использование контекстного менеджера¶
async with YooKassa(api_key="your_key", shop_id=12345) as client:
# Работа с API
payment = await client.payments.create_payment(...)
# Клиент автоматически закроется
Доступ к API модулям¶
client = YooKassa(api_key="your_key", shop_id=12345)
# Модули API
payments = client.payments # Работа с платежами
refunds = client.refunds # Возвраты
receipts = client.receipts # Чеки
invoices = client.invoices # Счета
payment_methods = client.payment_methods # Способы оплаты
payouts = client.payouts # Выплаты
self_employed = client.self_employed # Самозанятые
sbp_banks = client.sbp_banks # Участники СБП
personal_data = client.personal_data # Персональные данные
deals = client.deals # Безопасные сделки
webhooks = client.webhooks # Webhooks (требует OAuth токен)
Получение информации о настройках магазина или шлюза¶
import asyncio
from aioyookassa import YooKassa
async def get_settings():
async with YooKassa(api_key="your_api_key", shop_id=12345) as client:
# Получение настроек магазина
settings = await client.get_me()
print(f"Account ID: {settings.account_id}")
print(f"Status: {settings.status}")
print(f"Test mode: {settings.test}")
if settings.fiscalization:
print(f"Fiscalization enabled: {settings.fiscalization.enabled}")
print(f"Provider: {settings.fiscalization.provider}")
if settings.payment_methods:
print(f"Available payment methods: {settings.payment_methods}")
if settings.itn:
print(f"ITN: {settings.itn}")
# Для Сплитования платежей - получение настроек магазина продавца
seller_settings = await client.get_me(on_behalf_of="seller_shop_id")
print(f"Seller account ID: {seller_settings.account_id}")
asyncio.run(get_settings())