Skip to main content

Overview

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

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.
Returns: WhoAmI object with authentication details Example:

create_oauth_client()

Class method to create an OAuth client for authentication.
Parameters:
  • client_id: OAuth2 client ID from Monzo Developer Portal
  • client_secret: OAuth2 client secret
  • redirect_uri: OAuth2 redirect URI
  • http_client: Optional custom httpx client
Returns: 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

The MonzoClient is thread-safe when using the default httpx client. However, if you provide a custom http_client, ensure it’s configured for thread safety: