Mono Bank API

Asynchronous API Manager

class monobank_api_client.async_mono.manager.AsyncMonoManager(token=None)[source]

Bases: BaseMonoManager

An asynchronous manager class for interacting with Mono API.

This class provides various asynchronous methods for performing operations like retrieving currencies, client information, balance, statements, and setting up webhooks.

async async_request(method: str, uri: str, headers=None, data=None) Dict[source]

Makes an asynchronous HTTP request using the provided method, URI, headers, and data.

Parameters:
  • method (str) – The HTTP method (“GET”, “POST”, etc.) to use in the request.

  • uri (str) – The target URI for the HTTP request.

  • headers (dict or None) – Optional headers to include in the request.

  • data (dict or None) – Optional data to include in the request.

Returns:

Response payload including status code and details.

Return type:

dict

Raises:
  • aiohttp.ClientResponseError – Raised if the HTTP request fails with an HTTP error.

  • Exception – Raised if another error occurs during the request.

async create_webhook(webhook: str) Dict[source]

Creates and registers a webhook for receiving client account updates.

Parameters:

webhook (str) – The webhook URL to be registered.

Returns:

A dictionary containing the webhook creation response.

Return type:

dict

Raises:

Exception – Raised if an error occurs during webhook creation.

async get_balance() Dict[source]

Retrieves the balance details of the client from Mono API.

Returns:

A dictionary containing the client’s balance data.

Return type:

dict

Raises:

Exception – Raised if an error occurs while retrieving the balance details.

async get_client_info() Dict[source]

Retrieves client information from Mono API.

Returns:

A dictionary containing the client’s information.

Return type:

dict

Raises:

Exception – Raised if an error occurs during the request.

async get_currencies() Dict[source]

Retrieves the latest currency rates from Mono API.

Returns:

A dictionary containing the response payload with currency data.

Return type:

dict

Raises:

Exception – Raised if an error occurs during the request.

async get_currency(ccy: str) Dict[source]

Retrieves detailed currency exchange information for a given currency code.

Parameters:

ccy (str) – The currency code to retrieve exchange information for.

Returns:

A dictionary containing the response payload with currency details.

Return type:

dict

Raises:

Exception – Raised if an error occurs during the request.

async get_statement(period: int) Dict[source]

Retrieves the account statement for a specified period from Mono API.

Parameters:

period (int) – The number of months or the period for which the statement is requested.

Returns:

A dictionary containing the statement details.

Return type:

dict

Raises:

Exception – Raised if an error occurs during the request.

async classmethod session() ClientSession[source]

Creates an asynchronous ClientSession instance.

Returns:

ClientSession instance for making HTTP requests.

Return type:

aiohttp.client.ClientSession

Synchronous API Manager

class monobank_api_client.sync_mono.manager.SyncMonoManager(token=None)[source]

Bases: BaseMonoManager

SyncMonoManager handles synchronous interactions with Mono’s APIs.

This class provides methods for making HTTP requests to the Mono API, fetching currencies, account balance, client information, and more.

create_webhook(webhook: str) Dict[source]

Register a new webhook URL with Mono API.

Parameters:

webhook (str) – The URL to register as the webhook.

Returns:

API response confirming registration or an error.

Return type:

dict

get_balance() Dict[source]

Retrieve the account balance from Mono API.

The balance is calculated by accessing the first account in the client data.

Returns:

API response containing the account balance.

Return type:

dict

get_client_info() Dict[source]

Fetch client information using the auth token.

Returns:

API response containing client details.

Return type:

dict

get_currencies() Dict[source]

Retrieve the list of supported currencies from Mono API.

Returns:

API response containing currency details.

Return type:

dict

get_currency(ccy: str) Dict[source]

Retrieve specific currency details based on the given currency code.

Parameters:

ccy (str) – Currency code, e.g., “USD”, “EUR”.

Returns:

Currency details or error message.

Return type:

dict

get_statement(period: int) Dict[source]

Fetch a statement for a specified time period.

Parameters:

period (int) – Number of days for which the statement is fetched.

Returns:

API response containing the statement data.

Return type:

dict

classmethod session() Session[source]

Create and return a new session for API requests.

Returns:

A requests session instance.

Return type:

requests.sessions.Session

sync_request(method: str, uri: str, headers=None, data=None) Dict[source]

Make a synchronous HTTP request.

Parameters:
  • method (str) – HTTP method to use, e.g., “GET” or “POST”.

  • uri (str) – API endpoint to send the request to.

  • headers (dict or None) – Headers to include in the request.

  • data (dict or None) – Data payload for POST requests.

Returns:

Parsed API response or error message.

Return type:

dict

FastAPI Router

async monobank_api_client.fastapi_mono.router.add_monobank(schema: MonoSchema, session: AsyncSession = Depends(async_session)) Dict[source]

Add a new Monobank account.

Parameters:
  • schema – Schema containing the Monobank account details.

  • session – Async database session dependency.

Returns:

Response dictionary with operation details.

