Skip to main content

A library to fetch weather data from api.meteo.lt

Project description

Meteo.Lt Lithuanian weather forecast package

GitHub Release GitHub Activity License Project Maintenance Code style: black

Buy Me A Coffee

MeteoLt-Pkg is a Python library designed to fetch weather data from api.meteo.lt. This library provides convenient methods to interact with the API and obtain weather forecasts and related data. Please visit for more information.

Installation

You can install the package using pip:

pip install meteo_lt-pkg

Quick Start

Here's a quick example to get you started:

import asyncio
from meteo_lt import MeteoLtAPI

async def quick_example():
    async with MeteoLtAPI() as api:
        # Get current weather for Vilnius
        forecast = await api.get_forecast("vilnius")
        current = forecast.current_conditions

        print(f"Current temperature in Vilnius: {current.temperature}°C")
        print(f"Condition: {current.condition_code}")
        print(f"Wind: {current.wind_speed} m/s")

        # Check for weather warnings
        warnings = await api.get_weather_warnings("Vilniaus miesto")
        if warnings:
            print(f"Active warnings: {len(warnings)}")
            for warning in warnings:
                print(f"   - {warning.warning_type}: {warning.severity}")
        else:
            print("No active weather warnings")

asyncio.run(quick_example())

Usage

Basic Usage (Recommended)

The recommended way to use the library is with the async with context manager, which ensures proper cleanup of HTTP sessions:

import asyncio
from meteo_lt import MeteoLtAPI

async def main():
    async with MeteoLtAPI() as api:
        # Get weather forecast for Vilnius
        forecast = await api.get_forecast("vilnius")
        print(f"Current temperature in {forecast.place.name}: {forecast.current_conditions.temperature}°C")

        # Get weather warnings for Vilnius
        warnings = await api.get_weather_warnings("Vilniaus miesto")
        print(f"Active warnings: {len(warnings)}")
        for warning in warnings:
            print(f"- {warning.warning_type}: {warning.description}")

asyncio.run(main())

Alternative Usage

If you prefer not to use the context manager, make sure to call close() to properly cleanup resources:

async def alternative_usage():
    api = MeteoLtAPI()
    try:
        forecast = await api.get_forecast("kaunas")
        print(f"Temperature: {forecast.current_conditions.temperature}°C")
    finally:
        await api.close()  # Important: prevents session warnings

asyncio.run(alternative_usage())

Fetching Places

To get the list of available places:

async def fetch_places():
    async with MeteoLtAPI() as api:
        await api.fetch_places()
        for place in api.places:
            print(f"{place.name} ({place.code})")

asyncio.run(fetch_places())

Getting the Nearest Place

You can find the nearest place using latitude and longitude coordinates:

async def find_nearest_place():
    async with MeteoLtAPI() as api:
        # Example coordinates for Vilnius, Lithuania
        nearest_place = await api.get_nearest_place(54.6872, 25.2797)
        print(f"Nearest place: {nearest_place.name}")

asyncio.run(find_nearest_place())

NOTE: If no places are retrieved before, that is done automatically in get_nearest_place method.

Fetching Weather Forecast

To get the weather forecast for a specific place:

async def fetch_forecast():
    async with MeteoLtAPI() as api:
        # Get forecast for Vilnius
        forecast = await api.get_forecast("vilnius")

        # Current conditions
        current = forecast.current_conditions
        print(f"Current temperature: {current.temperature}°C")
        print(f"Feels like: {current.apparent_temperature}°C")
        print(f"Condition: {current.condition_code}")

        # Future forecasts
        print(f"\nNext 24 hours:")
        for timestamp in forecast.forecast_timestamps[:24]:
            print(f"{timestamp.datetime}: {timestamp.temperature}°C")

asyncio.run(fetch_forecast())

NOTE: current_conditions is the current hour record from the forecast_timestamps array. Also, forecast_timestamps array has past time records filtered out due to api.meteo.lt not doing that automatically.

Fetching Weather Forecast with Warnings

To get weather forecast enriched with warnings:

async def fetch_forecast_with_warnings():
    async with MeteoLtAPI() as api:
        # Get forecast with warnings using coordinates
        forecast = await api.get_forecast_with_warnings(
            latitude=54.6872,
            longitude=25.2797
        )

        print(f"Forecast for {forecast.place.name}")
        print(f"Current temperature: {forecast.current_conditions.temperature}°C")

        # Check for warnings in current conditions
        if forecast.current_conditions.warnings:
            print("Current warnings:")
            for warning in forecast.current_conditions.warnings:
                print(f"- {warning.warning_type}: {warning.severity}")

