
Security News
New CVE Forecasting Tool Predicts 47,000 Disclosures in 2025
CVEForecast.org uses machine learning to project a record-breaking surge in vulnerability disclosures in 2025.
WeatherAPI.com provides access to weather and geo data via a JSON/XML restful API. It allows developers to create desktop, web and mobile applications using this data very easy.
We provide following data through our API:
Real-time weather
10 day weather forecast
Astronomy
Time zone
Location data
Search or Autocomplete API
NEW: Historical weather
You need to signup and then you can find your API key under your account, and start using API right away!
If you find any features missing or have any suggestions, please contact us.
API access to the data is protected by an API key. If at anytime, you find the API key has become vulnerable, please regenerate the key using Regenerate button next to the API key.
Authentication to the WeatherAPI.com API is provided by passing your API key as request parameter through an API .
key=YOUR_API_KEY
You must have Python 2 >=2.7.9
or Python 3 >=3.4
installed on your system to install and run this SDK. This SDK package depends on other Python packages like nose, jsonpickle etc.
These dependencies are defined in the requirements.txt
file that comes with the SDK.
To resolve these dependencies, you can use the PIP Dependency manager. Install it by following steps at https://pip.pypa.io/en/stable/installing/.
Python and PIP executables should be defined in your PATH. Open command prompt and type pip --version
.
This should display the version of the PIP Dependency Manager installed if your installation was successful and the paths are properly defined.
requirements.txt
) for the SDK.pip install -r requirements.txt
. This should install all the required dependencies.The following section explains how to use the Weatherapi SDK package in a new project.
Open up a Python IDE like PyCharm. The basic workflow presented here is also applicable if you prefer using a different editor or IDE.
Click on Open
in PyCharm to browse to your generated SDK directory and then click OK
.
The project files will be displayed in the side bar as follows:
Create a new directory by right clicking on the solution name as shown below:
Name the directory as "test"
Add a python file to this project with the name "testsdk"
Name it "testsdk"
In your python file you will be required to import the generated python library using the following code lines
from weatherapi.weatherapi_client import WeatherapiClient
After this you can write code to instantiate an API client object, get a controller object and make API calls. Sample code is given in the subsequent sections.
To run the file within your test project, right click on your Python file inside your Test project and click on Run
You can test the generated SDK and the server with automatically generated test cases. unittest is used as the testing framework and nose is used as the test runner. You can run the tests as follows:
pip install -r test-requirements.txt
nosetests
In order to setup authentication and initialization of the API client, you need the following information.
Parameter | Description |
---|---|
key | TODO: add a description |
API client can be initialized as following.
# Configuration parameters and credentials
key = 'key'
client = WeatherapiClient(key)
An instance of the APIsController
class can be accessed from the API Client.
ap_is_controller = client.ap_is
Current weather or realtime weather API method allows a user to get up to date current weather information in json and xml. The data is returned as a Current Object.Current object contains current or realtime weather information for a given city.
def get_realtime_weather(self,
q,
lang=None)
Parameter | Tags | Description |
---|---|---|
q | Required | Pass US Zipcode, UK Postcode, Canada Postalcode, IP address, Latitude/Longitude (decimal degree) or city name. Visit request parameter section to learn more. |
lang | Optional | Returns 'condition:text' field in API in the desired language. Visit request parameter section to check 'lang-code'. |
q = 'q'
lang = 'lang'
result = ap_is_controller.get_realtime_weather(q, lang)
Error Code | Error Description |
---|---|
400 | Error code 1003: Parameter 'q' not provided.Error code 1005: API request url is invalid.Error code 1006: No location found matching parameter 'q'Error code 9999: Internal application error. |
401 | Error code 1002: API key not provided.Error code 2006: API key provided is invalid |
403 | Error code 2007: API key has exceeded calls per month quota. Error code 2008: API key has been disabled. |
Forecast weather API method returns upto next 10 day weather forecast and weather alert as json. The data is returned as a Forecast Object.
Forecast object contains astronomy data, day weather forecast and hourly interval weather information for a given city.
def get_forecast_weather(self,
q,
days,
dt=None,
unixdt=None,
hour=None,
lang=None)
Parameter | Tags | Description |
---|---|---|
q | Required | Pass US Zipcode, UK Postcode, Canada Postalcode, IP address, Latitude/Longitude (decimal degree) or city name. Visit request parameter section to learn more. |
days | Required | Number of days of weather forecast. Value ranges from 1 to 10 |
dt | Optional | Date should be between today and next 10 day in yyyy-MM-dd format |
unixdt | Optional | Please either pass 'dt' or 'unixdt' and not both in same request. unixdt should be between today and next 10 day in Unix format |
hour | Optional | Must be in 24 hour. For example 5 pm should be hour=17, 6 am as hour=6 |
lang | Optional | Returns 'condition:text' field in API in the desired language. Visit request parameter section to check 'lang-code'. |
q = 'q'
days = 30
dt = datetime.now()
unixdt = 30
hour = 30
lang = 'lang'
result = ap_is_controller.get_forecast_weather(q, days, dt, unixdt, hour, lang)
Error Code | Error Description |
---|---|
400 | Error code 1003: Parameter 'q' not provided.Error code 1005: API request url is invalid.Error code 1006: No location found matching parameter 'q'Error code 9999: Internal application error. |
401 | Error code 1002: API key not provided.Error code 2006: API key provided is invalid |
403 | Error code 2007: API key has exceeded calls per month quota. Error code 2008: API key has been disabled. |
History weather API method returns historical weather for a date on or after 1st Jan, 2015 as json. The data is returned as a Forecast Object.
def get_history_weather(self,
q,
dt,
unixdt=None,
end_dt=None,
unixend_dt=None,
hour=None,
lang=None)
Parameter | Tags | Description |
---|---|---|
q | Required | Pass US Zipcode, UK Postcode, Canada Postalcode, IP address, Latitude/Longitude (decimal degree) or city name. Visit request parameter section to learn more. |
dt | Required | Date on or after 1st Jan, 2015 in yyyy-MM-dd format |
unixdt | Optional | Please either pass 'dt' or 'unixdt' and not both in same request. unixdt should be on or after 1st Jan, 2015 in Unix format |
endDt | Optional | Date on or after 1st Jan, 2015 in yyyy-MM-dd format'end_dt' should be greater than 'dt' parameter and difference should not be more than 30 days between the two dates. |
unixendDt | Optional | Date on or after 1st Jan, 2015 in Unix Timestamp format unixend_dt has same restriction as 'end_dt' parameter. Please either pass 'end_dt' or 'unixend_dt' and not both in same request. e.g.: unixend_dt=1490227200 |
hour | Optional | Must be in 24 hour. For example 5 pm should be hour=17, 6 am as hour=6 |
lang | Optional | Returns 'condition:text' field in API in the desired language. Visit request parameter section to check 'lang-code'. |
q = 'q'
dt = datetime.now()
unixdt = 30
end_dt = datetime.now()
unixend_dt = 30
hour = 30
lang = 'lang'
result = ap_is_controller.get_history_weather(q, dt, unixdt, end_dt, unixend_dt, hour, lang)
Error Code | Error Description |
---|---|
400 | Error code 1003: Parameter 'q' not provided.Error code 1005: API request url is invalid.Error code 1006: No location found matching parameter 'q'Error code 9999: Internal application error. |
401 | Error code 1002: API key not provided.Error code 2006: API key provided is invalid |
403 | Error code 2007: API key has exceeded calls per month quota. Error code 2008: API key has been disabled. |
WeatherAPI.com Search or Autocomplete API returns matching cities and towns as an array of Location object.
def search_autocomplete_weather(self,
q)
Parameter | Tags | Description |
---|---|---|
q | Required | Pass US Zipcode, UK Postcode, Canada Postalcode, IP address, Latitude/Longitude (decimal degree) or city name. Visit request parameter section to learn more. |
q = 'q'
result = ap_is_controller.search_autocomplete_weather(q)
Error Code | Error Description |
---|---|
400 | Error code 1003: Parameter 'q' not provided.Error code 1005: API request url is invalid.Error code 1006: No location found matching parameter 'q'Error code 9999: Internal application error. |
401 | Error code 1002: API key not provided.Error code 2006: API key provided is invalid |
403 | Error code 2007: API key has exceeded calls per month quota. Error code 2008: API key has been disabled. |
IP Lookup API method allows a user to get up to date information for an IP address.
def get_ip_lookup(self,
q)
Parameter | Tags | Description |
---|---|---|
q | Required | Pass IP address. |
q = 'q'
result = ap_is_controller.get_ip_lookup(q)
Error Code | Error Description |
---|---|
400 | Error code 1003: Parameter 'q' not provided.Error code 1005: API request url is invalid.Error code 1006: No location found matching parameter 'q'Error code 9999: Internal application error. |
401 | Error code 1002: API key not provided.Error code 2006: API key provided is invalid |
403 | Error code 2007: API key has exceeded calls per month quota. Error code 2008: API key has been disabled. |
Return Location Object
def get_time_zone(self,
q)
Parameter | Tags | Description |
---|---|---|
q | Required | Pass US Zipcode, UK Postcode, Canada Postalcode, IP address, Latitude/Longitude (decimal degree) or city name. Visit request parameter section to learn more. |
q = 'q'
result = ap_is_controller.get_time_zone(q)
Error Code | Error Description |
---|---|
400 | Error code 1003: Parameter 'q' not provided.Error code 1005: API request url is invalid.Error code 1006: No location found matching parameter 'q'Error code 9999: Internal application error. |
401 | Error code 1002: API key not provided.Error code 2006: API key provided is invalid |
403 | Error code 2007: API key has exceeded calls per month quota. Error code 2008: API key has been disabled. |
Return Location and Astronomy Object
def get_astronomy(self,
q,
dt)
Parameter | Tags | Description |
---|---|---|
q | Required | Pass US Zipcode, UK Postcode, Canada Postalcode, IP address, Latitude/Longitude (decimal degree) or city name. Visit request parameter section to learn more. |
dt | Required | Date on or after 1st Jan, 2015 in yyyy-MM-dd format |
q = 'q'
dt = datetime.now()
result = ap_is_controller.get_astronomy(q, dt)
Error Code | Error Description |
---|---|
400 | Error code 1003: Parameter 'q' not provided.Error code 1005: API request url is invalid.Error code 1006: No location found matching parameter 'q'Error code 9999: Internal application error. |
401 | Error code 1002: API key not provided.Error code 2006: API key provided is invalid |
403 | Error code 2007: API key has exceeded calls per month quota. Error code 2008: API key has been disabled. |
FAQs
Python client library for Weather API
We found that weatherapi-forked demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
CVEForecast.org uses machine learning to project a record-breaking surge in vulnerability disclosures in 2025.
Security News
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
Research
Security News
Eight new malicious Firefox extensions impersonate games, steal OAuth tokens, hijack sessions, and exploit browser permissions to spy on users.