SDKs overview
Mercury provides an API designed for developers to programmatically interact with its banking platform, enabling automation of financial operations and integration of banking data into custom applications. The API allows for tasks such as retrieving account balances, listing transactions, and initiating payments. To simplify this interaction, Mercury offers official Software Development Kits (SDKs) for popular programming languages. These SDKs abstract the complexities of direct HTTP requests, authentication, and response parsing, offering a more idiomatic approach to API interactions through language-specific functions and objects. Beyond official offerings, a growing ecosystem of community-contributed libraries also exists, reflecting developer interest in extending Mercury's functionality across various frameworks and use cases.
The primary benefit of using an SDK is the reduction in development time and effort. Developers can leverage pre-built functions for common API operations, handle authentication flows more securely, and benefit from integrated error handling. This approach contrasts with direct API integration, which requires manual construction of HTTP requests, JSON serialization/deserialization, and explicit error management. The Mercury API documentation provides comprehensive details on available endpoints and data models to support both SDK and direct API usage for those requiring custom implementations or supporting less common programming environments.
Official SDKs by language
Mercury maintains official SDKs to facilitate seamless integration with its API. These SDKs are developed and supported by Mercury, ensuring compatibility with the latest API versions and adherence to best practices for security and performance. Each SDK is tailored to its respective language, providing a native development experience. The choice of SDK depends on the developer's preferred programming environment and the specific requirements of their application.
The official SDKs typically offer a structured way to interact with various Mercury API resources, covering functionality such as account information retrieval, transaction history access, and payment initiation. They often include features like automatic request signing, response parsing into language-specific objects, and robust error handling mechanisms. Developers are encouraged to consult the official Mercury API reference documentation for the most up-to-date information on SDK capabilities and usage guidelines.
| Language | Package Name | Install Command | Maturity |
|---|---|---|---|
| Python | mercury-python |
pip install mercury-python |
Stable |
| Node.js | @mercury/sdk |
npm install @mercury/sdk |
Stable |
| Ruby | mercury-ruby |
gem install mercury-ruby |
Stable |
Installation
Installing Mercury's official SDKs follows standard package management procedures for each respective programming language. Before installation, it is advisable to ensure that the appropriate language runtime and package manager are installed and configured on your development environment. For example, Python developers should have pip installed, Node.js developers should have npm or yarn, and Ruby developers should have gem. These tools are fundamental for managing project dependencies effectively.
Python SDK Installation
To install the Mercury Python SDK, use pip, the Python package installer. It is recommended to install SDKs within a virtual environment to manage dependencies explicitly for each project, preventing conflicts with other Python projects on your system. You can create and activate a virtual environment before installing:
python3 -m venv mercury_env
source mercury_env/bin/activate
pip install mercury-python
Node.js SDK Installation
For Node.js projects, the Mercury SDK is available via npm or yarn. Navigate to your project directory and execute one of the following commands:
npm install @mercury/sdk
or
yarn add @mercury/sdk
This command adds the @mercury/sdk package to your node_modules directory and updates your package.json file, listing it as a dependency.
Ruby SDK Installation
Ruby developers can install the Mercury SDK using RubyGems, Ruby's standard package manager. From your terminal, run:
gem install mercury-ruby
After installation, you can require the gem in your Ruby application by adding require 'mercury-ruby' to your code. For project-specific dependency management, consider using Bundler by adding gem 'mercury-ruby' to your Gemfile and then running bundle install.
After installing the SDK, the next step involves configuring it with your API keys, which are typically obtained from your Mercury developer dashboard. These keys are essential for authenticating your application's requests to the Mercury API securely. Adhering to secure practices by not hardcoding API keys directly into source code and using environment variables or a secure configuration management system is critical for application security, as highlighted in general API security guidelines like those from Google's API client library practices.
Quickstart example
This quickstart example demonstrates how to use the Mercury Node.js SDK to retrieve a list of your Mercury accounts. Before running this code, ensure you have installed the Node.js SDK and have your Mercury API key available. Replace YOUR_MERCURY_API_KEY with your actual API key.
const Mercury = require('@mercury/sdk');
// Initialize the Mercury client with your API key.
// It is recommended to store your API key in an environment variable
// rather than hardcoding it for security reasons.
const mercury = new Mercury({ apiKey: process.env.MERCURY_API_KEY || 'YOUR_MERCURY_API_KEY' });
async function getAccounts() {
try {
// Fetch a list of accounts associated with your Mercury profile.
const accounts = await mercury.accounts.list();
console.log('Successfully retrieved accounts:');
accounts.forEach(account => {
console.log(` Account Name: ${account.name}`);
console.log(` Account ID: ${account.id}`);
console.log(` Account Type: ${account.type}`);
console.log(` Currency: ${account.currency}`);
console.log(` Balance: ${account.balance.amount} ${account.balance.currency}`);
console.log('---');
});
} catch (error) {
console.error('Error retrieving accounts:', error.message);
// Log detailed error for debugging if needed
if (error.response && error.response.data) {
console.error('API Error Details:', error.response.data);
}
}
}
getAccounts();
To execute this example:
- Save the code as
getAccounts.js. - Ensure your
MERCURY_API_KEYenvironment variable is set, or replace'YOUR_MERCURY_API_KEY'with your key directly (for testing purposes only; environment variables are preferred in production). - Run from your terminal:
node getAccounts.js
This script will connect to the Mercury API, authenticate using your provided API key, and then attempt to fetch and print details of all accounts linked to your Mercury profile. The asynchronous getAccounts function handles the API call and processes the response. Error handling is included to catch potential issues during the API request, such as network problems or invalid API keys, providing informative messages.
Community libraries
While Mercury offers official SDKs, the developer community also contributes libraries and tools that extend integration possibilities. These community-driven projects can provide additional functionalities, support for less common programming languages or frameworks, or specialized utilities that complement the official SDKs. Community libraries typically emerge from developers needing to solve specific problems or to integrate Mercury with particular technology stacks not directly covered by official support.
Examples of community contributions might include:
- Framework-specific integrations: Libraries that provide wrappers or plugins for popular web frameworks (e.g., Ruby on Rails, Django, Laravel, Spring Boot) to streamline common tasks like webhook handling or data synchronization.
- Client libraries for other languages: SDKs for languages not officially supported, such as Go, C#, or PHP, developed by community members.
- Specialized tools: Command-line interfaces (CLIs) for quick API interactions, or tools for data visualization and reporting based on Mercury API data.
- Tutorials and examples: Comprehensive guides or demo applications that showcase complex integrations or specific use cases.
Developers interested in leveraging community libraries should explore platforms like GitHub, npm, PyPI, or RubyGems for packages tagged with "Mercury" or related keywords. It is crucial to evaluate the maturity, maintenance status, and security practices of any third-party library before incorporating it into a production environment. Checking the project's documentation, recent commit history, issue tracker, and community reviews can provide insight into its reliability. While community support can accelerate development, official SDKs generally offer a higher level of assurance regarding compatibility and ongoing maintenance directly from Mercury.