Skip to main content

A Python wrapper for the APIs of MeasureSpace.io

Project description

Measure Space API Python Package

A Python package for accessing weather, climate, air quality, and geocoding APIs provided by MeasureSpace.io.

Features

  • Get hourly and daily weather forecasts
  • Get daily climate forecasts
  • Get hourly and daily air quality forecasts
  • Geocoding: convert city names to coordinates and vice versa
  • Unified API call interface with flexible parameters

Installation

Clone the repository and install dependencies:

pip install -e .

Or install from PyPI:

pip install measure-space-api

Usage

Get Weather, Climate and Air Quality Variables

Import the package and call the functions:

from measure_space_api import (
    get_hourly_weather, get_daily_weather, get_daily_climate,
    get_hourly_air_quality, get_daily_air_quality,
    get_lat_lon_from_city, get_city_from_lat_lon
)

# Example: Get hourly weather by coordinates
api_key = "YOUR_API_KEY"
params = {
    # Variable names and meaning can be found at https://measurespace.io/documentation#global-hourly-weather-forecast-variables
    "variables": "tp,t2m",
    "unit": "metric"
}
df = get_hourly_weather(api_key, latitude=40.2, longitude=110.2, params=params, return_json=False)
print(df.head())

# Example: Get hourly weather by city name
geocoding_api_key = "YOUR_GEOCODING_API_KEY"
df = get_hourly_weather(api_key, geocoding_api_key, location_name="Beijing", params=params, return_json=False)
print(df.head())

Get City Coordinates

from measure_space_api.main import get_lat_lon_from_city
lat, lon = get_lat_lon_from_city(geocoding_api_key, "Shanghai")
print(lat, lon)

Use Environment Variables

You may use a .env file to store your API keys and load them with python-dotenv.

HOURLY_WEATHER_API_KEY=your_hourly_weather_key
DAILY_WEATHER_API_KEY=your_daily_weather_key
DAILY_CLIMATE_API_KEY=your_daily_climate_key
AIR_QUALITY_API_KEY=your_air_quality_key
GEOCODING_API_KEY=your_geocoding_key

Call API using API keys from .env file.

from measure_space_api import (
    get_hourly_weather, get_daily_weather, get_daily_climate,
    get_hourly_air_quality, get_daily_air_quality,
    get_lat_lon_from_city, get_city_from_lat_lon
)
from dotenv import load_dotenv
import os

# Load environment variables from .env file
load_dotenv()
# Example: Get hourly weather by coordinates
params = {
    # Variable names and meaning can be found at https://measurespace.io/documentation#global-hourly-weather-forecast-variables
    "variables": "tp,t2m",
    "unit": "metric"
}
df = get_hourly_weather(HOURLY_WEATHER_API_KEY, latitude=40.2, longitude=110.2, params=params, return_json=False)
print(df.head())

API Functions

Weather and Climate

  • get_hourly_weather(api_key, geocoding_api_key=None, location_name=None, latitude=None, longitude=None, params={'variables': 'tp, t2m', 'unit': 'metric'}, return_json=True)
  • get_daily_weather(api_key, geocoding_api_key=None, location_name=None, latitude=None, longitude=None, params={'variables': 'tp, minT, maxT', 'unit': 'metric'}, return_json=True)
  • get_daily_climate(api_key, geocoding_api_key=None, location_name=None, latitude=None, longitude=None, params={'variables': 'tp, tmin, tmax', 'unit': 'metric'}, return_json=True)

Air Quality

  • get_hourly_air_quality(api_key, geocoding_api_key=None, location_name=None, latitude=None, longitude=None, params={'variables': 'AQI, DP'}, return_json=True)
  • get_daily_air_quality(api_key, geocoding_api_key=None, location_name=None, latitude=None, longitude=None, params={'variables': 'AQI'}, return_json=True)

Geocoding

  • get_lat_lon_from_city(api_key, location_name)
  • get_city_from_lat_lon(api_key, latitude, longitude)

Parameters

  • api_key: Your API key for the weather/climate/air quality service
  • geocoding_api_key: (Optional) API key for geocoding service
  • location_name: (Optional) City name (e.g., "New York", "Beijing, China")
  • latitude, longitude: (Optional) Coordinates
  • params: (Optional) Dictionary of additional API parameters (e.g., variables, units, local_flag)
  • return_json: If True, returns JSON; if False, returns a pandas DataFrame

API Documentation

Publish to PyPI

  • uv build
  • uv publish --token <your-pypi-token>

License

Apache License

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

measure_space_api-0.1.2.tar.gz (12.5 kB view details)

Uploaded Source

Built Distribution

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

measure_space_api-0.1.2-py3-none-any.whl (11.0 kB view details)

Uploaded Python 3

File details

Details for the file measure_space_api-0.1.2.tar.gz.

File metadata

  • Download URL: measure_space_api-0.1.2.tar.gz
  • Upload date:
  • Size: 12.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.10

File hashes

Hashes for measure_space_api-0.1.2.tar.gz
Algorithm Hash digest
SHA256 12cf134162843046e46b92fe0cb74ccbcabb46fbc440bbc37efad60ec3b0d3ed
MD5 662d7d6b47e447c02a1cf5af98be5581
BLAKE2b-256 68efa801d965bae0b8c4c822fd97ae3e7f7fca24d1ee1467f351ea3c24b0d622

See more details on using hashes here.

File details

Details for the file measure_space_api-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for measure_space_api-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 2d9da2168d02c627ed5b5daf9849a71392131c5f3ef0127549629aa57cd671bf
MD5 222f72168d904ece9039b3e88b502026
BLAKE2b-256 2dc44788a5ed2d25e1cd033418f3923060028f5ee1ba8a9d09311b4371d2b009

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