PHPackages                             lfischer/open-weather-map-api - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. lfischer/open-weather-map-api

ActiveLibrary[API Development](/categories/api)

lfischer/open-weather-map-api
=============================

A simple PHP library for querying the Open Weather Map API.

1.0(5y ago)11381MITPHPPHP &gt;=7.2.0CI failing

Since Feb 1Pushed 5y ago1 watchersCompare

[ Source](https://github.com/leonardfischer/open-weather-map-api)[ Packagist](https://packagist.org/packages/lfischer/open-weather-map-api)[ Docs](https://github.com/leonardfischer/open-weather-map-api)[ RSS](/packages/lfischer-open-weather-map-api/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)Dependencies (3)Versions (6)Used By (0)

Open Weather Map API Client
===========================

[](#open-weather-map-api-client)

This library will help you integrate the Open Weather Map API to your webservice. It is lightweight and provides all necessary code including a lot of convenience methods.

Quick start
-----------

[](#quick-start)

Using the API is very easy - you'll only need to provide a API key (Get one [here](https://openweathermap.org/appid)) in order to use it. There are endpoints for retrieving different weather data by predefined conditions, like "by country and city", "by latitude and longitude", "by airport code" or even "by IP address".

Simply create a `API` instance and get the endpoint you need. These endpoints will contain convenience methods with typed parameters to receive the desired data.

```
use lfischer\openWeatherMap\API;

// Get weather data by a city and (optional) country name.
$weather = (new API(''))
    ->getCurrentWeather()
    ->byCityName('Dusseldorf,Germany');

// Get weather data by a "city ID".
$weather = (new API(''))
    ->getCurrentWeather()
    ->byCityId(524901);
```

### Default options

[](#default-options)

Most endpoints can define a **language** to get API responses in your language. For more details scroll down :)

By default you will receive an array with the data you like. Some endpoints can be used with different **modes** like "XML" and "HTML".

Also it is possible to use different **units** like "metric" and "imperial".

API endpoints for data collection
---------------------------------

[](#api-endpoints-for-data-collection)

The goal is to implement PHP classes for every [data collection API endpoint](https://openweathermap.org/api). The main `API` class has accessor methods for each available endpoint.

- `$api->getClimateForecast()` returns an instance of `ClimateForecastEndpoint`.
- `$api->getCurrentWeather()` returns an instance of `CurrentWeatherEndpoint`.
- `$api->getHourlyForecast()` returns an instance of `HourlyForecastEndpoint`.
- `$api->getDailyForecast()` returns an instance of `DailyForecastEndpoint`.
- `$api->getOneCall()` returns an instance of `OneCallEndpoint`.

**Sadly some endpoints require a paid subscription which I don't have. If anyone likes to contribute or test the affected endpoints please let me know!**

More convenience
----------------

[](#more-convenience)

The API client provides convenience methods and classes to set different **modes** (`xml`, `json` or `html`), **units** (`metric` or `imperial`) or **languages** (49 languages available).

Use the constants located in `Mode`, `Unit` and `Language` to get the correct values and autocompletion in your IDE.

```
// Get weather data by a city and (optional) country name.
use lfischer\openWeatherMap\API;
use lfischer\openWeatherMap\Parameter\Language;
use lfischer\openWeatherMap\Parameter\Mode;
use lfischer\openWeatherMap\Parameter\Unit;

$weather = (new API(''))
    ->getCurrentWeather()
    ->setMode(Mode::XML)
    ->setUnit(Unit::METRIC)
    ->setLanguage(Language::ENGLISH)
    ->byCityName('Dusseldorf,Germany');
```

Different Request options
-------------------------

[](#different-request-options)

The API client can use three different request adapters, according to your environment and possible other libraries.

### cURL

[](#curl)

In case you can not use `file_get_contents`, you can use the 'Curl' request adapter. For this your environment needs to provide the `curl` PHP extension.

### Dump

[](#dump)

The `Dump` request adapter can be used to return the prepared URL in case you have your own request library to work with. This is also used for testing.

### Guzzle

[](#guzzle)

If you are a fan of the great [Guzzle](https://packagist.org/packages/guzzlehttp/guzzle) library, you can use this adapter and make use of all its great features :)

### Simple

[](#simple)

The 'Simple' request adapter makes use of `file_get_contents` (just as the previous versions). For this adapter you will need to activate the [fopen wrappers](https://www.php.net/manual/de/filesystem.configuration.php#ini.allow-url-fopen).

Response types
--------------

[](#response-types)

According to the `mode` option the response will be returned in a different `Response` class. Every response type has a `getResponse` method that returns the specific set of data.

- `HtmlResponse->getResponse()` returns a `string`
- `JsonResponse->getResponse()` returns a `array`
- `XmlResponse->getResponse()` returns a `SimpleXMLElement`

Each type also contains a `getRawResponse` method which will return the raw `string` response from the API, in case you'd like to process the response on your own.

Contribution
============

[](#contribution)

As mentioned before I do not have a paid subscription in order to develop and test every data collection. For this I need **YOUR** help ;)

If anyone likes to contribute or test the affected endpoints please let me know!

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~750 days

Total

3

Last Release

1884d ago

Major Versions

0.2 → 1.02021-03-13

PHP version history (3 changes)0.1PHP &gt;=5.4.0

0.2PHP &gt;=5.6.0

1.0PHP &gt;=7.2.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/316a942d2a9c90eab5c2ba18e9886d5e7d8af7b5c6fe850fe96085dfd08f3486?d=identicon)[Leonard Fischer](/maintainers/Leonard%20Fischer)

---

Top Contributors

[![leonardfischer](https://avatars.githubusercontent.com/u/399835?v=4)](https://github.com/leonardfischer "leonardfischer (55 commits)")

---

Tags

apiopenweathermapopenweathermap-apiphpweatherweather-apiweather-dataweather-forecastapiweather

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/lfischer-open-weather-map-api/health.svg)

```
[![Health](https://phpackages.com/badges/lfischer-open-weather-map-api/health.svg)](https://phpackages.com/packages/lfischer-open-weather-map-api)
```

###  Alternatives

[cmfcmf/openweathermap-php-api

A PHP API to parse weather data from OpenWeatherMap.org. This wrapper tries to normalise and abstract the data and remove inconsistencies.

3471.3M7](/packages/cmfcmf-openweathermap-php-api)[rakibdevs/openweather-laravel-api

Laravel package to connect https://openweathermap.org/ to get customized weather data for any location on the globe immediately

7648.2k](/packages/rakibdevs-openweather-laravel-api)[adinan-cenci/climatempo-api

Uma api para previsão de tempo escrita em PHP.

448.2k](/packages/adinan-cenci-climatempo-api)[gnahotelsolutions/laravel-weather

🌤️ A wrapper around Open Weather Map to get the current weather on a location.

385.3k](/packages/gnahotelsolutions-laravel-weather)[rugaard/weatherkit

Integrate Apple WeatherKit API into your project

111.4k](/packages/rugaard-weatherkit)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
