openbankproject_client package

OpenBankProject Client Library

This library provides a Python client for interacting with the OpenBankProject API. It supports various authentication methods and provides a comprehensive set of features for working with banks, accounts, transactions, and more.

Main Features

  • Multiple authentication methods (DirectLogin, GatewayLogin)

  • Complete account management

  • Transaction handling

  • User and customer management

  • API management and configuration

  • Support for various banking operations

Quick Start

To get started, first install the package:

pip install openbankproject_client

Then, you can use it in your code:

from openbankproject_client import OpenBankProjectClient
from openbankproject_client.auth import DirectLoginAuth

# Create a client with DirectLogin authentication
auth = DirectLoginAuth(
    username="your_username",
    password="your_password",
    consumer_key="your_consumer_key"
)
client = OpenBankProjectClient(
    base_url="https://your-obp-instance.com",
    auth=auth
)

# Get list of banks
banks = client.get_banks()

For more information, see the getting_started/quickstart guide.

Package Structure

The package is organized into several modules:

  • auth: Authentication utilities

  • client: Main client implementation

  • errors: Error handling and custom exceptions

  • extended_account: Extended account management

  • extended_bank: Extended bank management

  • transaction: Transaction management

  • user: User management

  • api_management: API management utilities

  • And many more specialized modules

For detailed documentation of each module, see the modules section.

class openbankproject_client.OpenBankProjectClient(base_url: str = 'https://api.openbankproject.com', api_version: str = 'v5.1.0', direct_login_token: str | None = None, username: str | None = None, password: str | None = None, consumer_key: str | None = None, gateway_login_token: str | None = None, timeout: int = 30)[source]

Bases: object

Client for the OpenBankProject API.

This client provides access to all API endpoints and handles authentication, request formatting, and error handling.

__init__(base_url: str = 'https://api.openbankproject.com', api_version: str = 'v5.1.0', direct_login_token: str | None = None, username: str | None = None, password: str | None = None, consumer_key: str | None = None, gateway_login_token: str | None = None, timeout: int = 30)[source]

Initialize the OpenBankProject API client.

Parameters:
  • base_url – Base URL of the API server

  • api_version – API version to use

  • direct_login_token – Pre-generated DirectLogin token (if available)

  • username – Username for DirectLogin authentication

  • password – Password for DirectLogin authentication

  • consumer_key – Consumer key for DirectLogin authentication

  • gateway_login_token – Pre-generated GatewayLogin token (if available)

  • timeout – Request timeout in seconds

_build_url(endpoint: str) str[source]

Build a full URL for the given endpoint.

Parameters:

endpoint – API endpoint path

Returns:

Full URL including base URL and API version

_handle_response(response: Response) Dict[source]

Handle API response and raise appropriate exceptions for errors.

Parameters:

response – Response object from requests

Returns:

Parsed JSON response as dictionary

Raises:
authenticate() bool[source]

Authenticate with the API if not already authenticated.

Returns:

True if authentication was successful

Raises:

AuthenticationError – If authentication fails

delete(endpoint: str, **kwargs) Dict[source]

Make a DELETE request to the API.

Parameters:
  • endpoint – API endpoint path

  • **kwargs – Additional arguments to pass to requests

Returns:

Parsed JSON response as dictionary

get(endpoint: str, **kwargs) Dict[source]

Make a GET request to the API.

Parameters:
  • endpoint – API endpoint path

  • **kwargs – Additional arguments to pass to requests

Returns:

Parsed JSON response as dictionary

post(endpoint: str, **kwargs) Dict[source]

Make a POST request to the API.

Parameters:
  • endpoint – API endpoint path

  • **kwargs – Additional arguments to pass to requests

Returns:

Parsed JSON response as dictionary

put(endpoint: str, **kwargs) Dict[source]

Make a PUT request to the API.

Parameters:
  • endpoint – API endpoint path

  • **kwargs – Additional arguments to pass to requests

Returns:

Parsed JSON response as dictionary

request(method: str, endpoint: str, **kwargs) Dict[source]

Make a request to the API.

Parameters:
  • method – HTTP method (GET, POST, PUT, DELETE)

  • endpoint – API endpoint path

  • **kwargs – Additional arguments to pass to requests

Returns:

Parsed JSON response as dictionary

Raises:

Various exceptions based on API response

class openbankproject_client.DirectLoginAuth(username: str | None = None, password: str | None = None, consumer_key: str | None = None, token: str | None = None)[source]

