SDKs/Python SDK

Python SDK

Package: mcards-sdkVersion: 2.0.0

Requirements: Python >= 3.9

Installation

pip install mcards-sdk

HMAC Authentication

python
import os
from mcards_sdk import McardsSdk

# HMAC authentication
client = McardsSdk(
    api_key=os.environ["MCARDS_API_KEY"],
    api_secret=os.environ["MCARDS_API_SECRET"],
    base_url="https://api.mcards.com",  # optional
)

# All requests are automatically signed with HMAC-SHA256
profile = client.partner.get_profile()
print(f"Partner: {profile.data['name']}")

# Context manager (auto-closes HTTP client)
with McardsSdk(api_key="...", api_secret="...") as client:
    wallets = client.wallets.list()

OAuth2 Bearer Token

python
# OAuth2 Bearer token authentication
client = McardsSdk()

# 1. Exchange credentials for token
token = client.oauth.create_token(
    client_id="your-client-id",
    client_secret="your-client-secret",
    scope="partner:read wallets:read cards:read",
)

# 2. Set the Bearer token
client.set_bearer_token(token.data["access_token"])

# 3. Make authenticated requests
wallets = client.wallets.list()

Error Handling

python
# All methods return an ApiResponse object
class ApiResponse:
    data: dict | list | None  # Parsed JSON
    status: int               # HTTP status code
    headers: dict             # Response headers
    error: str | None         # Error message if not ok
    ok: bool                  # True if status < 400

# Check-based error handling
result = client.cards.get("card-uuid")
if not result.ok:
    print(f"Error {result.status}: {result.error}")

# Exception-based error handling
from mcards_sdk.exceptions import McardsSdkError

try:
    result = client.cards.get("card-uuid")
    result.raise_for_error()
except McardsSdkError as e:
    print(f"API error: {e} (status={e.status})")

Resource Reference

Partner

client.partner
get_profileGET /partner/profile

Get partner profile

get_profile() -> ApiResponse
get_api_keysGET /partner/api_keys

List API keys

get_api_keys() -> ApiResponse
get_rolesGET /partner/roles

List partner roles

get_roles() -> ApiResponse

OAuth

client.oauth
create_tokenPOST /oauth/token

Exchange credentials for token

create_token(client_id: str, client_secret: str, scope: str | None = None) -> ApiResponse
revoke_tokenPOST /oauth/revoke

Revoke an access token

revoke_token(token: str) -> ApiResponse
get_token_infoGET /oauth/token_info

Introspect current token

get_token_info() -> ApiResponse
list_scopesGET /oauth/scopes

List available scopes

list_scopes() -> ApiResponse
get_rate_limitGET /oauth/rate_limit

Get rate limit status

get_rate_limit() -> ApiResponse
list_applicationsGET /oauth/applications

List OAuth apps

list_applications() -> ApiResponse
create_applicationPOST /oauth/applications

Create OAuth app

create_application(name: str, scopes: str | None = None, sandbox: bool = False) -> ApiResponse
get_applicationGET /oauth/applications/:uuid

Get app details

get_application(uuid: str) -> ApiResponse
delete_applicationDELETE /oauth/applications/:uuid

Revoke OAuth app

delete_application(uuid: str) -> ApiResponse

Wallets

client.wallets
listGET /wallets

List wallets

list(page: int = 1, per_page: int = 25) -> ApiResponse
getGET /wallets/:uuid

Get wallet details

get(uuid: str) -> ApiResponse
updatePUT /wallets/:uuid

Update wallet

update(uuid: str, name: str | None = None, description: str | None = None) -> ApiResponse

Cards

client.cards
listGET /cards

List cards

list(page: int = 1, per_page: int = 25, status: str | None = None) -> ApiResponse
createPOST /cards

Issue a new card

create(cardholder_uuid: str | None = None, program_uuid: str | None = None) -> ApiResponse
getGET /cards/:uuid

Get card details

get(uuid: str) -> ApiResponse
activatePUT /cards/:uuid/activate

Activate a card

activate(uuid: str) -> ApiResponse
deactivatePUT /cards/:uuid/deactivate

Deactivate a card

deactivate(uuid: str) -> ApiResponse
get_balanceGET /cards/:uuid/balance

Get card balance

get_balance(uuid: str) -> ApiResponse

Transactions

client.transactions
listGET /transactions

List transactions

list(page: int = 1, per_page: int = 25, start_date: str | None = None, end_date: str | None = None, card_uuid: str | None = None) -> ApiResponse
getGET /transactions/:uuid

Get transaction details

get(uuid: str) -> ApiResponse

Sandbox

client.sandbox
get_environmentGET /sandbox

Get sandbox info

get_environment() -> ApiResponse
authorizePOST /sandbox/transactions/authorize

Simulate authorization

authorize(amount: float, currency: str, merchant_name: str, **kwargs) -> ApiResponse
settlePOST /sandbox/transactions/settle

Simulate settlement

settle(transaction_id: str, amount: float | None = None) -> ApiResponse
refundPOST /sandbox/transactions/refund

Simulate refund

refund(transaction_id: str, amount: float | None = None) -> ApiResponse
declinePOST /sandbox/transactions/decline

Simulate decline

decline(amount: float, currency: str, merchant_name: str, reason: str) -> ApiResponse