Configuration
The Meteostat Python library allows you to customize its behavior through a configuration system. You can set various options that affect how data is retrieved, cached, and processed. The configuration can be modified at runtime using the meteostat.config module.
🚀 Example
import meteostat as ms
# Set the cache directory
ms.config.cache_directory = '/path/to/cache'
# Now all data will be cached in the specified directory
# Your code here
🔍 API
Interface
meteostat.config
Properties
prefix
The prefix (without the underscore) which is used when parsing environment variables.
Data Type
str
Default Value
"MS"
block_large_requests
Block requests that are considered large (e.g., requesting data for a very long time period or many stations at once).
Data Type
bool
Default Value
True
cache_enable
Enable or disable caching of data.
Data Type
bool
Default Value
True
cache_directory
Directory path where cached data will be stored.
Data Type
str
Default Value
~/.meteostat/cache
cache_ttl
The maximum time-to-live for cached data in seconds. After this period, cached data will be considered stale and will be refreshed upon the next request.
This is the global maximum TTL for all cached data. Most data retrieval methods have their own specific TTL settings that override this global value. The value is typically lowered for data that changes frequently, such as recent weather observations, and increased for static data, such as station metadata.
Data Type
int
Default Value
2592000 (30 days)
cache_autoclean
Automatically clean up expired cache files when accessing the cache.
Data Type
bool
Default Value
True
network_proxies
Dictionary of proxy servers to use for network requests.
Data Type
Optional[Dict[str, str]]
Default Value
None
stations_db_ttl
The time-to-live for the local SQLite stations database in seconds. After this period, the database will be refreshed upon the next request.
Data Type
int
Default Value
604800 (7 days)
stations_db_urls
URLs to download the local SQLite stations database from. Multiple URLs can be specified and will be tried in order if the download from the first URL fails.
Data Type
List[str]
Default Value
[
"https://data.meteostat.net/stations.db",
"https://raw.githubusercontent.com/meteostat/weather-stations/main/stations.db"
]
stations_db_file
Path to the local SQLite stations database file.
Data Type
str
Default Value
~/.meteostat/stations.db
lapse_rate_parameters
List of temperature parameters that will have lapse rate adjustment applied during interpolation.
Data Type
List[Parameter]
Default Value
[
Parameter.TEMP,
Parameter.TMIN,
Parameter.TMAX
]
include_model_data
Include model data (e.g. reanalysis or weather forecast models) when retrieving data from Meteostat's default data providers.
Data Type
bool
Default Value
True
hourly_endpoint
The endpoint URL for retrieving hourly data from Meteostat's default data providers.
Data Type
str
Default Value
https://data.meteostat.net/hourly/{year}/{station}.csv.gz
daily_endpoint
The endpoint URL for retrieving daily data from Meteostat's default data providers.
Data Type
str
Default Value
https://data.meteostat.net/daily/{year}/{station}.csv.gz
monthly_endpoint
The endpoint URL for retrieving monthly data from Meteostat's default data providers.
Data Type
str
Default Value
https://data.meteostat.net/monthly/{station}.csv.gz
dwd_ftp_host
The FTP host for DWD data downloads.
Data Type
str
Default Value
"opendata.dwd.de"
dwd_hourly_modes
DWD differentiates between recent and historical hourly data. This setting specifies which mode(s) to use when retrieving hourly data from DWD.
Data Type
Optional[List[str]]
Default Value
None (both modes if applicable)
dwd_daily_modes
DWD differentiates between recent and historical daily data. This setting specifies which mode(s) to use when retrieving daily data from DWD.
Data Type
Optional[List[str]]
Default Value
None (both modes if applicable)
dwd_monthly_modes
DWD differentiates between recent and historical monthly data. This setting specifies which mode(s) to use when retrieving monthly data from DWD.
Data Type
Optional[List[str]]
Default Value
None (both modes if applicable)
aviationweather_endpoint
The endpoint URL for NOAA's Aviation Weather Center API.
Data Type
str
Default Value
(
"https://aviationweather.gov/api/data/metar?"
"ids={station}&format=raw&taf=false&hours=24"
)
aviationweather_user_agent
The use agent to send when accessing data from NOAA's Aviation Weather Center API.
Data Type
Optional[str]
Default Value
None
metno_forecast_endpoint
The endpoint URL for Met.no's weather forecast API.
Data Type
str
Default Value
(
"https://api.met.no/weatherapi/locationforecast/2.0/compact?"
"lat={latitude}&lon={longitude}&altitude={elevation}"
)
metno_user_agent
The use agent to send when accessing data from Met.no's APIs.
You must send a user agent containing your contact information (e.g. E-Mail address) as per Met.no's terms of service.
Data Type
Optional[str]
Default Value
None
Methods
get_env_name
Get the full name of the environment variable (including prefix) which can be used to set this configuration key.
Attributes
| Attribute | Description | Type | Default |
|---|---|---|---|
key | The key of the configuration option | str |
Return Value
str
load_env
Parse environment variables and update the configuration accordingly.
Return Value
None