Cybrid Bank API Python Client
The `cybrid-api-bank-python` library provides a Python client for interacting with the Cybrid Bank API. It enables developers to build and launch white-label crypto products and services, managing resources across banks, customers, accounts, and more. This package is automatically generated from the Cybrid OpenAPI specification. The current version is `0.128.106`, and it appears to be actively maintained with frequent releases, often on a daily basis.
Common errors
-
cybrid_api_bank.exceptions.ApiException: (401) Reason: Unauthorized HTTP response body: {'message': 'Unauthorized', 'message_code': 'unauthorized'}cause The provided access token is missing, invalid, or expired.fixEnsure `CYBRID_BANK_ACCESS_TOKEN` environment variable is correctly set with a valid, non-expired Bearer Token. Implement token refresh logic in production applications to automatically renew tokens before or upon expiration. -
AttributeError: module 'cybrid_api_bank' has no attribute 'api'
cause Incorrect import path for API classes. The API classes are nested within the `api` submodule.fixAdjust import statements to correctly reference the `api` submodule. For example, use `from cybrid_api_bank.api.accounts_api import AccountsApi` instead of `from cybrid_api_bank import AccountsApi`. -
cybrid_api_bank.exceptions.ApiException: (403) Reason: Forbidden HTTP response body: {'message': 'Forbidden', 'message_code': 'invalid_scope'}cause The access token used does not have the necessary scopes to perform the requested operation.fixReview the required scopes for the API endpoint you are calling (refer to Cybrid API documentation). Ensure that when you generate your access token, you request all the necessary scopes (e.g., `accounts:read` for listing accounts, `accounts:execute` for creating accounts).
Warnings
- breaking The Cybrid API, and by extension its generated clients, may undergo breaking changes. While Cybrid aims for a safe evolution of its API, changes in OpenAPI definitions can lead to breaking changes in downstream clients. Developers should subscribe to Cybrid's changelog for advance notice.
- gotcha API credentials (Client ID and Secret) should never be embedded directly in code or committed to a source code repository. They should be stored securely, preferably in environment variables or a secrets management tool.
- gotcha Using a broadly scoped 'Bank token' for customer-specific operations can lead to security vulnerabilities. API requests for a specific customer should use a customer-scoped access token.
- gotcha Access tokens have a limited lifetime (e.g., 30 minutes in production, 8 hours in sandbox). API calls with expired tokens will result in 401 Unauthorized errors.
Install
-
pip install cybrid-api-bank-python
Imports
- Configuration
from cybrid_api_bank.configuration import Configuration
- ApiClient
from cybrid_api_bank.api_client import ApiClient
- BanksApi
from cybrid_api_bank.api.banks_api import BanksApi
- AccountsApi
from cybrid_api_bank.api.accounts_api import AccountsApi
- exceptions
from cybrid_api_bank import exceptions
Quickstart
import os
import cybrid_api_bank
from cybrid_api_bank.configuration import Configuration
from cybrid_api_bank.api_client import ApiClient
from cybrid_api_bank.api.accounts_api import AccountsApi
# --- Configuration and Authentication ---
# It is strongly recommended to store Client ID and Secret in environment variables.
# Generate these credentials from the Cybrid Sandbox or dashboard.
# The access token can be generated using the Client ID and Client Secret via an OAuth 2.0 Client Credentials Grant flow.
# For a quick start, you might manually obtain a Bearer Token and use it directly.
# Replace with your actual Bearer Token or logic to fetch it.
# In a real application, you'd make an OAuth request to Cybrid's Identity Provider
# to exchange CLIENT_ID and CLIENT_SECRET for an ACCESS_TOKEN.
# Example: curl -X POST https://id.sandbox.cybrid.app/oauth/token -d '{"grant_type": "client_credentials", "client_id": "<Your Client ID>", "client_secret": "<Your Secret>", "scope": "accounts:read"}'
ACCESS_TOKEN = os.environ.get('CYBRID_BANK_ACCESS_TOKEN', 'YOUR_CYBRID_BANK_ACCESS_TOKEN')
# Configure API key authorization: BearerAuth
configuration = Configuration(
access_token = ACCESS_TOKEN,
host = "https://bank.sandbox.cybrid.app" # Or https://bank.production.cybrid.app for production
)
# Create an instance of the API client
with ApiClient(configuration) as api_client:
# Create an instance of the AccountsApi
accounts_api_instance = AccountsApi(api_client)
try:
# List accounts
# Optional parameters can be passed as keyword arguments
api_response = accounts_api_instance.list_accounts(limit=10)
print("Successfully listed accounts:")
for account in api_response.data:
print(f" Account GUID: {account.guid}, Asset: {account.asset}, Balance: {account.platform_balance}")
except cybrid_api_bank.exceptions.ApiException as e:
print(f"Exception when calling AccountsApi->list_accounts: {e}")
except Exception as e:
print(f"An unexpected error occurred: {e}")