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
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: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: