Metar - Python METAR report parser
Metar is a Python package designed to parse METAR-coded weather reports, providing easy access to various meteorological data points such as wind, temperature, visibility, and cloud conditions. The project recently settled on the package name `metar` (previously `python-metar`). It is currently at version 2.0.1, with an active release cadence, and requires Python >=3.10.
Common errors
-
ModuleNotFoundError: No module named 'python_metar'
cause Attempting to import using the old package name after installing the new `metar` package, or not having the `metar` package installed.fixEnsure you have installed the correct package with `pip install metar` and update your import statements to `from metar.Metar import Metar`. -
TypeError: Metar() got an unexpected keyword argument 'utcdelta'
cause You are passing the `utcdelta` argument to the `Metar` constructor, which was removed in version 2.0.0.fixRemove the `utcdelta` argument from the `Metar` constructor call. The library no longer uses this parameter. -
AttributeError: 'Position' object has no attribute 'getdistance'
cause You are attempting to call the `getdistance` method on a `Position` object, which was removed in version 1.9.0.fixThis method is no longer available. You will need to implement a custom distance calculation if this functionality is required.
Warnings
- breaking The `utcdelta` argument was removed from the `Metar` constructor in version 2.0.0. This was a breaking change.
- breaking The `position.getdistance` API was removed in version 1.9.0 as it was unused and broken.
- gotcha The package name has officially settled on `metar`. While older versions might have been installed as `python-metar`, ensure your `pip install` command and `import` statements use `metar`.
- gotcha The library now officially requires Python 3.10 or newer. Installing on older Python versions will likely result in compatibility errors.
Install
-
pip install metar
Imports
- Metar
from python_metar.Metar import Metar
from metar.Metar import Metar
Quickstart
from metar.Metar import Metar
# Example METAR string
metar_string = "METAR KSLK 200853Z AUTO 09006KT 10SM CLR 02/M01 A2999 RMK AO2"
# Parse the METAR report
m = Metar(metar_string)
# Access parsed data
print(f"Station: {m.station_id}")
print(f"Time: {m.time}")
print(f"Wind: {m.wind_dir}{m.wind_speed}KT")
print(f"Temperature: {m.temp}°C")
print(f"Dew Point: {m.dewpt}°C")
print(f"Visibility: {m.vis.value}{m.vis.units}")
# Print a formatted report
print("\n--- Formatted Report ---")
print(m.string())