Skip to main content

Unofficial Python wrapper for the BMKG (Meteorology, Climatology, and Geophysical Agency) API.

Project description

bmkg pypi downloads Build Status license BLAZINGLY FAST!!!

Unofficial Python wrapper for the BMKG (Meteorology, Climatology, and Geophysical Agency) API.

Installation

$ pip install bmkg

Examples

Fetching the weather of a specific province
# import the module
import bmkg

import asyncio
import os

async def getweather():
  # declare the client. the measuring unit used defaults to the metric system (celcius, km/h, etc.)
  async with bmkg.Client(unit=bmkg.IMPERIAL) as client:
    # fetch a weather forecast from a province
    weather = await client.get_forecast(bmkg.Province.JAKARTA)
    
    # get the weather forecast across various locations
    for forecast in weather.forecasts:
    
      # temperature of this forecast across various timeframes
      for temp in weather.temperature:
        print(f'temperature at {temp.date!r} is {temp.value!r}')

if __name__ == '__main__':
  # see https://stackoverflow.com/questions/45600579/asyncio-event-loop-is-closed-when-getting-loop
  # for more details
  if os.name == 'nt':
    asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
  
  asyncio.run(getweather())
Fetching the latest earthquake
# import the module
import bmkg

import asyncio
import os

async def getweather():
  # declare the client. the measuring unit used defaults to the metric system (celcius, km/h, etc.)
  async with bmkg.Client(unit=bmkg.IMPERIAL) as client:
    # fetch the latest earthquake
    earthquake = await client.get_latest_earthquake()
    
    print(repr(earthquake))

if __name__ == '__main__':
  # see https://stackoverflow.com/questions/45600579/asyncio-event-loop-is-closed-when-getting-loop
  # for more details
  if os.name == 'nt':
    asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
  
  asyncio.run(getweather())
Fetching the most recent earthquakes magnitude 5 or higher
# import the module
import bmkg

import asyncio
import os

async def getweather():
  # declare the client. the measuring unit used defaults to the metric system (celcius, km/h, etc.)
  async with bmkg.Client(unit=bmkg.IMPERIAL) as client:
    # fetch the most recent earthquakes magnitude 5 or higher
    earthquakes = await client.get_recent_earthquakes()
    
    # iterate through the generator
    for earthquake in earthquakes:
      print(repr(earthquake))

if __name__ == '__main__':
  # see https://stackoverflow.com/questions/45600579/asyncio-event-loop-is-closed-when-getting-loop
  # for more details
  if os.name == 'nt':
    asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
  
  asyncio.run(getweather())
Fetching the most recent earthquakes regardless of their magnitude
# import the module
import bmkg

import asyncio
import os

async def getweather():
  # declare the client. the measuring unit used defaults to the metric system (celcius, km/h, etc.)
  async with bmkg.Client(unit=bmkg.IMPERIAL) as client:
    # fetch the most recent earthquakes regardless of their magnitude
    earthquakes = await client.get_felt_earthquakes()
    
    # iterate through the generator
    for earthquake in earthquakes:
      print(repr(earthquake))

if __name__ == '__main__':
  # see https://stackoverflow.com/questions/45600579/asyncio-event-loop-is-closed-when-getting-loop
  # for more details
  if os.name == 'nt':
    asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
  
  asyncio.run(getweather())

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

bmkg-1.0.4.tar.gz (11.0 kB view details)

Uploaded Source

Built Distribution

bmkg-1.0.4-py3-none-any.whl (16.6 kB view details)

Uploaded Python 3

File details

Details for the file bmkg-1.0.4.tar.gz.

File metadata

  • Download URL: bmkg-1.0.4.tar.gz
  • Upload date:
  • Size: 11.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.3

File hashes

Hashes for bmkg-1.0.4.tar.gz
Algorithm Hash digest
SHA256 8f60ae90a683947c2ef7582d9556530c8efd6ec47c37a8d38b120e3f54ceca15
MD5 26cbbb0558f1bbbec847d81ee3b5c183
BLAKE2b-256 0dcca96e569cfe16ae1255528179c7612aeb94b75c2f28e8945b6e6821c698f5

See more details on using hashes here.

File details

Details for the file bmkg-1.0.4-py3-none-any.whl.

File metadata

  • Download URL: bmkg-1.0.4-py3-none-any.whl
  • Upload date:
  • Size: 16.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.3

File hashes

Hashes for bmkg-1.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 d5b86f4ed4e9f72bf59b4f265bb10d8063ba6daa6e677c2bfa0b6c601c34bc5f
MD5 574ed0508eda9375224ca5c95da6a041
BLAKE2b-256 20acafae260d518716734939b8b5b34d1edb5e92d5e7fc689d80f4b8a4e943d3

See more details on using hashes here.

Supported by

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