{"id":2592,"library":"modern-treasury","title":"Modern Treasury Python Library","description":"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.","status":"active","version":"1.75.0","language":"en","source_language":"en","source_url":"https://github.com/Modern-Treasury/modern-treasury-python","tags":["payments","finance","api client","treasury","banking","sdk"],"install":[{"cmd":"pip install modern-treasury","lang":"bash","label":"Install with pip"}],"dependencies":[{"reason":"Powers the underlying HTTP requests for both synchronous and asynchronous clients.","package":"httpx","optional":false}],"imports":[{"symbol":"ModernTreasury","correct":"from modern_treasury import ModernTreasury"},{"symbol":"AsyncModernTreasury","correct":"from modern_treasury import AsyncModernTreasury"}],"quickstart":{"code":"import os\nfrom modern_treasury import ModernTreasury\n\n# It's highly recommended to use environment variables for credentials\n# e.g., in a .env file: MODERN_TREASURY_API_KEY='your_api_key' MODERN_TREASURY_ORGANIZATION_ID='your_org_id'\nclient = ModernTreasury(\n    api_key=os.environ.get(\"MODERN_TREASURY_API_KEY\", \"\"),\n    organization_id=os.environ.get(\"MODERN_TREASURY_ORGANIZATION_ID\", \"\"),\n)\n\ntry:\n    # Example: Create a counterparty\n    counterparty = client.counterparties.create(\n        name=\"My First Counterparty\"\n    )\n    print(f\"Successfully created counterparty with ID: {counterparty.id}\")\n\n    # Example: List counterparties (handles pagination automatically)\n    print(\"\\nListing all counterparties:\")\n    for cp in client.counterparties.list():\n        print(f\" - {cp.name} (ID: {cp.id})\")\n\nexcept Exception as e:\n    print(f\"An error occurred: {e}\")","lang":"python","description":"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."},"warnings":[{"fix":"Update method calls to pass arguments as individual keyword parameters (e.g., `client.create({'name': '...' })` becomes `client.create(name='...')`). A migration guide was provided for incremental migration.","message":"A significant breaking change occurred around version v0.5.0, where argument passing to methods transitioned from a single `TypedDict` object to individual keyword arguments. Code written for older versions using `TypedDict` will break.","severity":"breaking","affected_versions":"<0.5.0"},{"fix":"Configure timeouts globally during client initialization (e.g., `ModernTreasury(timeout=20.0)`) or on a per-request basis using `with_options(timeout=...)`. Consider `httpx.Timeout` for granular control over connect, read, and write timeouts. Always implement retry policies for transient errors.","message":"While the library uses `httpx` and has a default request timeout of 1 minute (and retries certain errors), long-running operations or slow network conditions may benefit from explicit timeout configuration. If not explicitly set, requests could hang for the default duration.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Utilize the provided iterator for simple traversal, or use explicit pagination methods for more control, especially in asynchronous contexts where `await` is required for page fetching.","message":"List methods in the Modern Treasury API are paginated. While the Python library provides auto-paginating iterators (e.g., `for item in client.resource.list():`), direct access to raw page data or granular control requires using methods like `.has_next_page()`, `.next_page_info()`, or `.get_next_page()`.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Be prepared to update code that accesses `.content` or `.text` as properties to call them as methods (`.content()` or `.text()`) and ensure `await` is used for async client methods when the next major version is released. A migration script is expected.","message":"For users accessing raw response data (e.g., headers), the `LegacyAPIResponse` object is changing in the next major version. In the synchronous client, `content` and `text` will become methods instead of properties. In the asynchronous client, all methods will be asynchronous.","severity":"breaking","affected_versions":"Likely >v1.x.x (upcoming major version)"}],"env_vars":null,"last_verified":"2026-04-10T00:00:00.000Z","next_check":"2026-07-09T00:00:00.000Z"}