Skip to main content

Mesta Python Library

pypi

The official Mesta client library. It is generated from the Mesta OpenAPI specification and updated with every API release. 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.0.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.0-py3-none-any.whl (636.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mesta-0.1.0.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.0.tar.gz
Algorithm Hash digest
SHA256 eb69776a664d4524449b1129a28dde3bf5fee8a101be7f09f113bad2f3ba8e34
MD5 1495e1b41f00a3ebafe0de532420b843
BLAKE2b-256 b63c3636b797d2123ebce032b09284dda54654e9f3918d0f76b5ad540a62bbac

See more details on using hashes here.

Provenance

The following attestation bundles were made for mesta-0.1.0.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.0-py3-none-any.whl.

File metadata

  • Download URL: mesta-0.1.0-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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f30f53ee79922bf567c851d7ec72132d83fe8e2eba00031d26cfa5f9e675ca6a
MD5 4cdd73c499d6a8cd9e516fd9ce3ab3f5
BLAKE2b-256 6bf3e38e344ce6ff667641094f8c69bc677db58418d828ce4ae10e8e61b59045

See more details on using hashes here.

Provenance

The following attestation bundles were made for mesta-0.1.0-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

0.1.1

2 files

This release

0.1.0 This release

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