SDKs overview
Tomorrow provides SDKs and client libraries that streamline interaction with its various APIs, including the Weather API, Historical Weather API, and Air Quality API. These libraries are designed to simplify tasks such as authentication, request formatting, and response parsing, allowing developers to focus on integrating weather data into their applications rather than managing the underlying HTTP communication. While official SDKs are available for specific programming languages, the API's RESTful architecture means it can be consumed by any language capable of making HTTP requests, often with community-contributed libraries or direct HTTP clients.
The core functionality of Tomorrow's APIs is to deliver real-time and forecasted weather data, historical weather records, and air quality information. SDKs abstract the complexity of directly interacting with endpoints like Tomorrow Weather API V4, providing methods that map to API operations. This approach can reduce development time and potential errors associated with manual API calls.
For scenarios not covered by official SDKs, developers can utilize generic HTTP client libraries available in most programming languages to interact with the Tomorrow API endpoints. This flexibility supports a wide range of integration patterns and development environments. For example, cURL is commonly used for direct API testing and scripting due to its ubiquitous presence and command-line utility for making HTTP requests.
Official SDKs by language
Tomorrow offers official SDKs for popular programming languages, designed to provide a native development experience. These SDKs are maintained to reflect the latest API versions and features, ensuring compatibility and access to the full range of Tomorrow's weather data services.
| Language | Package Name | Install Command | Maturity |
|---|---|---|---|
| Python | tomorrow_io |
pip install tomorrow-io |
Stable |
| Node.js | @tomorrow-io/sdk |
npm install @tomorrow-io/sdk |
Stable |
These official libraries are documented on the Tomorrow API documentation portal, which includes installation instructions, usage examples, and API-specific method references.
Installation
Installing Tomorrow's SDKs typically involves using the respective language's package manager. The following instructions cover the official Python and Node.js SDKs.
Python SDK
The Python SDK can be installed via pip, the standard package installer for Python. Ensure you have Python and pip installed on your system.
pip install tomorrow-io
After installation, you can import the library into your Python projects. The Tomorrow Python SDK documentation provides further details on setup and usage.
Node.js SDK
The Node.js SDK is available through npm, the package manager for JavaScript. You need Node.js and npm installed to use this SDK.
npm install @tomorrow-io/sdk
Once installed, you can require or import the module into your Node.js applications. The Tomorrow Node.js SDK guide offers comprehensive examples.
Quickstart example
This section provides a quickstart example demonstrating how to retrieve current weather conditions using the Tomorrow SDKs. You will need an API key, which can be obtained by signing up for a Tomorrow API plan, including the free Developer Plan.
The example focuses on fetching current weather data for a specific location (e.g., New York City) using coordinates.
Python Quickstart
To use the Python SDK, replace YOUR_API_KEY with your actual Tomorrow API key.
import tomorrow_io as tmio
def get_current_weather(api_key, lat, lon):
try:
# Initialize the client with your API key
client = tmio.TomorrowIO(api_key)
# Define the location and fields to retrieve
location = [lat, lon] # Example: New York City coordinates
fields = ['temperature', 'humidity', 'windSpeed']
# Get current weather data
response = client.timelines.get_forecast(
location=location,
fields=fields,
timesteps=['current']
)
if response.data and response.data.timelines:
current_data = response.data.timelines[0].intervals[0].values
print(f"Current Weather at ({lat}, {lon}):")
print(f" Temperature: {current_data.temperature}°C")
print(f" Humidity: {current_data.humidity}%")
print(f" Wind Speed: {current_data.windSpeed} m/s")
else:
print("No current weather data found.")
except tmio.exceptions.TomorrowIOException as e:
print(f"Tomorrow.io API Error: {e}")
except Exception as e:
print(f"An unexpected error occurred: {e}")
# Replace with your actual API key and desired coordinates
API_KEY = "YOUR_API_KEY"
LATITUDE = 40.7128
LONGITUDE = -74.0060
get_current_weather(API_KEY, LATITUDE, LONGITUDE)
This Python script initializes the Tomorrow.io client, specifies the location and desired weather fields, and then retrieves the current forecast data. Error handling is included to catch potential API-specific or general exceptions.
Node.js Quickstart
For the Node.js SDK, replace YOUR_API_KEY with your actual Tomorrow API key. This example uses an asynchronous function to fetch data.
const { TomorrowIO } = require('@tomorrow-io/sdk');
async function getCurrentWeather(apiKey, lat, lon) {
try {
// Initialize the client with your API key
const client = new TomorrowIO(apiKey);
// Define the location and fields to retrieve
const location = [lat, lon]; // Example: New York City coordinates
const fields = ['temperature', 'humidity', 'windSpeed'];
// Get current weather data
const response = await client.timelines.getForecast({
location,
fields,
timesteps: ['current'],
});
if (response.data && response.data.timelines) {
const currentData = response.data.timelines[0].intervals[0].values;
console.log(`Current Weather at (${lat}, ${lon}):`);
console.log(` Temperature: ${currentData.temperature}°C`);
console.log(` Humidity: ${currentData.humidity}%`);
console.log(` Wind Speed: ${currentData.windSpeed} m/s`);
} else {
console.log('No current weather data found.');
}
} catch (error) {
if (error.response) {
console.error(`Tomorrow.io API Error: ${error.response.status} - ${JSON.stringify(error.response.data)}`);
} else {
console.error(`An unexpected error occurred: ${error.message}`);
}
}
}
// Replace with your actual API key and desired coordinates
const API_KEY = "YOUR_API_KEY";
const LATITUDE = 40.7128;
const LONGITUDE = -74.0060;
getCurrentWeather(API_KEY, LATITUDE, LONGITUDE);
This Node.js script also initializes the Tomorrow.io client, defines the request parameters, and fetches current weather data. Asynchronous operations are handled with async/await, and error handling is included for API responses and general errors.
Community libraries
Beyond the officially supported SDKs, developers may encounter community-contributed libraries or integrations that interact with the Tomorrow API. These can vary in language, scope, and maintenance status. While not officially endorsed or supported by Tomorrow, they can offer alternative ways to integrate with the API, especially for languages or frameworks where an official SDK is not available.
When considering community libraries, it is advisable to review their documentation, recent activity, and community support. Resources like GitHub and language-specific package repositories (e.g., PyPI for Python, npm for Node.js, Maven Central for Java) are common places to discover such tools. Developers should verify that community solutions adhere to best practices for API key security and error handling, as outlined in general HTTP status code documentation or the Tomorrow API error codes.
For example, some developers might build wrappers in languages like Go or Ruby, or create plugins for specific data visualization tools or IoT platforms. These often leverage standard HTTP client libraries (e.g., Python's requests, Node.js's node-fetch) to make direct calls to the Tomorrow API and parse the JSON responses. While potentially useful, such libraries require developers to be more familiar with the underlying API structure and error handling mechanisms compared to using official SDKs.