Easy access to the meteoblue dataset API
Project description
meteoblue Python Dataset SDK
This library simplifies access to the meteoblue dataset API.
In order to use this library you need a meteoblue API key.
Features:
- Fetch any dataset from the meteoblue environmental data archive
- Transparently integrates job queues to query large datasets
- Efficiently transfers data using compressed protobuf messages
- Asynchronous interface to query data in parallel
- Data can be used as simple floating-point arrays. No further formatting required.
- Semantic Versioning: The interface for version 1 is declared stable. Breaking interface changes will be published in version 2.
Installation
- Ensure that you are using at least Python 3.7 with
python --version
(Sometimespython3
) - Install the module with
pip install 'meteoblue_dataset_sdk >=1.0,<2.0'
(Sometimespip3
)
This module will also install the following dependencies automatically:
- aiohttp >=3.6,<4
- protobuf >=3.0,<4
Usage
See main.py for a working example. To generate the query JSON it is highly recommended to use the dataset API web interfaces.
import meteoblue_dataset_sdk
import logging
# Display information about the current download state
logging.basicConfig(level=logging.INFO)
query = {
"units": {
"temperature": "C",
"velocity": "km/h",
"length": "metric",
"energy": "watts",
},
"geometry": {
"type": "MultiPoint",
"coordinates": [[7.57327, 47.558399, 279]],
"locationNames": ["Basel"],
},
"format": "protobuf",
"timeIntervals": ["2019-01-01T+00:00/2019-01-01T+00:00"],
"timeIntervalsAlignment": "none",
"queries": [
{
"domain": "NEMSGLOBAL",
"gapFillDomain": None,
"timeResolution": "hourly",
"codes": [{"code": 11, "level": "2 m above gnd"}],
}
],
}
client = meteoblue_dataset_sdk.Client(apikey="xxxxxx")
result = client.querySync(query)
# result is a structured object containing timestamps and data
timeInterval = result.geometries[0].timeIntervals[0]
data = result.geometries[0].codes[0].timeIntervals[0].data
print(timeInterval)
# start: 1546300800
# end: 1546387200
# stride: 3600
NOTE: timeInterval.end
is the first timestamp that is not included anymore in the time interval.
If your code is using async/await
, you should use await client.query()
instead of client.querySync()
. Asynchronous IO is essential for modern webserver frameworks like Flask or FastAPI.
client = meteoblue_dataset_sdk.Client(apikey="xxxxxx")
result = await client.query(query)
Protobuf format
Data is transferred using protobuf and defined as this protobuf structure.
A 10 year hourly data series for 1 location requires 350 kb
using protobuf, compared to 1600 kb
using JSON. Additionally the meteoblue Python SDK transfers data using gzip which reduces the size to only 87 kb
.
More detailed output of the result
protobuf object:
geometries {
domain: "NEMSGLOBAL"
lats: 47.66651916503906
lons: 7.5
asls: 499.7736511230469
locationNames: "Basel"
nx: 1
ny: 1
timeResolution: "hourly"
timeIntervals {
start: 1546300800
end: 1546387200
stride: 3600
}
codes {
code: 11
level: "2 m above gnd"
unit: "\302\260C"
aggregation: "none"
timeIntervals {
data: 2.890000104904175
data: 2.690000057220459
data: 2.549999952316284
data: 2.380000114440918
data: 2.2699999809265137
data: 2.119999885559082
data: 1.9900000095367432
data: 1.8300000429153442
data: 1.8200000524520874
data: 2.0999999046325684
data: 2.430000066757202
data: 2.9200000762939453
data: 3.7200000286102295
data: 3.930000066757202
data: 3.9100000858306885
data: 3.5299999713897705
data: 3.130000114440918
data: 2.880000114440918
data: 2.6500000953674316
data: 2.4600000381469727
data: 2.2799999713897705
data: 2.0299999713897705
data: 1.690000057220459
data: 1.3799999952316284
}
}
}
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for meteoblue_dataset_sdk-1.0.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | bea544e3b102065224d291b750ad10248e3adf5abac7db03d4d061aa829e7ab5 |
|
MD5 | 606ac787b9618d8f4cc1785fa3baea85 |
|
BLAKE2b-256 | 0db9cd00fd20ed56341aa7fcfd746518c3cc404672ee81cf325709a27c87e3c7 |
Hashes for meteoblue_dataset_sdk-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5016de37c7b8dfe5b4df0f7243795138590177776b139685e7d1bb924eb3ee87 |
|
MD5 | cfdc5e0eb0b60590cec910e94a1055b8 |
|
BLAKE2b-256 | 93169e0c2b4983aeeb8a579d8e6c912764384d8cfcb2670c810d6af6ef54db54 |