Python SDK
Package:
mcards-sdkVersion: 2.0.0Requirements: Python >= 3.9
Installation
pip install mcards-sdkHMAC 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.partnerget_profileGET /partner/profileGet partner profile
get_profile() -> ApiResponseget_api_keysGET /partner/api_keysList API keys
get_api_keys() -> ApiResponseget_rolesGET /partner/rolesList partner roles
get_roles() -> ApiResponseOAuth
client.oauthcreate_tokenPOST /oauth/tokenExchange credentials for token
create_token(client_id: str, client_secret: str, scope: str | None = None) -> ApiResponserevoke_tokenPOST /oauth/revokeRevoke an access token
revoke_token(token: str) -> ApiResponseget_token_infoGET /oauth/token_infoIntrospect current token
get_token_info() -> ApiResponselist_scopesGET /oauth/scopesList available scopes
list_scopes() -> ApiResponseget_rate_limitGET /oauth/rate_limitGet rate limit status
get_rate_limit() -> ApiResponselist_applicationsGET /oauth/applicationsList OAuth apps
list_applications() -> ApiResponsecreate_applicationPOST /oauth/applicationsCreate OAuth app
create_application(name: str, scopes: str | None = None, sandbox: bool = False) -> ApiResponseget_applicationGET /oauth/applications/:uuidGet app details
get_application(uuid: str) -> ApiResponsedelete_applicationDELETE /oauth/applications/:uuidRevoke OAuth app
delete_application(uuid: str) -> ApiResponseWallets
client.walletslistGET /walletsList wallets
list(page: int = 1, per_page: int = 25) -> ApiResponsegetGET /wallets/:uuidGet wallet details
get(uuid: str) -> ApiResponseupdatePUT /wallets/:uuidUpdate wallet
update(uuid: str, name: str | None = None, description: str | None = None) -> ApiResponseCards
client.cardslistGET /cardsList cards
list(page: int = 1, per_page: int = 25, status: str | None = None) -> ApiResponsecreatePOST /cardsIssue a new card
create(cardholder_uuid: str | None = None, program_uuid: str | None = None) -> ApiResponsegetGET /cards/:uuidGet card details
get(uuid: str) -> ApiResponseactivatePUT /cards/:uuid/activateActivate a card
activate(uuid: str) -> ApiResponsedeactivatePUT /cards/:uuid/deactivateDeactivate a card
deactivate(uuid: str) -> ApiResponseget_balanceGET /cards/:uuid/balanceGet card balance
get_balance(uuid: str) -> ApiResponseTransactions
client.transactionslistGET /transactionsList transactions
list(page: int = 1, per_page: int = 25, start_date: str | None = None, end_date: str | None = None, card_uuid: str | None = None) -> ApiResponsegetGET /transactions/:uuidGet transaction details
get(uuid: str) -> ApiResponseSandbox
client.sandboxget_environmentGET /sandboxGet sandbox info
get_environment() -> ApiResponseauthorizePOST /sandbox/transactions/authorizeSimulate authorization
authorize(amount: float, currency: str, merchant_name: str, **kwargs) -> ApiResponsesettlePOST /sandbox/transactions/settleSimulate settlement
settle(transaction_id: str, amount: float | None = None) -> ApiResponserefundPOST /sandbox/transactions/refundSimulate refund
refund(transaction_id: str, amount: float | None = None) -> ApiResponsedeclinePOST /sandbox/transactions/declineSimulate decline
decline(amount: float, currency: str, merchant_name: str, reason: str) -> ApiResponse