使用前需先在 YooMoney 注册应用拿到 CLIENT_ID、REDIRECT_URI 和 CLIENT_SECRET 并完成 OAuth 授权换取 token;异步客户端要用 async with 管理,否则底层连接池不会正确关闭;项目为非官方库且采用 GPL-3.0 许可,商用前需确认合规
yoomoney-api
AlekseyKorshukGPL-3.0更新放缓YooMoney(原 Yandex.Money)支付 API 的 Python 客户端,同时支持同步和异步调用,用 Pydantic 模型保证类型安全,方便在 Python 项目里接入俄罗斯钱包支付。
Python client for the YooMoney (ex-Yandex.Money) API — sync & async, Pydantic models, type-safe
pip install yoomoney --upgradeREADME 未说明,纯 Python 网络客户端,无 GPU 或特殊硬件要求
非官方 YooMoney 钱包 API 的 Python 封装,同步异步双客户端,返回 Pydantic 类型安全模型
YooMoney(原 Yandex.Money)支付 API 的 Python 客户端,同时支持同步和异步调用,用 Pydantic 模型保证类型安全,方便在 Python 项目里接入俄罗斯钱包支付。
核心能力
- 同时提供同步 Client 与异步 AsyncClient 两套客户端
- 用 Pydantic 模型返回账户、操作等结构化数据
- 通过 Authorize 走 OAuth 流程获取访问令牌
- 支持分页拉取操作历史并按时间倒序返回
- 可生成可嵌入网站的 Quickpay 支付表单链接
容易踩的坑
- v2.0.0v2.0.0 — Full rewrite with async support, Pydantic models & modern tooling最新正式版2026-02-13 · 2026-02-13 16:23 UTC
YooMoney API v2.0.0
Full library rewrite with async support, Pydantic models, and modern Python tooling.
Highlights
- Async client — New
AsyncClientwith full async/await API parity. Use it as anasync withcontext manager for proper connection handling. - Pydantic v2 models — All data classes (
Account,Operation,OperationDetails,History, etc.) are now PydanticBaseModelsubclasses with proper type annotations and validation. - httpx instead of requests — Switched from
requeststohttpxfor both synchronous and asynchronous HTTP, with connection pooling and proper resource management. - Transport layer — New internal
SyncTransport/AsyncTransportabstraction handles authentication, base URL, and HTTP calls cleanly. - Centralized error handling — All API error codes are mapped in a single
ERROR_MAPdict with a unifiedraise_for_error()helper, removing duplicated error-checking logic.
Breaking Changes
- Minimum Python version is now 3.10 (was 3.x).
- Dependency change:
requestsreplaced byhttpx>=0.27andpydantic>=2.0. - Model instances are now Pydantic models — attribute access is the same, but serialization methods (
.model_dump(),.model_dump_json()) are now available. ClientandAsyncClientnow support context managers (with/async with) for proper cleanup.
New Features
AsyncClient— fully asynchronous client with the same interface asClientClientsupportswithstatement (context manager)- Pydantic field validators auto-parse ISO datetime strings from API responses
Quickpaynow properly URL-encodes parameters viahttpx
Build & Tooling
- Migrated from
setup.pytopyproject.tomlwithhatchlingbuild backend - Added
.gitignoreand.python-version - New CI lint workflow with ruff (format + lint) and mypy (type checking)
- Updated PyPI publish workflow to use
uvandactions/checkout@v4 - Comprehensive ruff and mypy configuration in
pyproject.toml
Documentation
- Completely rewritten
README.rstwith structured table of contents, feature table, PyPI badges, and async examples - Added Russian translation (
README_RU.rst) - Moved tutorial GIF to
docs/assets/ - All examples updated with modern Python style (f-strings, proper formatting)
Installation
```bash pip install yoomoney==2.0.0 --upgrade ```
Or with uv:
```bash uv add yoomoney ```
- Async client — New
- v0.1.22025-01-29 · 2025-01-29 12:01 UTC
查看更新说明
What's Changed
- add "raise" to IllegalParamTillDate(). Update history.py by @VL1507 in https://github.com/AlekseyKorshuk/yoomoney-api/pull/23
New Contributors
- @VL1507 made their first contribution in https://github.com/AlekseyKorshuk/yoomoney-api/pull/23
Full Changelog: https://github.com/AlekseyKorshuk/yoomoney-api/compare/v0.1.1...v0.1.2
- v0.1.12024-07-13 · 2024-07-13 11:23 UTC
查看更新说明
What's Changed
Full Changelog: https://github.com/AlekseyKorshuk/yoomoney-api/compare/v0.1.0...v0.1.1
- v0.1.0YooMoney API2021-10-25 · 2021-10-25 13:53 UTC
查看更新说明
What's Changed
Full Changelog: https://github.com/AlekseyKorshuk/yoomoney-api/commits/v0.1.0
用户点评
登录用户的真实使用记录,可按版本和硬件筛选还没有人点评。第一个说出真实体验的人最有价值。
YooMoney API
Unofficial Python library for the YooMoney API
|pypi| |python| |license|
.. |pypi| image:: https://img.shields.io/pypi/v/yoomoney?color=blue&label=PyPI :target: https://pypi.org/project/yoomoney/ .. |python| image:: https://img.shields.io/pypi/pyversions/yoomoney :target: https://pypi.org/project/yoomoney/ .. |license| image:: https://img.shields.io/github/license/AlekseyKorshuk/yoomoney-api :target: https://github.com/AlekseyKorshuk/yoomoney-api/blob/master/LICENSE
🇷🇺 Версия на русском языке <README_RU.rst>_
.. contents:: Table of Contents :depth: 2 :local: :backlinks: none
Introduction
This library provides a convenient Python wrapper around the
YooMoney Wallet API <https://yoomoney.ru/docs/wallet>__.
Both synchronous (Client) and asynchronous (AsyncClient) clients
are included out of the box.
Features
+-----------------------------+---------------------------------------------------------------+
| Method | Description |
+=============================+===============================================================+
| Access token_ | Obtain an OAuth access token. |
+-----------------------------+---------------------------------------------------------------+
| Account information_ | Retrieve the current status of the user account. |
+-----------------------------+---------------------------------------------------------------+
| Operation history_ | View the full or partial history of operations (paginated, |
| | reverse-chronological order). |
+-----------------------------+---------------------------------------------------------------+
| Operation details_ | Get detailed information about a single operation. |
+-----------------------------+---------------------------------------------------------------+
| Quickpay forms_ | Generate a payment form that can be embedded into any website |
| | or blog. |
+-----------------------------+---------------------------------------------------------------+
Installation
From PyPI (recommended):
.. code-block:: shell
pip install yoomoney --upgrade
Or with uv <https://docs.astral.sh/uv/>_:
.. code-block:: shell
uv add yoomoney
From source:
.. code-block:: shell
git clone https://github.com/AlekseyKorshuk/yoomoney-api --recursive cd yoomoney-api uv sync
Quick start
Access token
First of all you need to receive an access token.
.. image:: docs/assets/token.gif :alt: Getting an access token
- Log in to your YooMoney wallet. If you do not have one,
create it <https://yoomoney.ru/reg>_. - Go to the
App registration <https://yoomoney.ru/myservices/new>_ page. - Set the application parameters. Save CLIENT_ID and REDIRECT_URI for the next steps.
- Click Confirm.
- Replace the placeholders below with your real credentials, choose the required scopes, and run the code.
- Follow the on-screen instructions.
.. code-block:: python
from yoomoney import Authorize
Authorize( client_id="YOUR_CLIENT_ID", redirect_uri="YOUR_REDIRECT_URI", client_secret="YOUR_CLIENT_SECRET", scope=[ "account-info", "operation-history", "operation-details", "incoming-transfers", "payment-p2p", "payment-shop", ], )
You are done with the most difficult part!
Account information
Replace YOUR_TOKEN and run:
.. code-block:: python
from yoomoney import Client
client = Client("YOUR_TOKEN") user = client.account_info()
print("Account number:", user.account) print("Account balance:", user.balance) print("Currency (ISO 4217):", user.currency) print("Account status:", user.account_status) print("Account type:", user.account_type)
print("Extended balance information:") for key, value in vars(user.balance_details).items(): print(f" {key}: {value}")
print("Linked bank cards:") if user.cards_linked: for card in user.cards_linked: print(f" {card.pan_fragment} — {card.type}") else: print(" No cards linked")
.. code-block:: text
Account number: 410019014512803 Account balance: 999999999999.99 Currency (ISO 4217): 643 Account status: identified Account type: personal Extended balance information: total: 999999999999.99 available: 999999999999.99 deposition_pending: None blocked: None debt: None hold: None Linked bank cards: No cards linked
Operation history
Replace YOUR_TOKEN and run:
.. code-block:: python
from yoomoney import Client
client = Client("YOUR_TOKEN") history = client.operation_history()
print("List of operations:") print("Next page starts with:", history.next_record)
for op in history.operations: print() print(f"Operation: {op.operation_id}") print(f" Status : {op.status}") print(f" Datetime : {op.datetime}") print(f" Title : {op.title}") print(f" Pattern id : {op.pattern_id}") print(f" Direction : {op.direction}") print(f" Amount : {op.amount}") print(f" Label : {op.label}") print(f" Type : {op.type}")
.. code-block:: text
List of operations: Next page starts with: None
Operation: 670278348725002105 Status : success Datetime : 2021-10-10 10:10:10 Title : Пополнение с карты ****4487 Pattern id : None Direction : in Amount : 100500.0 Label : 3784030974 Type : deposition
Operation: 670244335488002313 Status : success Datetime : 2021-10-10 10:10:10 Title : Перевод от 410019014512803 Pattern id : p2p Direction : in Amount : 100500.0 Label : 7920963969 Type : incoming-transfer
Operation details
Replace YOUR_TOKEN and OPERATION_ID (e.g. 670244335488002312) and run:
.. code-block:: python
from yoomoney import Client
client = Client("YOUR_TOKEN") details = client.operation_details(operation_id="OPERATION_ID")
for key, value in vars(details).items(): if not key.startswith("_"): print(f"{key:20s} : {str(value).replace(chr(10), ' ')}")
.. code-block:: text
operation_id : 670244335488002312 status : success pattern_id : p2p direction : in amount : 100500.0 amount_due : None fee : None datetime : 2021-10-10 10:10:10 title : Перевод от 410019014512803 sender : 410019014512803 recipient : None recipient_type : None message : Justtext comment : None codepro : False protection_code : None expires : None answer_datetime : None label : 7920963969 details : Justtext type : incoming-transfer digital_goods : None
Quickpay forms
.. code-block:: python
from yoomoney import Quickpay
quickpay = Quickpay( receiver="410019014512803", quickpay_form="shop", targets="Sponsor this project", paymentType="SB", sum=150, )
print(quickpay.base_url) print(quickpay.redirected_url)
.. code-block:: text
https://yoomoney.ru/quickpay/confirm.xml?receiver=410019014512803&quickpay-form=shop&targets=Sponsor%20this%20project&paymentType=SB&sum=150 https://yoomoney.ru/transfer/quickpay?requestId=343532353937313933395f66326561316639656131626539326632616434376662373665613831373636393537613336383639
Async client
An asynchronous client (AsyncClient) exposes the same API as the synchronous
Client, but every method is a coroutine. Use it as an async with context
manager so the underlying connection pool is closed properly.
Async account information
.. code-block:: python
import asyncio from yoomoney import AsyncClient
async def main(): async with AsyncClient("YOUR_TOKEN") as client: user = await client.account_info()
print("Account number:", user.account)
print("Account balance:", user.balance)
print("Currency (ISO 4217):", user.currency)
print("Account status:", user.account_status)
print("Account type:", user.account_type)
print("Extended balance information:")
for key, value in vars(user.balance_details).items():
print(f" {key}: {value}")
print("Linked bank cards:")
if user.cards_linked:
for card in user.cards_linked:
print(f" {card.pan_fragment} — {card.type}")
else:
print(" No cards linked")
asyncio.run(main())
Async operation history
.. code-block:: python
import asyncio from yoomoney import AsyncClient
async def main(): async with AsyncClient("YOUR_TOKEN") as client: history = await client.operation_history()
print("List of operations:")
print("Next page starts with:", history.next_record)
for op in history.operations:
print()
print(f"Operation: {op.operation_id}")
print(f" Status : {op.status}")
print(f" Datetime : {op.datetime}")
print(f" Title : {op.title}")
print(f" Pattern id : {op.pattern_id}")
print(f" Direction : {op.direction}")
print(f" Amount : {op.amount}")
print(f" Label : {op.label}")
print(f" Type : {op.type}")
asyncio.run(main())
Async operation details
.. code-block:: python
import asyncio from yoomoney import AsyncClient
async def main(): async with AsyncClient("YOUR_TOKEN") as client: details = await client.operation_details(operation_id="OPERATION_ID")
for key, value in vars(details).items():
if not key.startswith("_"):
print(f"{key:20s} : {str(value).replace(chr(10), ' ')}")
asyncio.run(main())
License
This project is licensed under the
GPL-3.0 <https://github.com/AlekseyKorshuk/yoomoney-api/blob/master/LICENSE>_.