A comprehensive Python wrapper around OpenWeatherMap web APIs providing weather data, forecasts, air pollution, UV index, and agricultural information
—
Direct and reverse geocoding for converting between place names and geographic coordinates. Enables location resolution for weather API calls and geographic data processing.
class GeocodingManager:
def geocoding_api_version(self) -> tuple:
"""
Get Geocoding API version.
Returns:
Tuple representing the API version
"""
def geocode(self, toponym: str, country: str = None, state_code: str = None, limit: int = None) -> List[Location]:
"""
Convert place names to coordinates.
Parameters:
- toponym: Place name to geocode
- country: Two-letter country code (ISO 3166) for filtering
- state_code: Two-letter state code (US only) for filtering
- limit: Maximum number of results
Returns:
List of Location objects matching the query
"""class GeocodingManager:
def reverse_geocode(self, lat: float, lon: float, limit: int = None) -> List[Location]:
"""
Convert coordinates to place names.
Parameters:
- lat: Latitude (-90.0 to 90.0)
- lon: Longitude (-180.0 to 180.0)
- limit: Maximum number of results
Returns:
List of Location objects for the coordinates
"""from pyowm import OWM
owm = OWM('your-api-key')
geo_mgr = owm.geocoding_manager()
# Direct geocoding
locations = geo_mgr.geocode('London', country='GB', limit=5)
for loc in locations:
print(f"{loc.name}, {loc.country}: {loc.lat}, {loc.lon}")
# Reverse geocoding
locations = geo_mgr.reverse_geocode(51.5074, -0.1278, limit=3)
for loc in locations:
print(f"{loc.name}, {loc.country}")Install with Tessl CLI
npx tessl i tessl/pypi-pyowm