YooKassa Python SDK
raw JSON → 3.10.1 verified Mon Apr 27 auth: no python
YooKassa (formerly Yandex.Checkout) Python SDK for payment acceptance via API. Current version 3.10.1, active development with monthly releases.
pip install yookassa Common errors
error yookassa.exceptions.AuthenticationError: 401 Unauthorized ↓
cause Missing or incorrect account_id or secret_key in Configuration.
fix
Verify environment variables YOOKASSA_SHOP_ID and YOOKASSA_SECRET_KEY are set correctly.
error yookassa.exceptions.BadRequestError: 400 - invalid request ↓
cause Missing required fields in payment request (e.g., amount or confirmation).
fix
Ensure 'amount' and 'confirmation' dictionaries are provided in the request body.
error ModuleNotFoundError: No module named 'yookassa' ↓
cause Library not installed or installed in wrong environment.
fix
Run 'pip install yookassa' in the correct Python environment.
error TypeError: can only concatenate str (not 'Payment') to str ↓
cause Attempting to concatenate payment object directly with string.
fix
Use f-string or str(payment.id) when printing payment ID.
Warnings
breaking Version 3.0.0 changed authentication from YooKassaClient to Configuration.account_id / secret_key ↓
fix Use Configuration.account_id and Configuration.secret_key instead of YooKassaClient.
breaking Version 3.0.0 removed synchronous client; all methods are synchronous but now require explicit Configuration ↓
fix Update imports and initialization to use Configuration.
gotcha Payment.id is a string, not an integer. Concatenation without str() will cause TypeError. ↓
fix Always treat payment.id as string; use str() if needed.
gotcha API keys must be set before any SDK calls; otherwise AuthenticationError is raised. ↓
fix Set Configuration.account_id and Configuration.secret_key at the top of your script.
Imports
- Configuration wrong
from yookassa.configuration import Configurationcorrectfrom yookassa import Configuration
Quickstart
import os
from yookassa import Configuration, Payment
Configuration.account_id = os.environ.get('YOOKASSA_SHOP_ID', '')
Configuration.secret_key = os.environ.get('YOOKASSA_SECRET_KEY', '')
payment = Payment.create({
'amount': {'value': '100.00', 'currency': 'RUB'},
'confirmation': {'type': 'redirect', 'return_url': 'https://example.com'},
'capture': True,
'description': 'Test payment'
})
print(payment.id)