QPay Integration made easy (async & sync, typed schemas, auto token refresh)
Project description
qpay-client
qpay-client is a production-ready Python client for the QPay v2 payment API — Mongolia's leading payment provider.
Built and used in production systems, it supports both async and sync clients, Pydantic v2-validated schemas, automatic
token management, retry logic with exponential backoff, and typed wrappers for all common endpoints.
Documentation: qpay-client.readthedocs.io
QPay developer portal: developer.qpay.mn
Features
- Both
AsyncQPayClientandQPayClient(sync) supported - Authentication and token refresh managed automatically
- Request/response validation via Pydantic v2 schemas
- Retry logic for network errors and transient server failures
- Configurable
payment_checkpolling with exponential backoff withandasync withcontext manager support- Structured
QPayErrorexceptions with error codes and descriptions
Installation
Using pip:
pip install qpay-client
Using uv:
uv add qpay-client
Using poetry:
poetry add qpay-client
Quickstart
Async client
from decimal import Decimal
from qpay_client.v2 import AsyncQPayClient, QPaySettings
from qpay_client.v2.schemas import InvoiceCreateSimpleRequest
settings = QPaySettings.sandbox()
async def main():
async with AsyncQPayClient(settings=settings) as client:
invoice = await client.invoice_create(
InvoiceCreateSimpleRequest(
sender_invoice_no="ORDER-1001",
invoice_receiver_code="terminal",
invoice_description="Test invoice",
amount=Decimal("1500"),
callback_url="https://example.com/qpay/callback?payment_id=ORDER-1001",
)
)
print(invoice.invoice_id)
print(invoice.qPay_shortUrl)
Sync client
from decimal import Decimal
from qpay_client.v2 import QPayClient, QPaySettings
from qpay_client.v2.schemas import InvoiceCreateSimpleRequest
settings = QPaySettings.sandbox()
with QPayClient(settings=settings) as client:
invoice = client.invoice_create(
InvoiceCreateSimpleRequest(
sender_invoice_no="ORDER-1002",
invoice_receiver_code="terminal",
invoice_description="Sync test invoice",
amount=Decimal("2500"),
callback_url="https://example.com/qpay/callback?payment_id=ORDER-1002",
)
)
print(invoice.invoice_id)
Configuration
Sandbox
from qpay_client.v2 import QPaySettings
settings = QPaySettings.sandbox()
Production
from qpay_client.v2 import QPaySettings
settings = QPaySettings.production(
username="your-merchant-username",
password="your-merchant-password",
invoice_code="YOUR_INVOICE_CODE",
)
Retry and delay settings
settings = QPaySettings.sandbox(
client_retries=2,
client_delay=0.25,
client_jitter=0.1,
payment_check_retries=8,
payment_check_delay=0.5,
payment_check_jitter=0.2,
)
Checking a payment
from qpay_client.v2.enums import ObjectType
from qpay_client.v2.schemas import Offset, PaymentCheckRequest
check_request = PaymentCheckRequest(
object_type=ObjectType.invoice,
object_id="YOUR_INVOICE_ID",
offset=Offset(page_number=1, page_limit=100),
)
result = await client.payment_check(check_request)
if result.count > 0:
print("Payment found")
FastAPI callback flow
examples/quickstart.py contains a working async example with a QPay callback endpoint.
The general pattern is:
- Create an invoice
- Store the
invoice_idin your database - On QPay callback, call
payment_checkto verify the payment - Return
"SUCCESS"with HTTP 200
To run the example:
fastapi dev examples/quickstart.py
Returning HTTP 200 with body "SUCCESS" from your callback endpoint is required by QPay.
Import paths
Import clients and settings from qpay_client.v2:
from qpay_client.v2 import AsyncQPayClient, QPayClient, QPaySettings, QPayError
Import schemas and enums from their respective modules:
from qpay_client.v2.enums import ObjectType
from qpay_client.v2.schemas import InvoiceCreateSimpleRequest, Offset, PaymentCheckRequest
Supported endpoints
Authentication
tokenrefresh
Invoice
invoice_getinvoice_createinvoice_cancel
Payment
payment_getpayment_listpayment_checkpayment_cancelpayment_refund
Ebarimt
ebarimt_getebarimt_create
Subscription
subscription_getsubscription_cancel
Notes
- Never call
QPaySettings()directly — usesandbox()orproduction()factory methods. - All public endpoint methods check and refresh authentication automatically; no need to manage tokens manually.
payment_checkpolls with exponential backoff — tune retry/delay settings to your use case.- Do not commit production credentials to source control.
License
MIT License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file qpay_client-2.0.3.tar.gz.
File metadata
- Download URL: qpay_client-2.0.3.tar.gz
- Upload date:
- Size: 18.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d222a476fcfe6ffc7e2000956b03f03c0b26af55f4915f09c926fbe298cc858b
|
|
| MD5 |
a84f662e5d714f472cb556fe6fdf064b
|
|
| BLAKE2b-256 |
796158012e140551c4d7d1dd55c6c3fe1dde8fe7c13055e17d98512b0e21f45b
|
Provenance
The following attestation bundles were made for qpay_client-2.0.3.tar.gz:
Publisher:
release.yml on Amraa1/qpay_client
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
qpay_client-2.0.3.tar.gz -
Subject digest:
d222a476fcfe6ffc7e2000956b03f03c0b26af55f4915f09c926fbe298cc858b - Sigstore transparency entry: 1761847124
- Sigstore integration time:
-
Permalink:
Amraa1/qpay_client@698bd463fa3874e0c52b688db514d7bc1a7ac753 -
Branch / Tag:
refs/tags/v2.0.3 - Owner: https://github.com/Amraa1
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@698bd463fa3874e0c52b688db514d7bc1a7ac753 -
Trigger Event:
release
-
Statement type:
File details
Details for the file qpay_client-2.0.3-py3-none-any.whl.
File metadata
- Download URL: qpay_client-2.0.3-py3-none-any.whl
- Upload date:
- Size: 25.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1e4e0b3ae017038ef2662cb045e33c8af509c94d18ad5a4039f4cfbe8a2ad64e
|
|
| MD5 |
c24c4c0543e3820e093bf56bbc923096
|
|
| BLAKE2b-256 |
fc3d1d9df3a5c6828532af5a3976dae5c2814aa9afbb867533c5c5b4606836ac
|
Provenance
The following attestation bundles were made for qpay_client-2.0.3-py3-none-any.whl:
Publisher:
release.yml on Amraa1/qpay_client
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
qpay_client-2.0.3-py3-none-any.whl -
Subject digest:
1e4e0b3ae017038ef2662cb045e33c8af509c94d18ad5a4039f4cfbe8a2ad64e - Sigstore transparency entry: 1761847318
- Sigstore integration time:
-
Permalink:
Amraa1/qpay_client@698bd463fa3874e0c52b688db514d7bc1a7ac753 -
Branch / Tag:
refs/tags/v2.0.3 - Owner: https://github.com/Amraa1
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@698bd463fa3874e0c52b688db514d7bc1a7ac753 -
Trigger Event:
release
-
Statement type: