Install & Compatibility
Where this runs
tested against v1.79.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 1.606s · 36.7MB
glibcpy 3.10–3.95 runs
installs and imports cleanly · install 4.5s · import 1.488s · 36MB
35MB installed
● package 35MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
ModernTreasury
✓ from modern_treasury import ModernTreasury
AsyncModernTreasury
✓ from modern_treasury import AsyncModernTreasury
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}")
Debug
Known issues
breakingA 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.fixUpdate 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. affects: <0.5.0
gotchaWhile 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.fixConfigure 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.
affects: All versions
gotchaList 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()`.fixUtilize 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.
affects: All versions
breakingFor 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.fixBe 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.
affects: Likely >v1.x.x (upcoming major version)
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'modern_treasury'
The 'modern-treasury' Python library is not installed in the current environment or the import statement has a typo.
fixInstall the library using pip: `pip install modern-treasury` or ensure the import statement is `from modern_treasury import ModernTreasury`.
modern_treasury.APIConnectionError: Missing required client configuration: api_key
The Modern Treasury API key or Organization ID was not provided to the client, either as environment variables or direct arguments.
fixSet the `MODERN_TREASURY_API_KEY` and `MODERN_TREASURY_ORGANIZATION_ID` environment variables, or pass them explicitly when initializing the client: `client = ModernTreasury(api_key='YOUR_API_KEY', organization_id='YOUR_ORG_ID')`.
modern_treasury.APIStatusError: Status Code: 400, Message: "A required parameter is missing in the request."
An API request was made to Modern Treasury with one or more mandatory parameters missing or incorrectly formatted for the specific endpoint.
fixConsult the Modern Treasury API documentation for the specific endpoint being called to identify all required parameters and ensure they are included with the correct data types and formats in your request payload.
modern_treasury.APIStatusError: Status Code: 422, Message: "The value provided for the parameter is invalid."
The API received a request where a parameter's value was not acceptable, failing server-side validation. This can also manifest as specific messages like "Already verified account".
fixReview the API documentation for the specific endpoint and the parameter in question, ensuring that the value provided adheres to the expected format, type, and allowed range or set of options. For 'Already verified account', ensure you're not attempting to re-verify an account that is already verified.
AttributeError: 'ModernTreasury' object has no attribute 'some_nonexistent_method'
The code is attempting to call a method or access an attribute on the `ModernTreasury` client object that either does not exist, is misspelled, or has been changed in a different version of the library.
fixCheck the `modern-treasury` library's `api.md` or official documentation for the correct method and attribute names for your installed version of the library.
Upgrade
Version history
1.79.0latest on PyPI · released Jul 27, 2026
Audit
Dependencies
httpxrequiredPowers the underlying HTTP requests for both synchronous and asynchronous clients.