WeatherAPI Open Source: 20+ Language Integration Examples

WeatherAPI GitHub Repository: 20+ Language Integration Examples Now Open Source

We’re excited to announce the launch of our comprehensive open-source GitHub repository featuring WeatherAPI integration examples in over 20 programming languages. This initiative reflects our commitment to supporting the developer community and making weather data integration as seamless as possible across different tech stacks.

Why We Built This Repository

With 850,000+ developers already using WeatherAPI worldwide, we constantly receive requests for implementation examples in various programming languages. While our documentation provides solid foundations, developers often need practical, production-ready code examples to accelerate their integration process.

Our new repository addresses this need by providing battle-tested code samples that demonstrate best practices for API authentication, error handling, response parsing, and data visualization across multiple languages and frameworks.

What’s Included

The repository covers all major WeatherAPI endpoints with implementations in languages including:

  • Web Development: JavaScript, TypeScript, PHP, Python, Ruby, Go
  • Mobile Development: Swift (iOS), Kotlin/Java (Android), Dart (Flutter)
  • Enterprise Languages: C#, Java, Scala, Clojure
  • Systems Programming: Rust, C++, C
  • Emerging Languages: Elixir, Zig, Crystal
  • Scripting: Bash, PowerShell, Perl

Each language folder contains examples for current weather, forecast data, historical queries, and marine conditions, plus practical implementations like weather dashboards and CLI tools.

Featured Implementation: JavaScript Weather Dashboard

Here’s a sample from our JavaScript implementation that fetches current weather and 3-day forecast:

class WeatherAPI {
  constructor(apiKey) {
    this.apiKey = apiKey;
    this.baseUrl = 'https://api.weatherapi.com/v1';
  }

  async getCurrentWeather(location) {
    try {
      const response = await fetch(
        `${this.baseUrl}/current.json?key=${this.apiKey}&q=${encodeURIComponent(location)}&aqi=yes`
      );
      
      if (!response.ok) {
        throw new Error(`HTTP ${response.status}: ${response.statusText}`);
      }
      
      return await response.json();
    } catch (error) {
      console.error('Weather API Error:', error.message);
      throw error;
    }
  }

  async getForecast(location, days = 3) {
    try {
      const response = await fetch(
        `${this.baseUrl}/forecast.json?key=${this.apiKey}&q=${encodeURIComponent(location)}&days=${days}&aqi=yes&alerts=yes`
      );
      
      return await response.json();
    } catch (error) {
      console.error('Forecast API Error:', error.message);
      throw error;
    }
  }
}

// Usage example
const weather = new WeatherAPI('YOUR_API_KEY');

async function displayWeather(city) {
  try {
    const current = await weather.getCurrentWeather(city);
    const forecast = await weather.getForecast(city, 3);
    
    console.log(`Current: ${current.current.temp_c}°C, ${current.current.condition.text}`);
    
    forecast.forecast.forecastday.forEach((day, index) => {
      console.log(`Day ${index + 1}: ${day.day.maxtemp_c}°C / ${day.day.mintemp_c}°C`);
    });
  } catch (error) {
    console.error('Failed to fetch weather:', error.message);
  }
}

Python Implementation Highlights

Our Python examples leverage the popular requests library with comprehensive error handling and response caching:

import requests
from datetime import datetime, timedelta
import json

class WeatherAPIClient:
    def __init__(self, api_key):
        self.api_key = api_key
        self.base_url = "https://api.weatherapi.com/v1"
        self.session = requests.Session()
        
    def get_marine_data(self, location):
        """Fetch marine conditions including wave height and tides"""
        endpoint = f"{self.base_url}/marine.json"
        params = {
            'key': self.api_key,
            'q': location,
            'days': 3
        }
        
        try:
            response = self.session.get(endpoint, params=params, timeout=10)
            response.raise_for_status()
            return response.json()
        except requests.exceptions.RequestException as e:
            print(f"Marine API request failed: {e}")
            return None

# Example: Get surf conditions
client = WeatherAPIClient('YOUR_API_KEY')
marine_data = client.get_marine_data('Malibu, CA')

if marine_data:
    for day in marine_data['forecast']['forecastday']:
        print(f"Date: {day['date']}")
        print(f"Wave height: {day['day']['maxwave_m']}m")
        print(f"Water temp: {day['day']['avgvis_km']}°C")

Repository Structure and Best Practices

Each language implementation follows consistent patterns:

  • Authentication: Secure API key handling with environment variables
  • Error Handling: Robust exception management for network and API errors
  • Rate Limiting: Built-in respect for API rate limits
  • Caching: Response caching examples to optimize API usage
  • Testing: Unit tests and integration test examples

The repository includes comprehensive README files with setup instructions, dependencies, and deployment guides for each language.

Community Contributions Welcome

We encourage the developer community to contribute additional examples, optimizations, and new language implementations. The repository accepts pull requests for:

  • New programming language examples
  • Framework-specific integrations
  • Performance optimizations
  • Additional use case implementations

Get Started Today

Access the complete repository at https://github.com/weatherapicom/weatherapi-examples and start building with WeatherAPI in your preferred language. Each example is designed to work with our free tier, which provides 100,000 API calls per month with no credit card required.

Sign up for your free WeatherAPI key and explore over 4 million locations with real-time weather, forecasts, marine data, and more. Join the 850,000+ developers already building amazing weather-powered applications with WeatherAPI.

Scroll to Top