SDKs overview
Hirak Exchange Rates offers a suite of Software Development Kits (SDKs) designed to streamline integration with its API for various programming environments. These SDKs provide pre-built functions and methods that encapsulate the complexity of HTTP requests, authentication, and response parsing, allowing developers to focus on application logic rather than low-level API interactions. The official SDKs support popular languages such as Python, Node.js, PHP, Ruby, and Go, ensuring broad compatibility for different development stacks. Each SDK is typically maintained to reflect the latest API features and best practices, as detailed in the Hirak Exchange Rates official documentation.
Using an SDK can reduce development time and potential errors by providing idiomatic access to API endpoints. For instance, developers can retrieve real-time exchange rates or historical data through simple function calls, with the SDK handling the serialization and deserialization of data. This approach is consistent with common API integration patterns observed in other platforms, such as Stripe's API client libraries, which also abstract HTTP communication.
Official SDKs by language
Hirak Exchange Rates provides officially supported SDKs for several programming languages, each designed to offer a native-like development experience. These SDKs are the recommended method for interacting with the Hirak Exchange Rates API due to their direct support and maintenance by the Hirak team. Below is a summary of the available official SDKs:
| Language | Package/Module Name | Installation Command | Maturity |
|---|---|---|---|
| Python | hirak-exchange-rates |
pip install hirak-exchange-rates |
Stable |
| Node.js | @hirak/exchange-rates |
npm install @hirak/exchange-rates |
Stable |
| PHP | hirak/exchange-rates |
composer require hirak/exchange-rates |
Stable |
| Ruby | hirak-exchange-rates |
gem install hirak-exchange-rates |
Stable |
| Go | github.com/hirak/exchange-rates-go |
go get github.com/hirak/exchange-rates-go |
Stable |
Each SDK is designed to provide access to the full range of Hirak Exchange Rates API functionalities, including real-time exchange rates, historical data, and currency conversion. Developers can refer to the specific documentation for each language for detailed usage instructions and examples.
Installation
Installing the Hirak Exchange Rates SDKs involves using the standard package manager for each respective programming language. Ensure you have the correct language runtime and package manager installed before proceeding. The following instructions detail the common installation methods:
Python
For Python, the SDK can be installed using pip, the Python package installer. It is recommended to use a virtual environment to manage dependencies.
pip install hirak-exchange-rates
Node.js
Node.js developers can install the SDK via npm (Node Package Manager) or yarn.
npm install @hirak/exchange-rates
# or
yarn add @hirak/exchange-rates
PHP
PHP projects typically use Composer for dependency management. The Hirak Exchange Rates SDK can be added to your project with Composer.
composer require hirak/exchange-rates
Ruby
Ruby projects use Bundler and RubyGems. The SDK can be installed via the gem command.
gem install hirak-exchange-rates
Go
Go modules are used for dependency management in Go projects. The SDK can be fetched using the go get command.
go get github.com/hirak/exchange-rates-go
After installation, ensure that the SDK is correctly imported into your project files according to the language's module import conventions. For further details on installation and setup, consult the Hirak Exchange Rates API documentation.
Quickstart example
This section provides a quickstart example demonstrating how to fetch real-time exchange rates using the Hirak Exchange Rates SDKs. The examples are provided for Python and Node.js, reflecting the primary language examples highlighted by Hirak Exchange Rates. Replace YOUR_API_KEY with your actual API key obtained from your Hirak Exchange Rates account.
Python Quickstart
This Python example demonstrates how to initialize the client and fetch the latest exchange rates for a specific currency pair.
from hirak_exchange_rates import HirakClient
# Initialize the client with your API key
client = HirakClient(api_key="YOUR_API_KEY")
try:
# Fetch real-time exchange rates for USD to EUR
rates = client.get_latest_rates(base_currency="USD", target_currency="EUR")
print(f"USD to EUR: {rates['EUR']}")
# Fetch rates for multiple target currencies
multiple_rates = client.get_latest_rates(base_currency="USD", target_currencies=["EUR", "GBP", "JPY"])
print("USD to multiple currencies:")
for currency, rate in multiple_rates.items():
print(f" {currency}: {rate}")
# Fetch historical rates for a specific date
historical_rates = client.get_historical_rates(date="2023-01-15", base_currency="USD", target_currency="GBP")
print(f"Historical USD to GBP on 2023-01-15: {historical_rates['GBP']}")
except Exception as e:
print(f"An error occurred: {e}")
Node.js Quickstart
This Node.js example illustrates how to use the SDK to retrieve real-time and historical exchange rate data asynchronously.
const HirakClient = require('@hirak/exchange-rates');
// Initialize the client with your API key
const client = new HirakClient('YOUR_API_KEY');
async function getExchangeRates() {
try {
// Fetch real-time exchange rates for USD to EUR
const rates = await client.getLatestRates({ baseCurrency: 'USD', targetCurrency: 'EUR' });
console.log(`USD to EUR: ${rates.EUR}`);
// Fetch rates for multiple target currencies
const multipleRates = await client.getLatestRates({ baseCurrency: 'USD', targetCurrencies: ['EUR', 'GBP', 'JPY'] });
console.log('USD to multiple currencies:');
for (const currency in multipleRates) {
console.log(` ${currency}: ${multipleRates[currency]}`);
}
// Fetch historical rates for a specific date
const historicalRates = await client.getHistoricalRates({ date: '2023-01-15', baseCurrency: 'USD', targetCurrency: 'GBP' });
console.log(`Historical USD to GBP on 2023-01-15: ${historicalRates.GBP}`);
} catch (error) {
console.error(`An error occurred: ${error.message}`);
}
}
getExchangeRates();
These examples cover basic functionality, including fetching current rates for single or multiple currency pairs and retrieving historical data. More advanced features and error handling strategies are detailed in the Hirak Exchange Rates API documentation.
Community libraries
While Hirak Exchange Rates provides a set of official SDKs, the broader developer community may also contribute unofficial libraries or wrappers. These community-driven tools can sometimes offer additional features, integrations with specific frameworks, or support for languages not officially covered. However, it is important to note that community libraries may not receive the same level of maintenance, security auditing, or official support as the SDKs provided by Hirak Exchange Rates.
Developers considering community libraries should evaluate their active maintenance, community support, and alignment with the latest API versions. Resources like GitHub and language-specific package repositories (e.g., PyPI for Python, npm for Node.js) are common places to discover such contributions. Always verify the source and reputation of any third-party library before integrating it into production systems. For critical applications, relying on the official Hirak Exchange Rates SDKs is generally recommended to ensure compatibility and access to direct support.