Bases: object

Authentication handler for DirectLogin authentication method.

__init__(username: str | None = None, password: str | None = None, consumer_key: str | None = None, token: str | None = None)[source]

Initialize DirectLogin authentication.

Parameters:
  • username – User’s username (required if token not provided)

  • password – User’s password (required if token not provided)

  • consumer_key – Consumer key for the application (required if token not provided)

  • token – Pre-generated DirectLogin token (optional)

authenticate(client) bool[source]

Authenticate with the API and get a token if needed.

Parameters:

client – OpenBankProjectClient instance

Returns:

True if authentication was successful

get_headers() Dict[str, str][source]

Get authentication headers.

Returns:

Dict containing the Authorization header

class openbankproject_client.GatewayLoginAuth(token: str)[source]

Bases: object

Authentication handler for GatewayLogin authentication method.

__init__(token: str)[source]

Initialize GatewayLogin authentication.

Parameters:

token – GatewayLogin JWT token

authenticate(client) bool[source]

Authenticate with the API.

Parameters:

client – OpenBankProjectClient instance

Returns:

True if authentication was successful

get_headers() Dict[str, str][source]

Get authentication headers.

Returns:

Dict containing the Authorization header

class openbankproject_client.Authentication[source]

Bases: object

Authentication utilities for the OpenBankProject API.

static create_direct_login_header(username: str, password: str, consumer_key: str) Dict[str, str][source]

Create a DirectLogin authorization header.

Parameters:
  • username – User’s username

  • password – User’s password

  • consumer_key – Consumer key for the application

Returns:

Dict containing the Authorization header

static create_gateway_login_header(jwt: str) Dict[str, str][source]

Create a GatewayLogin authorization header.

Parameters:

jwt – JSON Web Token for authentication

Returns:

Dict containing the Authorization header

static create_token_header(token: str, auth_type: str = 'DirectLogin') Dict[str, str][source]

Create an authorization header using a token.

Parameters:
  • token – Authentication token

  • auth_type – Authentication type (DirectLogin or GatewayLogin)

Returns:

Dict containing the Authorization header

static generate_jwt(consumer_key: str, consumer_secret: str, user_id: str | None = None, expiry_seconds: int = 3600) str[source]

Generate a JWT token for GatewayLogin.

This is a simplified implementation and may need to be adjusted based on the specific requirements of the OpenBankProject API.

Parameters:
  • consumer_key – Consumer key for the application

  • consumer_secret – Consumer secret for the application

  • user_id – Optional user ID to include in the token

  • expiry_seconds – Token expiry time in seconds (default: 1 hour)

Returns:

JWT token string

exception openbankproject_client.ApiError(message: str, status_code: int | None = None, detail: Dict | None = None)[source]

Bases: Exception

Base exception for OpenBankProject API errors.

__init__(message: str, status_code: int | None = None, detail: Dict | None = None)[source]

Initialize the exception.

Parameters:
  • message – Error message

  • status_code – HTTP status code (if applicable)

  • detail – Additional error details

__str__() str[source]

Return string representation of the error.

exception openbankproject_client.AuthenticationError(message: str, status_code: int | None = None, detail: Dict | None = None)[source]

Bases: ApiError

Exception raised for authentication errors.

exception openbankproject_client.ResourceNotFoundError(message: str, status_code: int | None = None, detail: Dict | None = None)[source]

Bases: ApiError

Exception raised when a resource is not found.

exception openbankproject_client.ValidationError(message: str, status_code: int | None = None, detail: Dict | None = None)[source]

Bases: ApiError

Exception raised for validation errors.

exception openbankproject_client.PermissionError(message: str, status_code: int | None = None, detail: Dict | None = None)[source]

Bases: ApiError

Exception raised for permission errors.

exception openbankproject_client.RateLimitError(message: str, status_code: int | None = None, detail: Dict | None = None)[source]

Bases: ApiError

Exception raised when rate limit is exceeded.

exception openbankproject_client.ServerError(message: str, status_code: int | None = None, detail: Dict | None = None)[source]

Bases: ApiError

Exception raised for server errors.

class openbankproject_client.ErrorHandler[source]

Bases: object

Utility class for handling API errors.

static handle_error_response(response: Any) None[source]

Handle error responses from the API.

Parameters:

response – Response object from requests library

Raises:

Submodules