SDKs overview

Currencylayer provides access to real-time and historical currency exchange rate data through a RESTful API. While the platform does not distribute traditional, installable Software Development Kits (SDKs) as separate packages for specific programming languages, its API reference includes extensive code examples and integration guidelines. These examples demonstrate how to interact with the API using standard HTTP client libraries available in popular programming environments. This approach allows developers to integrate Currencylayer's functionalities into their applications using familiar tools and practices for making HTTP requests and parsing JSON responses.

The documentation covers various API endpoints, including live rates, historical data, currency conversion, and time-series data. Developers typically use their preferred language's HTTP client to send authenticated requests to the Currencylayer API and then process the JSON response. This method offers flexibility, enabling integration across a wide range of platforms and frameworks without being tied to specific SDK versions.

Official SDKs by language

Currencylayer's official support for integration primarily comes in the form of detailed code examples rather than dedicated SDK packages. The official documentation provides snippets and guidance for interacting with the API using common HTTP request methods in several programming languages. This allows developers to construct requests manually and parse the JSON responses directly, which is a common pattern for REST API integrations.

Language Integration Approach Example Library/Method Maturity
cURL Direct HTTP request curl command-line tool Stable (API examples)
PHP HTTP client libraries file_get_contents, Guzzle HTTP (community) Stable (API examples)
Python HTTP client libraries requests library Stable (API examples)
Node.js HTTP client libraries axios, node-fetch Stable (API examples)
Go Standard library HTTP client net/http package Stable (API examples)
Ruby HTTP client libraries Net::HTTP, httparty Stable (API examples)
Java HTTP client libraries java.net.HttpURLConnection, Apache HttpClient Stable (API examples)

Installation

Since Currencylayer primarily offers API access via direct HTTP requests and JSON responses, installation typically involves setting up an HTTP client library in your chosen programming language. There are no proprietary SDK packages to install via package managers like npm, pip, or Composer for Currencylayer itself.

Python (using requests)

The requests library is a popular choice for making HTTP requests in Python. It can be installed using pip:

pip install requests

Node.js (using axios)

axios is a widely used promise-based HTTP client for the browser and Node.js. Install it via npm:

npm install axios

PHP (using Composer and Guzzle HTTP)

Guzzle is a PHP HTTP client that makes it easy to send HTTP requests and trivial to integrate with web services. Install it using Composer:

composer require guzzlehttp/guzzle

Ruby (using httparty)

httparty is a simple wrapper around Net::HTTP that makes using web service APIs much easier. Install it using RubyGems:

gem install httparty

Java (using Apache HttpClient)

Apache HttpClient is a robust, full-featured, and efficient HTTP client library. If you're using Maven, add the following to your pom.xml:

<dependency>
    <groupId>org.apache.httpcomponents</groupId>
    <artifactId>httpclient</artifactId>
    <version>4.5.13</version>
</dependency>

Quickstart example

This example demonstrates fetching live exchange rates for USD to EUR and GBP using Python's requests library. Replace YOUR_API_KEY with your actual Currencylayer API key, which you can obtain from your Currencylayer account dashboard.

import requests

API_KEY = 'YOUR_API_KEY' # Replace with your actual API key
BASE_URL = 'http://api.currencylayer.com'

def get_live_rates(source='USD', currencies='EUR,GBP'):
    endpoint = f'{BASE_URL}/live'
    params = {
        'access_key': API_KEY,
        'source': source,
        'currencies': currencies
    }
    try:
        response = requests.get(endpoint, params=params)
        response.raise_for_status() # Raise an HTTPError for bad responses (4xx or 5xx)
        data = response.json()
        if data.get('success'):
            print("Live Exchange Rates:")
            for currency, rate in data['quotes'].items():
                print(f"  {currency}: {rate}")
        else:
            print(f"API Error: {data.get('error', {}).get('info', 'Unknown error')}")
    except requests.exceptions.HTTPError as errh:
        print (f"Http Error: {errh}")
    except requests.exceptions.ConnectionError as errc:
        print (f"Error Connecting: {errc}")
    except requests.exceptions.Timeout as errt:
        print (f"Timeout Error: {errt}")
    except requests.exceptions.RequestException as err:
        print (f"Something went wrong: {err}")

if __name__ == '__main__':
    get_live_rates()

This Python script defines a function get_live_rates that constructs a GET request to the /live endpoint, including the API key and desired currencies as parameters. It then prints the fetched exchange rates or an error message if the request fails. For more detailed error handling and API response structures, refer to the Currencylayer documentation.

Community libraries

While Currencylayer itself provides integration guidance through code examples, the open-source community often develops client libraries or wrappers to simplify interaction with popular APIs. These community-contributed libraries can abstract away the details of HTTP requests, JSON parsing, and error handling, offering a more idiomatic interface for specific programming languages.

Developers looking for community solutions for Currencylayer may find libraries on platforms like GitHub or package repositories (e.g., PyPI for Python, npm for Node.js). It is advisable to evaluate such libraries based on their activity, maintenance status, documentation, and community support. For example, a search on GitHub for "currencylayer python" or "currencylayer nodejs client" might yield relevant projects. However, it is important to note that community libraries are not officially supported by Currencylayer and their reliability and compatibility may vary. Always refer to the official Currencylayer documentation for the most accurate and up-to-date API specifications.

When using community-contributed code, developers should prioritize libraries that:

  • Are actively maintained and updated.
  • Have clear documentation and examples.
  • Are compatible with the latest API version.
  • Are licensed appropriately for your project (e.g., MIT, Apache 2.0).
  • Have a strong test suite for reliability.

If a suitable community library is not available or does not meet specific project requirements, integrating directly with the Currencylayer API using a standard HTTP client is a robust and well-documented approach, as demonstrated in the quickstart example.