A php api to parse weather data from This api tries to normalise and abstract the data and remove inconsistencies.

v2.2.3 2018-01-21 12:18 UTC


A php API to retrieve and parse global weather data from This library aims to normalise the provided data and remove some inconsistencies. This library is neither maintained by OpenWeatherMap nor their official PHP API.

Build Status Scrutinizer Quality Score codecov SensioLabsInsight


This library can be found on Packagist. The recommended way to install and use this is through Composer.

composer require "cmfcmf/openweathermap-php-api"

Example call

use Cmfcmf\OpenWeatherMap;
use Cmfcmf\OpenWeatherMap\Exception as OWMException;

// Must point to composer's autoload file.
require 'vendor/autoload.php';

// Language of data (try your own language here!):
$lang = 'de';

// Units (can be 'metric' or 'imperial' [default]):
$units = 'metric';

// Create OpenWeatherMap object. 
// Don't use caching (take a look into Examples/Cache.php to see how it works).
$owm = new OpenWeatherMap('YOUR-API-KEY');

try {
    $weather = $owm->getWeather('Berlin', $units, $lang);
} catch(OWMException $e) {
    echo 'OpenWeatherMap exception: ' . $e->getMessage() . ' (Code ' . $e->getCode() . ').';
} catch(\Exception $e) {
    echo 'General exception: ' . $e->getMessage() . ' (Code ' . $e->getCode() . ').';

echo $weather->temperature;

For more example code and instructions on how to use this library, please take a look into the Examples folder. Make sure to get an API Key from and put it into Examples/ApiKey.ini.

  • CurrentWeather.php Shows how to receive the current weather.
  • WeatherForecast.php Shows how to receive weather forecasts.
  • WeatherHistory.php Shows how to receive weather history.
  • Cache.php Shows how to implement and use a cache.


I'm happy about every pull request or issue you find and open to help making this API more awesome.

You can use Vagrant to kick-start your development. Simply run vagrant up, vagrant ssh and cd into /vagrant to start developing.


MIT — Please see the LICENSE file distributed with this source code for further information regarding copyright and licensing.

Please check out the following official links to read about the terms, pricing and license of OpenWeatherMap before using the service.