Skip to content

Commit a0e2cf3

Browse files
committed
docs, docs, docs!
1 parent 9664888 commit a0e2cf3

10 files changed

+167
-4
lines changed
File renamed without changes.

sphinx/usage-examples-v2/air-pollution-api-usage-examples.md renamed to sphinx/v3/air-pollution-api-usage-examples.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ Please be aware that also data forecasts can be returned, depending on the searc
2121

2222
Getting the data is easy:
2323
```
24+
from pyowm import OWM
25+
owm = OWM('apikey')
26+
2427
# Get latest CO Index on geocoordinates
2528
coi = owm.coindex_around_coords(lat, lon)
2629

sphinx/usage-examples-v2/alerts-api-usage-examples.md renamed to sphinx/v3/alerts-api-usage-examples.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ from pyowm.alertapi30.enums import WeatherParametersEnum, OperatorsEnum, AlertCh
2222
from pyowm.alertapi30.condition import Condition
2323

2424
# obtain an AlertManager instance
25-
owm = OWM(API_Key='blablabla')
25+
owm = OWM('apikey')
2626
am = owm.alert_manager()
2727

2828
# -- areas --
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# City ID Registry usage examples
2+
3+
Using city IDS instead of toponyms or geographic coordinates is the preferred way of querying the OWM weather API
4+
5+
You can obtain the city ID for your toponyms/geoocoords of interest via the `City ID Registry`.
6+
7+
Please refer to the `Code Recipes` page, section: `Identifying cities and places via city IDs`, to get info about it

sphinx/v3/exceptions.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Exceptions
2+
3+
PyOWM uses custom exception classes. Here you can learn which classes are used and when such exceptions are cast by the library
4+
5+
## Exceptions Hierarchy
6+
7+
```
8+
Exception
9+
|
10+
|___PyOWMError
11+
|
12+
|___ConfigurationError
13+
| |
14+
| |__ConfigurationNotFoundError
15+
| |__ConfigurationParseError
16+
|
17+
|___APIRequestError
18+
| |
19+
| |__BadGatewayError
20+
| |__TimeoutError
21+
| |__InvalidSSLCertificateError
22+
|
23+
|___APIResponseError
24+
|
25+
|__NotFoundError
26+
|__UnauthorizedError
27+
|__ParseAPIResponseError
28+
```
29+
30+
## Exception root causes
31+
32+
* `PyOWMError` is the base class. Never raised directly
33+
* `ConfigurationError` parent class for configuration-related exceptions. Never raised directly
34+
* `ConfigurationNotFoundError` raised when trying to load configuration from a non-existent file
35+
* `ConfigurationParseError` raised when configuration can be loaded from the file but is in a wrong, unparsable format
36+
* `APIRequestError` base class for network/infrastructural issues when invoking OWM APIs
37+
* `BadGatewayError` raised when upstream OWM API backends suffer communication issues.
38+
* `TimeoutError` raised when calls to the API suffer timeout due to slow response times upstream
39+
* `InvalidSSLCertificateError` raised when it is impossible to verify the SSL certificates provided by the OWM APIs
40+
* `APIResponseError` base class for non-ok API responses from OWM APIs
41+
* `NotFoundError` raised when the user tries to access resources that do not exist on the OWM APIs
42+
* `UnauthorizedError` raised when the user tries to access resources she is not authorized to access (eg. you need a paid API subscription)
43+
* `ParseAPIResponseError` raised upon impossibility to parse the JSON payload of API responses
44+
45+
46+
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Global PyOWM library usage examples
2+
3+
The PyOWM library has one main entry point: the `OWM` class. You just need to instantiate it to get started!
4+
5+
Please refer to the `Code Recipes` page, section: `Library initialization`, to get info about how to instantiate
6+
the PyOWM library
7+
8+
9+
10+
## Dumping PyOWM objects to Python dictionaries
11+
PyOWM object instances (eg. `Weather` or `Location` objects) can be dumped to `dict`s:
12+
13+
```python
14+
from pyowm.owm import OWM
15+
owm = OWM('your-api-key')
16+
mgr = owm.weather_manager()
17+
weather = mgr.weather_at_place('London,GB').weather # get the weather at London,GB now
18+
dump_dict = weather.to_dict()
19+
```
20+
21+
This is useful as you can save the dump dictionaries to files (eg. using Pyhon `json` or `pickle` modules)
22+
23+
## Printing objects
24+
Most of PyOWM objects can be pretty-printed for a quick introspection:
25+
26+
```python
27+
from pyowm.owm import OWM
28+
owm = OWM('your-api-key')
29+
print(owm) # <pyowm.weatherapi25.owm25.OWM25 - API key=*******i-key, subscription type=free, PyOWM version=3.0.0>
30+
```
31+
File renamed without changes.
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# PyOWM configuration description
2+
3+
PyOWM can be configured at your convenience.
4+
5+
The library comes with a pre-cooked configuration that you can change according to your needs. The configuration is formulated as a Python dictionary.
6+
7+
## Default configuration
8+
The default config is the `DEFAULT_CONFIG` dict living in the `pyowm.config` module (check it to know the defaults)
9+
10+
## Configuration format
11+
The config dict is formatted as follows:
12+
13+
```
14+
{
15+
"subscription_type": <pyowm.commons.enums.SubscriptionTypeEnum>,
16+
"language": <str>,
17+
"connection": {
18+
"use_ssl": <bool>
19+
"verify_ssl_certs": <bool>>,
20+
"use_proxy": <bool>,
21+
"timeout_secs": <int>
22+
},
23+
"proxies": {
24+
"http": <str>,
25+
"https": <str>
26+
}
27+
}
28+
```
29+
30+
Here are the keys:
31+
32+
* `subscription_type`: this object represents an OWM API Plan subscription. Possible values are: `free|startup|developer|professional|enterprise`
33+
* `language`: 2-char string representing the language you want the weather statuses returned in. Currently serving: `en|ru|ar|zh_cn|ja|es|it|fr|de|pt` and more. Check [here](https://openweathermap.org/current) for a comprehensive list of supported languages
34+
* `connection`:
35+
* `use_ssl`: whether to use SSL or not for API calls
36+
* `verify_ssl_certs`: speaks by itself..
37+
* `use_proxy`: whether to use a proxy server or not (useful if you're eg. in a corporate network). HTTP and SOCKS5 proxies are allowed
38+
* `timeout_secs`: after how many seconds the API calls should be timeouted
39+
* `proxies` (this sub-dict is ignored if `use_proxy == False`)
40+
* `http`: the HTTP URL of the proxy server
41+
* `https`: the HTTPS/SOCKS5 URL of the proxy server
42+
43+
## Providing a custom configuration
44+
You can either pass in your custom dict to the global `OWM` object upon instantiation:
45+
46+
```python
47+
from pyowm import OWM
48+
owm = OWM('my-api-key', config=my_custom_config_dict) # pass in your dict as a named argument
49+
```
50+
51+
or you can put your custom configuration inside a JSON text file and have it read by PyOWM:
52+
53+
```python
54+
from pyowm.owm import OWM
55+
from pyowm.utils.config import get_config_from
56+
config_dict = get_config_from('/path/to/configfile.json') # This utility comes in handy
57+
owm = OWM('your-free-api-key', config_dict)
58+
```
59+
60+
Be aware that the JSON file must be properly formatted and that the unspecified non-mandatory keys will be filled in with default values. Here is an example:
61+
62+
```json
63+
{
64+
"api_key": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
65+
"subscription_type": "professional",
66+
"language": "ru",
67+
"connection": {
68+
"use_ssl": true,
69+
"verify_ssl_certs": true,
70+
"timeout_secs": 1
71+
}
72+
}
73+
```
File renamed without changes.

sphinx/usage-examples-v2/uv-api-usage-examples.md renamed to sphinx/v3/uv-api-usage-examples.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ Please refer to the official API docs for [UV](http://openweathermap.org/api/uvi
99
Getting the data is easy:
1010

1111
```python
12-
uvi = owm.uvindex_around_coords(lat, lon)
12+
from pyowm import OWM
13+
owm = OWM('apikey')
14+
mgr = owm.uvindex_manager()
15+
uvi = mgr.uvindex_around_coords(lat, lon)
1316
```
1417

1518
The query returns an UV Index value entity instance
@@ -20,15 +23,15 @@ The query returns an UV Index value entity instance
2023
As easy as:
2124

2225
```python
23-
uvi_list = owm.uvindex_forecast_around_coords(lat, lon)
26+
uvi_list = mgr.uvindex_forecast_around_coords(lat, lon)
2427
```
2528

2629
### Querying UV index history
2730

2831
As easy as:
2932

3033
```python
31-
uvi_history_list = owm.uvindex_history_around_coords(
34+
uvi_history_list = mgr.uvindex_history_around_coords(
3235
lat, lon,
3336
datetime.datetime(2017, 8, 1, 0, 0),
3437
end=datetime.datetime(2018, 2, 15, 0, 0))

0 commit comments

Comments
 (0)