async monobank_api_client.fastapi_mono.router.balance(user_id: str, session: AsyncSession = Depends(async_session)) Dict[source]

Retrieve account balance for a Monobank user.

Parameters:
  • user_id – User identifier.

  • session – Async database session dependency.

Returns:

Response dictionary containing balance details.

async monobank_api_client.fastapi_mono.router.change_monobank(user: str, schema: MonoSchemaUpdate, session: AsyncSession = Depends(async_session)) Dict[source]

Update an existing Monobank account.

Parameters:
  • user – User identifier.

  • schema – Schema with updated Monobank account details.

  • session – Async database session dependency.

Returns:

Response dictionary with operation details.

async monobank_api_client.fastapi_mono.router.client_info(user_id: str, session: AsyncSession = Depends(async_session)) Dict[source]

Retrieve client information associated with Monobank.

Parameters:
  • user_id – User identifier.

  • session – Async database session dependency.

Returns:

Response dictionary containing client information.

async monobank_api_client.fastapi_mono.router.currencies() Dict[source]

Fetch available currency exchange rates from Monobank.

Returns:

Response dictionary containing currency data.

async monobank_api_client.fastapi_mono.router.currency(ccy_pair: str) Dict[source]

Fetch details for a specific currency pair.

Parameters:

ccy_pair – Currency pair (e.g., “USD/EUR”).

Returns:

Response dictionary containing currency pair details.

async monobank_api_client.fastapi_mono.router.delete_monobank(user: str, session: AsyncSession = Depends(async_session)) Dict[source]

Delete a Monobank account.

Parameters:
  • user – User identifier.

  • session – Async database session dependency.

Returns:

Response dictionary with operation confirmation.

async monobank_api_client.fastapi_mono.router.statement(user_id: str, period: int, session: AsyncSession = Depends(async_session)) Dict[source]

Fetch Monobank account statement for a specific period.

Parameters:
  • user_id – User identifier.

  • period – Time period in days for the statements.

  • session – Async database session dependency.

Returns:

Response dictionary with transaction data.

async monobank_api_client.fastapi_mono.router.webhook(user_id: str, webhook: str, session: AsyncSession = Depends(async_session)) Dict[source]

Register a webhook for a Monobank account.

Parameters:
  • user_id – User identifier.

  • webhook – Webhook URL to be registered.

  • session – Async database session dependency.

Returns:

Response dictionary confirming webhook registration.

Django Rest Framework Views

class monobank_api_client.drf_mono.views.BalanceView(**kwargs)[source]

Retrieves the balance information for the current user based on the Mono token.

get(request) Dict[source]

Retrieve the account balance for the current user.

Parameters:

request – The HTTP request.

Returns:

A response with the account balance or an error if the token is not found.

class monobank_api_client.drf_mono.views.CreateWebhook(**kwargs)[source]

Creates webhooks for the Mono service via a POST request.

post(request) Dict[source]

Create a webhook for the current user’s Mono configuration.

Parameters:

request – The HTTP request containing the webhook URL data.

Returns:

A response indicating success or an error if no token is found.

serializer_class

alias of WebhookSerializer

class monobank_api_client.drf_mono.views.CurrenciesListView(**kwargs)[source]

Provides a list of available currencies via a GET request.

get(request) Dict[source]

Retrieve a list of available currencies.

:param request:The HTTP request. :returns: A response containing the currencies list.

class monobank_api_client.drf_mono.views.CurrencyView(**kwargs)[source]

Retrieves details about a specific currency based on a provided currency pair.

- post

Get details for a specific currency by currency pair.

get(request) Dict[source]

Retrieve client information using the Mono token.

Parameters:

request – The HTTP request.

Returns:

A response with client details or an error if no token is found.

post(request) Dict[source]

Retrieve information for a specific currency.

Parameters:

request – The HTTP request containing the currency pair data.

Returns:

A response with the currency details.

serializer_class

alias of MonoCurrencySerializer

class monobank_api_client.drf_mono.views.MonoView(**kwargs)[source]

Handles operations related to Mono tokens such as creation, update, and deletion.

post()[source]

Create a Mono token.

put()[source]

Update a Mono token.

delete()[source]

Delete a Mono token.

delete(request) Dict[source]

Delete the Mono token for the current user.

Parameters:

request – The HTTP request.

Returns:

A response indicating success or if the token was not found.

post(request) Dict[source]

Create a Mono token for the current user.

Parameters:

request – The HTTP request containing the token data.

Returns:

A response indicating success or if the token already exists.

put(request) Dict[source]

Update the Mono token for the current user.

Parameters:

request – The HTTP request containing updated token data.

Returns:

A response indicating success or if the token was not found.

serializer_class

alias of MonoTokenSerializer

class monobank_api_client.drf_mono.views.StatementView(**kwargs)[source]

Generates account statements based on a specific period via a POST request.

post(request) Dict[source]

Retrieve account statements for a specified period.

Parameters:

request – The HTTP request containing the period data.

Returns:

A response with the account statements or an error if the token is not found.

serializer_class

alias of MonoPeriodSerializer