Overview
TheMonzoClient
is the primary interface for all Monzo API operations. It handles authentication, provides access to all API endpoints, and manages HTTP connections.
Class Definition
Initialization
Basic Usage
Parameters
Parameter | Type | Default | Description |
---|---|---|---|
access_token | Optional[str] | None | OAuth2 access token. If not provided, loads from cache |
http_client | Optional[httpx.Client] | None | Custom httpx client instance |
timeout | float | 30.0 | Request timeout in seconds |
Authentication
The client handles authentication in several ways:- Automatic Token Loading
- Explicit Token
- Mock Mode
Custom HTTP Client
You can provide a custom httpx client for advanced configuration:Properties
The client provides access to all API endpoints through dedicated properties:Property | Type | Description |
---|---|---|
accounts | AccountsAPI | Account and balance operations |
transactions | TransactionsAPI | Transaction management |
pots | PotsAPI | Savings pot operations |
attachments | AttachmentsAPI | File attachment management |
receipts | ReceiptsAPI | Receipt management |
webhooks | WebhooksAPI | Webhook management |
feed | FeedAPI | Feed item creation |
Methods
whoami()
Get information about the current access token.WhoAmI
object with authentication details
Example:
create_oauth_client()
Class method to create an OAuth client for authentication.client_id
: OAuth2 client ID from Monzo Developer Portalclient_secret
: OAuth2 client secretredirect_uri
: OAuth2 redirect URIhttp_client
: Optional custom httpx client
MonzoOAuth
instance for handling authentication flow
Example:
Context Manager Support
The client supports context manager protocol for automatic resource cleanup:Error Handling
The client raises specific exceptions for different error conditions:Complete Example
Advanced Configuration
Connection Pooling
For applications making many concurrent requests:Proxy Configuration
For clients behind corporate proxies:Custom Headers
Add custom headers to all requests:Thread Safety
TheMonzoClient
is thread-safe when using the default httpx client. However, if you provide a custom http_client
, ensure it’s configured for thread safety: