Client library for Mopé by Hakrinbank
- API Docs
- Instructions for acquiring a token
- Python 3.11 or newer
- Mopé API Token
First, install from PyPi by running pip install python-mope
Example usage:
from mope import Mope
mope = Mope(token="test_123")
mope.shop.get_payment_request(payment_id="123")Requests use a 5-second connect timeout and a 30-second read timeout by default.
Configure both with Mope(token="test_123", timeout=(3.0, 15.0)), or pass a
single number of seconds to apply to both. mope.client.Client accepts the same
keyword argument. Values must be finite and greater than zero. The read timeout
limits inactivity between received bytes, not the total duration of a request.
Shop methods raise mope.errors.MopeAPIError for HTTP errors. It is a subclass
of requests.HTTPError, so existing handlers keep working. Its status_code,
code, message, and data fields expose the HTTP status and validated Mopé
error details, such as code 1033 for account limits exceeded. If the error body
is missing or malformed, code and data are None and message retains the
HTTP error description. The original response and exception cause are preserved.
Connection failures and timeouts remain requests.RequestException subclasses.
Malformed successful responses still raise TypeError, ValueError, or
KeyError; invalid JSON raises requests.exceptions.JSONDecodeError, which is
also a ValueError. Applications should translate these errors at the API call
boundary and decide which failures are retryable. Requests are not automatically
retried, including payment creation after a timeout.
Install uv, then run:
uv sync --locked
uv run --locked ruff check .
uv run --locked ruff format --check .
uv run --locked ty check
uv run --locked pytest
uv build --no-sourcesDevelopment uses Python 3.15.2 from .python-version; uv installs it when needed.
The library supports Python 3.11+, and CI tests the built wheel on Python 3.11,
3.12, 3.13, 3.14, and 3.15. Ruff and ty target Python 3.11 compatibility.
Run uv run ruff format . to format code. Commit uv.lock after changing
dependencies; use uv lock --upgrade to refresh their locked versions.
The package includes inline types and a py.typed marker. API responses are
validated before creating models: invalid field types raise TypeError, invalid
status values raise ValueError, and missing required fields raise KeyError.
Values are not coerced. Payment metadata remains a list of dictionaries with
string key and value fields, as defined by the
Mopé API schema.
To release, update mope/__version__.py, run uv lock, and commit the changes.
Publish a GitHub release whose tag is the package version or v followed by that
version. The workflow checks the tag, runs lint, formatting and type checks,
builds the source distribution and wheel, and tests the installed wheel across
all supported Python versions before uploading those same artifacts to PyPI.
Methods
| Argument | Type | Required |
|---|---|---|
| amount | int | yes |
| description | string | yes |
| order_id | string | yes |
| currency | enum (USD, SRD, EUR) | yes |
| redirect_url | string | yes |
return type: mope.models.payments.CreatePaymentResponse
| Argument | Type | Required |
|---|---|---|
| payment_id | string | yes |
return type: mope.models.payments.PaymentRequest