asyncio.run(fetch_forecast_with_warnings())

Fetching Weather Warnings

To get weather warnings for Lithuania or specific administrative areas:

async def fetch_warnings():
    async with MeteoLtAPI() as api:
        # Get all weather warnings
        warnings = await api.get_weather_warnings()
        print(f"Total active warnings: {len(warnings)}")

        for warning in warnings:
            print(f"Warning: {warning.warning_type} in {warning.county}")
            print(f"Severity: {warning.severity}")
            print(f"Description: {warning.description}")
            print(f"Active: {warning.start_time} to {warning.end_time}")
            print("-" * 50)

async def fetch_warnings_for_area():
    async with MeteoLtAPI() as api:
        # Get warnings for specific administrative division
        vilnius_warnings = await api.get_weather_warnings("Vilniaus miesto")
        print(f"Warnings for Vilnius: {len(vilnius_warnings)}")

        for warning in vilnius_warnings:
            print(f"- {warning.warning_type} ({warning.severity})")

asyncio.run(fetch_warnings())
asyncio.run(fetch_warnings_for_area())

Data Models

The package includes several data models to represent the API responses:

Coordinates

Represents geographic coordinates.

from meteo_lt import Coordinates

coords = Coordinates(latitude=54.6872, longitude=25.2797)
print(coords)

Place

Represents a place with associated metadata.

from meteo_lt import Place

place = Place(code="vilnius", name="Vilnius", administrative_division="Vilnius City Municipality", country="LT", coordinates=coords)
print(place.latitude, place.longitude)

ForecastTimestamp

Represents a timestamp within the weather forecast, including various weather parameters.

from meteo_lt import ForecastTimestamp

forecast_timestamp = ForecastTimestamp(
    datetime="2024-07-23T12:00:00+00:00",
    temperature=25.5,
    apparent_temperature=27.0,
    condition_code="clear",
    wind_speed=5.0,
    wind_gust_speed=8.0,
    wind_bearing=180,
    cloud_coverage=20,
    pressure=1012,
    humidity=60,
    precipitation=0
)
print(forecast_timestamp.condition)

Forecast

Represents the weather forecast for a place, containing multiple forecast timestamps.

from meteo_lt import Forecast

forecast = Forecast(
    place=place,
    forecast_created=datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
    forecast_timestamps=[forecast_timestamp]
)
print(forecast.current_conditions().temperature)

WeatherWarning

Represents a weather warning for a specific area.

from meteo_lt import WeatherWarning

warning = WeatherWarning(
    county="Vilniaus apskritis",
    warning_type="frost",
    severity="Moderate",
    description="Ground surface frost 0-5 degrees in many places",
    start_time="2024-07-23T12:00:00Z",
    end_time="2024-07-23T18:00:00Z"
)
print(f"Warning for {warning.county}: {warning.description}")

Contributing

Contributions are welcome! For major changes please open an issue to discuss or submit a pull request with your changes. If you want to contribute you can use devcontainers in vscode for easiest setup follow instructions here.


Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

meteo_lt_pkg-0.5.0b0.tar.gz (14.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

meteo_lt_pkg-0.5.0b0-py3-none-any.whl (13.7 kB view details)

Uploaded Python 3

File details

Details for the file meteo_lt_pkg-0.5.0b0.tar.gz.

File metadata

  • Download URL: meteo_lt_pkg-0.5.0b0.tar.gz
  • Upload date:
  • Size: 14.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for meteo_lt_pkg-0.5.0b0.tar.gz
Algorithm Hash digest
SHA256 901693d26e792edc9b6422676fab6f22dd1f410d912b79a265c8ef38deaf82f4
MD5 1fcda184f88bec05152006bb68eff877
BLAKE2b-256 5edaf582089079db831f38cdf8bb11b4b38ea9d49e7afb2dbcb3d36eb242eda3

See more details on using hashes here.

File details

Details for the file meteo_lt_pkg-0.5.0b0-py3-none-any.whl.

File metadata

  • Download URL: meteo_lt_pkg-0.5.0b0-py3-none-any.whl
  • Upload date:
  • Size: 13.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for meteo_lt_pkg-0.5.0b0-py3-none-any.whl
Algorithm Hash digest
SHA256 c4395aafe4de92aec2668acf1e82193961f6c5fa4cb7bff9fdfb2b739af6e493
MD5 9ccc17e5df963f57ea83e7ea55c3d6fe
BLAKE2b-256 581e3d7b887ede23c66945a8974240b2bb6c114480f857690d7a8c54e0eac6c1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page