Skip to main content

Mercury Bank API Python Client

A comprehensive Python client library for interacting with the Mercury Bank API. This library provides easy access to account information, transaction data, and other Mercury banking services.

Features

  • Complete API Coverage: Full support for Mercury Bank's transaction and account endpoints
  • Type Safety: Comprehensive type hints and data models for all API responses
  • Error Handling: Proper exception handling with custom error types
  • Robust Parsing: Built-in parsing for complex transaction details and routing information
  • Easy to Use: Simple, intuitive interface with sensible defaults
  • Well Documented: Comprehensive documentation and examples

Installation

Prerequisites

pip install mercury-bank-api

Quick Start

from mercury_bank_api import MercuryBankAPIClient

# Initialize the client with your API token
client = MercuryBankAPIClient(api_token="your_api_token_here")

# Get all accounts
accounts = client.get_accounts()
for account in accounts:
    print(f"{account.name}: ${account.currentBalance:.2f}")

# Get transactions for a specific account
transactions = client.get_transactions(account_id="account_123", limit=10)
for transaction in transactions.transactions:
    print(f"${transaction.amount:.2f} - {transaction.counterpartyName}")

Note: Make sure to replace "your_api_token_here" with your actual Mercury API token from your Mercury dashboard.

API Reference

MercuryBankAPIClient

The main client class for interacting with the Mercury Bank API.

Initialization

client = MercuryBankAPIClient(
    api_token="your_token",  # Required: Your Mercury API token
    timeout=30               # Optional: Request timeout in seconds (default: 30)
)

Methods

get_accounts() -> List[Account]

Retrieve information about all your bank accounts.

accounts = client.get_accounts()
for account in accounts:
    print(f"Account: {account.name}")
    print(f"Balance: ${account.currentBalance:.2f}")
    print(f"Available: ${account.availableBalance:.2f}")
    print(f"Status: {account.status}")
get_transactions(account_id, **kwargs) -> TransactionResponse

Retrieve transactions for a specific account with optional filtering.

Parameters:

  • account_id (str): The ID of the account
  • limit (int, optional): Maximum number of transactions to return
  • offset (int, optional): Number of transactions to skip
  • start_date (str, optional): Start date filter (ISO format)
  • end_date (str, optional): End date filter (ISO format)
  • status (str, optional): Filter by status ("pending", "sent", "cancelled", "failed")
  • kind (str, optional): Filter by transaction kind
# Get recent transactions
transactions = client.get_transactions(
    account_id="account_123",
    limit=50,
    status="pending"
)

print(f"Total transactions: {transactions.total}")
for transaction in transactions.transactions:
    print(f"${transaction.amount:.2f} - {transaction.counterpartyName}")
get_account_by_id(account_id) -> Optional[Account]

Get a specific account by its ID.

account = client.get_account_by_id("account_123")
if account:
    print(f"Found account: {account.name}")
get_transaction_by_id(account_id, transaction_id) -> Optional[Transaction]

Get a specific transaction by its ID.

transaction = client.get_transaction_by_id("account_123", "transaction_456")
if transaction:
    print(f"Transaction: ${transaction.amount:.2f}")

Data Models

Account

Represents a Mercury bank account.

Key Attributes:

  • id: Account ID
  • name: Account name
  • currentBalance: Current account balance
  • availableBalance: Available balance
  • accountNumber: Account number
  • routingNumber: Routing number
  • status: Account status ("active", "deleted", "pending", "archived")
  • type: Account type ("mercury", "external", "recipient")

Transaction

Represents a Mercury bank transaction.

Key Attributes:

  • id: Transaction ID
  • amount: Transaction amount
  • counterpartyName: Name of the counterparty
  • createdAt: Transaction creation date
  • status: Transaction status ("pending", "sent", "cancelled", "failed")
  • kind: Transaction type (see API docs for all types)
  • details: Detailed routing and payment information
  • attachments: List of transaction attachments

TransactionResponse

Response object containing transactions and metadata.

Attributes:

  • total: Total number of transactions matching the query
  • transactions: List of Transaction objects

Error Handling

The client raises MercuryBankAPIError for API-related errors:

from mercury_bank_api import MercuryBankAPIClient, MercuryBankAPIError

try:
    client = MercuryBankAPIClient(api_token="invalid_token")
    accounts = client.get_accounts()
except MercuryBankAPIError as e:
    print(f"API Error: {e}")

Common Error Messages

  • 401 Unauthorized: Invalid or missing API token. Check your token in the Mercury dashboard
  • 403 Forbidden: Token doesn't have sufficient permissions for the requested operation
  • 404 Not Found: The requested resource (account, transaction) doesn't exist
  • 429 Too Many Requests: Rate limit exceeded. Implement retry logic with backoff

Authentication

The Mercury API uses Bearer token authentication. You can obtain an API token from your Mercury dashboard.

Security Note: Never commit your API token to version control. Use environment variables:

import os
from mercury_bank_api import MercuryBankAPIClient

api_token = os.getenv("MERCURY_API_TOKEN")
client = MercuryBankAPIClient(api_token=api_token)

Examples

See examples.py for comprehensive usage examples, including:

  • Fetching all accounts
  • Retrieving transactions with filtering
  • Finding specific transactions
  • Working with transaction details and attachments

To run the examples:

export MERCURY_API_TOKEN="your_token_here"
python examples.py

API Token Permissions

Make sure your API token has the appropriate permissions:

  • Read Only: Can fetch accounts and transactions
  • Read and Write: Additionally can initiate transactions (requires IP whitelist)
  • Custom: Can be configured with specific scopes

For this client library, a Read Only token is sufficient for all implemented features.

Rate Limiting

The Mercury API may have rate limits. The client will raise a MercuryBankAPIError if you exceed these limits. Implement appropriate retry logic in your application if needed.

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Add tests for your changes
  4. Submit a pull request

Support

For API-related questions, consult the Mercury API documentation.

For client library issues, please open an issue in this repository.

License

See LICENSE file for details.

Metadata

Release files for mercury-bank-api 1.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mercury-bank-api 1.0.3
File Size Uploaded Provenance Actions
mercury_bank_api-1.0.3.tar.gz 13.6 kB With provenance Details for mercury_bank_api-1.0.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for mercury-bank-api 1.0.3
File Interpreter ABI Platform Actions
mercury_bank_api-1.0.3-py3-none-any.whl Python 3 none any Details for mercury_bank_api-1.0.3-py3-none-any.whl

Total release size: 25.7 kB

Release files / mercury_bank_api-1.0.3.tar.gz

Download URL mercury_bank_api-1.0.3.tar.gz
Size 13.6 kB
Tags Source
SHA-256 checksum
How to use checksums
bd42560832963beba9d5b0304cbe6900bb4d67f4f01060a0bdcf07fd60e93d7c
BLAKE2b-256 checksum
How to use checksums
c823df61ec99011fe2d62b102c5268afbfc5ac684e7dd74cbc47358a125e1891
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 29, 2025.

Transparency log

Release files / mercury_bank_api-1.0.3-py3-none-any.whl

Download URL mercury_bank_api-1.0.3-py3-none-any.whl
Size 12.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
450c2bf22903899aa2bbd3b76fa4c76e274b8c836e51fe99e3ed1f3cab987383
BLAKE2b-256 checksum
How to use checksums
43016a7b0e25be2d407621407e896f6782021dab40f5759bd74348e3c9e5e518
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 29, 2025.

Transparency log

Security for mercury-bank-api 1.0.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for mercury_bank_api-1.0.3.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 29, 2025.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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