SDKs overview
The Bank of Russia provides public access to a range of official financial data, including daily exchange rates, through an XML-based API. While there is no extensive suite of official, multi-language Software Development Kits (SDKs) directly from the Bank of Russia, the public nature of the XML endpoint encourages the development of community-driven libraries and direct API consumption. Developers typically interact with the Bank of Russia's daily exchange rates web service by parsing the XML responses directly or using helper libraries.
These tools facilitate the integration of official Russian Ruble exchange rates into various applications, supporting financial analysis, currency conversion tools, and other data-driven services. The primary offering is the direct XML endpoint, which developers can consume using standard HTTP client libraries available in most programming languages. This approach, while requiring manual XML parsing, offers flexibility and direct control over data fetching and processing.
Official SDKs by language
As of 2026, the Bank of Russia does not offer officially supported, language-specific SDKs for its public data services in the traditional sense. The primary method of interaction is through its XML-based web service for exchange rates. Developers are expected to use standard web request libraries and XML parsers available within their chosen programming environments.
Despite the absence of conventional SDKs, the Bank of Russia provides comprehensive documentation detailing the structure of its XML responses, enabling developers to build their own client libraries or integrate directly. This model aligns with the practices of some central banks which prioritize direct data access over prescriptive SDKs, allowing for broader compatibility across diverse technical stacks.
The following table outlines the general approach for integrating with the Bank of Russia's API, emphasizing direct XML consumption rather than pre-built SDKs:
| Language | Package/Method | Installation Command (Conceptual) | Maturity |
|---|---|---|---|
| Python | requests, xml.etree.ElementTree |
pip install requests |
Stable (standard library/common packages) |
| JavaScript (Node.js) | axios, xml2js |
npm install axios xml2js |
Stable (common third-party packages) |
| Java | java.net.http, javax.xml.parsers |
(Standard library) | Stable (standard library) |
| C# (.NET) | HttpClient, System.Xml.Linq |
(Standard library) | Stable (standard library) |
Installation
Since official, language-specific SDKs are not provided by the Bank of Russia, installation typically involves standard package managers for HTTP clients and XML parsing libraries, which are widely available in most programming ecosystems. The process focuses on preparing your environment to make HTTP requests and then parse the XML data received from the Bank of Russia's API endpoint.
Python
To interact with web services and parse XML in Python, the requests library is commonly used for HTTP requests, and xml.etree.ElementTree (part of the standard library) for XML parsing.
pip install requests
JavaScript (Node.js)
For Node.js environments, axios is a popular choice for making HTTP requests, and xml2js can be used for parsing XML into JavaScript objects.
npm install axios xml2js
Java
Java's standard library includes java.net.http.HttpClient for making HTTP requests (since Java 11) and javax.xml.parsers (DocumentBuilderFactory, DocumentBuilder) for parsing XML documents.
// No external installation for standard library components.
// Add HttpClient module to module-info.java if using modules:
// requires java.net.http;
C# (.NET)
In C#, HttpClient is used for HTTP requests, and System.Xml.Linq provides LINQ to XML capabilities for parsing XML responses. Both are part of the .NET standard library.
// No external installation for standard library components.
Quickstart example
This quickstart example demonstrates how to fetch and parse daily exchange rates from the Bank of Russia API using Python. It retrieves the exchange rate for a specific currency (e.g., USD) on a given date.
Python example: Fetching USD exchange rate
This script fetches the daily exchange rates for a specified date and extracts the USD rate. The Bank of Russia's API structure typically provides data against the Russian Ruble (RUB).
import requests
import xml.etree.ElementTree as ET
from datetime import date
def get_cbr_exchange_rate(currency_code: str, target_date: date):
"""
Fetches the exchange rate for a given currency from the Bank of Russia API.
The currency_code should be ISO 4217, e.g., 'USD'.
"""
formatted_date = target_date.strftime('%d/%m/%Y')
# API endpoint for daily exchange rates
url = f"https://www.cbr.ru/scripts/XML_daily.asp?date_req={formatted_date}"
try:
response = requests.get(url)
response.raise_for_status() # Raise an HTTPError for bad responses (4xx or 5xx)
root = ET.fromstring(response.content)
for valute in root.findall('Valute'):
char_code = valute.find('CharCode').text
if char_code == currency_code:
nominal = int(valute.find('Nominal').text)
value = float(valute.find('Value').text.replace(',', '.'))
print(f"Exchange rate for {currency_code} on {formatted_date}: {nominal} {currency_code} = {value} RUB")
return value / nominal
print(f"Currency code {currency_code} not found for {formatted_date}.")
return None
except requests.exceptions.HTTPError as http_err:
print(f"HTTP error occurred: {http_err}")
except requests.exceptions.ConnectionError as conn_err:
print(f"Connection error occurred: {conn_err}")
except requests.exceptions.Timeout as timeout_err:
print(f"Timeout error occurred: {timeout_err}")
except requests.exceptions.RequestException as req_err:
print(f"An unexpected error occurred: {req_err}")
except ET.ParseError as parse_err:
print(f"Error parsing XML: {parse_err}")
return None
# Example usage:
today = date.today()
usd_rate = get_cbr_exchange_rate('USD', today)
if usd_rate:
print(f"1 USD = {usd_rate:.4f} RUB")
# Example for a past date
past_date = date(2023, 1, 15)
eur_rate_past = get_cbr_exchange_rate('EUR', past_date)
if eur_rate_past:
print(f"1 EUR = {eur_rate_past:.4f} RUB on {past_date}")
This example demonstrates the fundamental steps: constructing the URL, making an HTTP GET request, and then parsing the XML response to extract specific currency data. For robust production applications, error handling and more sophisticated XML parsing (e.g., using XPath for complex queries) are recommended. Developers should consult the Bank of Russia's official API documentation for the exact XML structure and available parameters.
For additional guidance on general XML parsing in Python, resources like the Python xml.etree.ElementTree documentation can be helpful.
Community libraries
Given the Bank of Russia's direct XML API approach, a number of community-contributed libraries have emerged to simplify interaction. These libraries often wrap the XML parsing logic into more developer-friendly functions, returning data in common formats like JSON or Python dictionaries.
While a comprehensive official list of community libraries is not maintained by the Bank of Russia, developers can find various implementations on public code repositories such as GitHub. Searching for terms like "cbr xml daily python" or "bank of russia exchange rates nodejs" typically reveals several options. These libraries often share common goals:
- Simplified Data Retrieval: Abstracting the HTTP request details.
- Automated Parsing: Converting XML responses into more consumable data structures.
- Error Handling: Providing more robust error management than direct HTTP calls.
When selecting a community library, it is advisable to consider factors such as:
- Active Maintenance: Libraries that are regularly updated and have active contributors.
- Documentation: Clear and comprehensive usage instructions.
- Community Support: The presence of an issue tracker and responsive maintainers.
- License: Compatibility with your project's licensing requirements.
Developers are encouraged to review the source code of any third-party library to ensure it meets their security and reliability standards, as these are not officially vetted or supported by the Bank of Russia.