Privat Bank API
Asynchronous API Manager
- class privatbank_api_client.async_privat.manager.AsyncPrivatManager(token=None, iban=None)[source]
Bases:
BasePrivatManagerA manager class providing asynchronous methods to interact with Privat APIs, inheriting shared utilities from BasePrivatManager.
This class is responsible for making HTTP requests to the Privat APIs and supports methods to get currency rates, balance, transaction statements, and create payments.
- async async_request(method: str, uri: str, headers=None, data=None) Dict[source]
Sends an asynchronous HTTP request to the given URI :param method: The HTTP method to use (e.g., “GET”, “POST”). :type method: str :param uri: The target API endpoint. :type uri: str :param headers: Optional HTTP headers to send with the request. :type headers: dict or None :param data: Optional payload for POST requests. :type data: dict or None :return: A dictionary containing the response payload. :rtype: dict :raises aiohttp.ClientResponseError: If the request results in an HTTP error. :raises Exception: For other unexpected exceptions.
- async create_payment(recipient: str, amount: float) Dict[source]
Creates a payment transaction using the Privat APIs.
- Parameters:
recipient (str) – The recipient’s identifier for the transaction.
amount (float) – The amount to transfer.
- Returns:
A dictionary containing the status or result of the payment.
- Return type:
dict
- Raises:
Exception – If an error occurs during the request.
- async get_balance() Dict[source]
Retrieves the account balance for the authorized client.
- Returns:
A dictionary containing the account balance details.
- Return type:
dict
- Raises:
Exception – If there’s an error retrieving or parsing the balance data.
- async get_client_info() Dict[source]
Retrieves detailed client information from Privat APIs.
- Returns:
A dictionary containing client information details.
- Return type:
dict
- Raises:
Exception – If an error occurs during the request.
- async get_currencies(cashe_rate: bool) Dict[source]
Fetches currency rates from the Privat APIs.
- Parameters:
cashe_rate (bool) – Determines whether to fetch cash rate or non-cash rate.
- Returns:
A dictionary with currency rate data.
- Return type:
dict
- Raises:
Exception – If an error occurs during the request.
- async get_statement(period: int, limit: int) Dict[source]
Fetches the transaction statement for a specified time period and limit.
- Parameters:
period (int) – The period in days to retrieve transactions for.
limit (int) – The maximum number of transactions to retrieve.
- Returns:
A dictionary of transaction statement details.
- Return type:
dict
- Raises:
Exception – If an error occurs during the request.
Synchronous API Manager
- class privatbank_api_client.sync_privat.manager.SyncPrivatManager(token=None, iban=None)[source]
Bases:
BasePrivatManagerSyncPrivatManager provides methods to interact with PrivatBank APIs synchronously. The class is used for retrieving account information, balances, making payments, and obtaining transaction statements.
- create_payment(recipient: str, amount: float) Dict[source]
Create a payment transaction to a specified recipient.
- Parameters:
recipient (str) – The recipient’s account identifier.
amount (float) – The amount to be transferred.
- Returns:
A dictionary denoting the payment response from the server.
- Return type:
dict
- get_balance() Dict[source]
Retrieve the account balance from the client information.
- Returns:
A dictionary containing the account balance.
- Return type:
dict
- get_client_info() Dict[source]
Retrieve client account information (e.g., balances or transactions).
- Returns:
A dictionary comprising client details from PrivatBank.
- Return type:
dict
- get_currencies(cashe_rate: bool) Dict[source]
Obtain exchange rates from PrivatBank APIs.
- Parameters:
cashe_rate (bool) – Whether to fetch cash exchange rates.
- Returns:
A dictionary containing exchange rate information.
- Return type:
dict
- get_statement(period: int, limit: int) Dict[source]
Retrieve the account statement for a given period and limit.
- Parameters:
period (int) – The number of days prior to the current date for which to fetch transactions.
limit (int) – The maximum number of transactions to fetch.
- Returns:
A dictionary containing the statement details.
- Return type:
dict
- classmethod session() Session[source]
Create and return a session object for making HTTP requests.
- Returns:
A new requests.Session instance.
- Return type:
requests.sessions.Session
- sync_request(method: str, uri: str, headers=None, data=None) Dict[source]
Perform a synchronous HTTP request using the specified method, URI, headers, and data :param method: HTTP method for the request (e.g., “GET”, “POST”). :type method: str :param uri: The URI to which the request is sent. :type uri: str :param headers: Optional headers to include in the request. :type headers: dict or None :param data: Optional data payload for POST requests. :type data: dict, str, bytes, or None :return: The response from the server parsed into a dictionary. :rtype: dict
FastAPI Router
- async privatbank_api_client.fastapi_privat.router.add_privatbank(schema: PrivatSchema, session: AsyncSession = Depends(async_session)) Dict[source]
Add a new PrivatBank user record to the database.
- Parameters:
schema – PrivatSchema object containing user details.
session – Database session dependency for async queries.
- Returns:
Dictionary with the creation response or error details.
- Raises:
Exception in case of database or internal issues.
- async privatbank_api_client.fastapi_privat.router.balance(user_id: str, session: AsyncSession = Depends(async_session)) Dict[source]
Fetch the account balance for a given PrivatBank user.
- Parameters:
user_id – Unique identifier of the user.
session – Database session dependency for async queries.
- Returns:
Dictionary with account balance or error details.
- Raises:
Exception in case of internal issues or API failure.
- async privatbank_api_client.fastapi_privat.router.change_privatbank(user_id: str, schema: PrivatSchemaUpdate, session: AsyncSession = Depends(async_session)) Dict[source]
Update an existing PrivatBank user record.
- Parameters:
user_id – Unique identifier of the user to be updated.
schema – PrivatSchemaUpdate object with updated details.
session – Database session dependency for async queries.
- Returns:
Dictionary with the update response or error details.
- Raises:
Exception in case of database or internal issues.
- async privatbank_api_client.fastapi_privat.router.client_info(user_id: str, session: AsyncSession = Depends(async_session)) Dict[source]
Retrieve client-specific details from PrivatBank.
- Parameters:
user_id – Unique identifier of the user.
session – Database session dependency for async queries.
- Returns:
Dictionary with client details or error information.
- Raises:
Exception in case of internal issues or missing user records.
- async privatbank_api_client.fastapi_privat.router.currencies(cashe_rate: bool) Dict[source]
Fetch current currency exchange rates from PrivatBank.
- Parameters:
cashe_rate – Boolean indicating if cash rates should be fetched.
- Returns:
Dictionary with current exchange rates or error details.
- Raises:
Exception in case of an internal issue or API failure.
- async privatbank_api_client.fastapi_privat.router.delete_privatbank(user_id: str, session: AsyncSession = Depends(async_session)) Dict[source]
Delete a PrivatBank user record from the database.
- Parameters:
user_id – Unique identifier of the user to delete.
session – Database session dependency for async queries.
- Returns:
Dictionary with the deletion response or error details.
- Raises:
Exception in case of database or internal issues.
- async privatbank_api_client.fastapi_privat.router.payment(schema: PrivatSchemaPayment, session: AsyncSession = Depends(async_session)) Dict[source]
Perform a payment to another account using PrivatBank.
- Parameters:
schema – PrivatSchemaPayment object with recipient and amount details.
session – Database session dependency for async queries.
- Returns:
Dictionary with payment confirmation or error details.
- Raises:
Exception in case of internal issues or API failure.
- async privatbank_api_client.fastapi_privat.router.statement(user_id: str, period: int, limit: int, session: AsyncSession = Depends(async_session)) Dict[source]
Retrieve a transaction statement for the specified user.
- Parameters:
user_id – Unique identifier of the user.
period – Time period (in days) for the statement.
limit – Maximum number of transaction records to fetch.
session – Database session dependency for async queries.
- Returns:
Dictionary with transaction details or error information.
- Raises:
Exception in case of internal issues or API failure.
Django Rest Framework Views
- class privatbank_api_client.drf_privat.views.PrivatBalanceView(**kwargs)[source]
Retrieves account balance information from the Privat API.
- get(request)[source]
Fetches the account balance information.
- get(request) Dict[source]
Fetches account balance information for the user using the Privat API.
- Parameters:
request (Request) – The HTTP request object.
- Returns:
HTTP response containing the account balance.
- Return type:
Dict
- class privatbank_api_client.drf_privat.views.PrivatClientInfo(**kwargs)[source]
Retrieves client information from the Privat API based on stored credentials.
- get(request)[source]
Fetches the client information.
- get(request) Dict[source]
Fetches client information from the Privat API.
- Parameters:
request (Request) – The HTTP request object.
- Returns:
HTTP response containing the client information.
- Return type:
Dict
- class privatbank_api_client.drf_privat.views.PrivatCurrenciesCashRate(**kwargs)[source]
Retrieves cash currency rates from the Privat API.
- get(request)[source]
Fetches the cash currency rates.
- get(request) Dict[source]
Fetches cash currency rates.
- Parameters:
request (Request) – The HTTP request object.
- Returns:
HTTP response containing the cash currency rates.
- Return type:
Dict
- class privatbank_api_client.drf_privat.views.PrivatCurrenciesNonCashRate(**kwargs)[source]
Retrieves non-cash currency rates from the Privat API.
- get(request)[source]
Fetches the non-cash currency rates.
- get(request) Dict[source]
Fetches non-cash currency rates.
- Parameters:
request (Request) – The HTTP request object.
- Returns:
HTTP response containing the non-cash currency rates.
- Return type:
Dict
- class privatbank_api_client.drf_privat.views.PrivatPaymentView(**kwargs)[source]
Handles payment operations through the Privat API.
- post(request)[source]
Processes and executes the payment based on provided recipient and amount.
- post(request) Dict[source]
Processes and executes a payment using the Privat API.
- Parameters:
request (Request) – The HTTP request containing payment details such as recipient and amount.
- Returns:
HTTP response indicating success or failure of the payment process.
- Return type:
Dict
- serializer_class
alias of
PrivatPaymentSerializer
- class privatbank_api_client.drf_privat.views.PrivatStatementView(**kwargs)[source]
Retrieves account statements from the Privat API based on a given period and limit.
- post(request)[source]
Fetches account statements for the specified period and limit.
- post(request) Dict[source]
Fetches account statements based on the provided period and limit.
- Parameters:
request (Request) – The HTTP request containing the period and limit data.
- Returns:
HTTP response with the account statements or an error message.
- Return type:
Dict
- serializer_class
alias of
PrivatPeriodSerializer
- class privatbank_api_client.drf_privat.views.PrivatView(**kwargs)[source]
Handles CRUD operations for Privat model instances.
- post(request)[source]
Creates a new Privat instance for the user or raises an exception if one exists.
- put(request)[source]
Updates the existing Privat instance with new data or raises an exception if none exists.
- delete(request)[source]
Deletes the user’s Privat instance or raises an exception if none exists.
- delete(request) Dict[source]
Deletes the user’s Privat instance.
- Parameters:
request (Request) – The HTTP request object.
- Returns:
HTTP response indicating success or failure of the deletion.
- Return type:
Dict
- post(request) Dict[source]
Creates a new Privat instance for the user.
- Parameters:
request (Request) – The HTTP request containing user’s data to create the Privat instance.
- Returns:
HTTP response indicating success or failure of the operation.
- Return type:
Dict
- put(request) Dict[source]
Updates an existing Privat instance for the user.
- Parameters:
request (Request) – The HTTP request containing updated data for the Privat instance.
- Returns:
HTTP response indicating success or failure of the operation.
- Return type:
Dict
- serializer_class
alias of
PrivatSerializer