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

Usage

Initializing the API Client To start using the library, you need to initialize the MeteoLtAPI client:

from meteo_lt import MeteoLtAPI

api_client = MeteoLtAPI()

Fetching Places

To get the list of available places:

import asyncio

async def fetch_places():
    await api_client.fetch_places()
    for place in api_client.places:
        print(place)

asyncio.run(fetch_places())

Getting the Nearest Place

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

async def find_nearest_place(latitude, longitude):
    nearest_place = await api_client.get_nearest_place(latitude, longitude)
    print(f"Nearest place: {nearest_place.name}")

 # Example coordinates for Vilnius, Lithuania
asyncio.run(find_nearest_place(54.6872, 25.2797))

Also, 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, use the get_forecast method with the place code:

async def fetch_forecast(place_code):
    forecast = await api_client.get_forecast(place_code)
    current_conditions = forecast.current_conditions()
    print(f"Current temperature: {current_conditions.temperature}°C")

# Example place code for Vilnius, Lithuania
asyncio.run(fetch_forecast("vilnius"))

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.

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)

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.2.2b0.tar.gz (6.8 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.2.2b0-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: meteo_lt_pkg-0.2.2b0.tar.gz
  • Upload date:
  • Size: 6.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.9

File hashes

Hashes for meteo_lt_pkg-0.2.2b0.tar.gz
Algorithm Hash digest
SHA256 5479dc8a8425797369903522e9554a258bcb13869043e85ea5c3952259e9d1eb
MD5 a90916b44d532c51703c1f9857495360
BLAKE2b-256 62aa743c5393c53ed02ebdcc966a80da738b40e7adcdc304f0df2373b0c023a2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: meteo_lt_pkg-0.2.2b0-py3-none-any.whl
  • Upload date:
  • Size: 7.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.9

File hashes

Hashes for meteo_lt_pkg-0.2.2b0-py3-none-any.whl
Algorithm Hash digest
SHA256 bfbb10b008389d20107c3c39d08e7ecaf1bbfbd5df7891872835afe885272a95
MD5 81d4b457acec1000b0f5698ee3fda933
BLAKE2b-256 81b199e89757f7657e0463b56abc8ff53adab4020edd838bd9651b07beeaccd3

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