Modern Treasury Python Library

1.75.0 · active · verified Fri Apr 10

The official Python library for the Modern Treasury API, providing convenient access to their REST API from any Python 3.9+ application. It features comprehensive type definitions for request parameters and response fields, offering both synchronous and asynchronous clients powered by `httpx`. The library undergoes very frequent updates, often with multiple releases per week, reflecting ongoing API development and new features.

Warnings

Install

Imports

Quickstart

Initializes the synchronous Modern Treasury client using environment variables for authentication and demonstrates creating and listing counterparties. For asynchronous usage, import `AsyncModernTreasury` and `await` calls.

import os
from modern_treasury import ModernTreasury

# It's highly recommended to use environment variables for credentials
# e.g., in a .env file: MODERN_TREASURY_API_KEY='your_api_key' MODERN_TREASURY_ORGANIZATION_ID='your_org_id'
client = ModernTreasury(
    api_key=os.environ.get("MODERN_TREASURY_API_KEY", ""),
    organization_id=os.environ.get("MODERN_TREASURY_ORGANIZATION_ID", ""),
)

try:
    # Example: Create a counterparty
    counterparty = client.counterparties.create(
        name="My First Counterparty"
    )
    print(f"Successfully created counterparty with ID: {counterparty.id}")

    # Example: List counterparties (handles pagination automatically)
    print("\nListing all counterparties:")
    for cp in client.counterparties.list():
        print(f" - {cp.name} (ID: {cp.id})")

except Exception as e:
    print(f"An error occurred: {e}")

view raw JSON →