Skip to main content

Mesta Python Library

pypi

The official Mesta client library. Each method calls one API endpoint. For end-to-end flows such as onboarding a sender or making a payout, follow the guides at https://docs.mesta.xyz.

Table of Contents

Documentation

API reference documentation is available here.

Installation

pip install mesta

Reference

A full reference for this library is available here.

Usage

Instantiate and use the client with the following:

from mesta import Mesta

client = Mesta(
    api_key="<value>",
    api_secret="<x-api-secret>",
)

client.merchants.accept_terms(
    merchant_id="merchantId",
)

Environments

This SDK allows you to configure different environments for API requests.

from mesta import Mesta
from mesta.environment import MestaEnvironment

client = Mesta(
    environment=MestaEnvironment.PRODUCTION,
)

Async Client

The SDK also exports an async client so that you can make non-blocking calls to our API. Note that if you are constructing an Async httpx client class to pass into this client, use httpx.AsyncClient() instead of httpx.Client() (e.g. for the httpx_client parameter of this client).

import asyncio

from mesta import AsyncMesta

client = AsyncMesta(
    api_key="<value>",
    api_secret="<x-api-secret>",
)


async def main() -> None:
    await client.merchants.accept_terms(
        merchant_id="merchantId",
    )


asyncio.run(main())

Exception Handling

When the API returns a non-success status code (4xx or 5xx response), a subclass of the following error will be thrown.

from mesta.core.api_error import ApiError

try:
    client.merchants.accept_terms(...)
except ApiError as e:
    print(e.status_code)
    print(e.body)

Advanced

Access Raw Response Data

The SDK provides access to raw response data, including headers, through the .with_raw_response property. The .with_raw_response property returns a "raw" client that can be used to access the .headers and .data attributes.

from mesta import Mesta

client = Mesta(...)
response = client.merchants.with_raw_response.accept_terms(...)
print(response.headers)  # access the response headers
print(response.status_code)  # access the response status code
print(response.data)  # access the underlying object

Retries

The SDK is instrumented with automatic retries with exponential backoff. A request will be retried as long as the request is deemed retryable and the number of retry attempts has not grown larger than the configured retry limit (default: 2).

Which status codes are retried depends on the retryStatusCodes generator configuration:

legacy (current default): retries on

  • 408 (Timeout)
  • 409 (Conflict)
  • 429 (Too Many Requests)
  • 5XX (All server errors, including 500)

recommended: retries on

  • 408 (Timeout)
  • 409 (Conflict)
  • 429 (Too Many Requests)
  • 502 (Bad Gateway)
  • 503 (Service Unavailable)
  • 504 (Gateway Timeout)

Use the max_retries request option to configure this behavior.

client.merchants.accept_terms(..., request_options={
    "max_retries": 1
})

Timeouts

The SDK defaults to a 60 second timeout. You can configure this with a timeout option at the client or request level.

from mesta import Mesta

client = Mesta(..., timeout=20.0)

# Override timeout for a specific method
client.merchants.accept_terms(..., request_options={
    "timeout": 1
})

Custom Client

You can override the httpx client to customize it for your use-case. Some common use-cases include support for proxies and transports.

import httpx
from mesta import Mesta

client = Mesta(
    ...,
    httpx_client=httpx.Client(
        proxy="http://my.test.proxy.example.com",
        transport=httpx.HTTPTransport(local_address="0.0.0.0"),
    ),
)

Retries and writes

The client retries a request up to two times on 408, 429 and 5xx responses, with backoff and jitter. The Mesta API does not accept an idempotency key yet, so a retried write, for example creating an order or a beneficiary, can be processed twice if the first attempt reached the server before it failed. Until idempotency keys are available, disable retries on writes and handle the error in your code:

client.orders.create(..., request_options={"max_retries": 0})

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mesta-0.1.1.tar.gz (266.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mesta-0.1.1-py3-none-any.whl (636.0 kB view details)

Uploaded Python 3

File details

Details for the file mesta-0.1.1.tar.gz.

File metadata

  • Download URL: mesta-0.1.1.tar.gz
  • Upload date:
  • Size: 266.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for mesta-0.1.1.tar.gz
Algorithm Hash digest
SHA256 572e773e62801033c6f8d6149c992bfba9cf913e709805c03236a9a73dccbc29
MD5 6b14e784843a3162c0b8c7b06c5490e8
BLAKE2b-256 15b3d72ba11e9af15711279f36ca093d0d0cdf4d3f2a17b8167747cbe1337292

See more details on using hashes here.

Provenance

The following attestation bundles were made for mesta-0.1.1.tar.gz:

Publisher: ci.yml on mestafi/mesta-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mesta-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: mesta-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 636.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for mesta-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6f55339b2992302d20fca5825f2f65c7f4d500498c5e58b749739f22a34485a4
MD5 3747414e24d9741c1fe68682648bfb63
BLAKE2b-256 8eaf3363b009a14e7fbb4b981084c92cf63ee6b41e1a5bb61c1af53de52a8e53

See more details on using hashes here.

Provenance

The following attestation bundles were made for mesta-0.1.1-py3-none-any.whl:

Publisher: ci.yml on mestafi/mesta-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page