Geonames Cache

3.0.1 · active · verified Sun Apr 12

geonamescache is a Python library that provides quick access to a subset of GeoNames data. It allows retrieval of names, ISO and FIPS codes for continents, countries, US states, US counties, and cities as Python dictionaries. The country and city datasets also include population and geographic data. The library is actively maintained, with regular updates and a consistent release cadence, including a recent patch release (3.0.1) in March 2026.

Warnings

Install

Imports

Quickstart

Initialize GeonamesCache and retrieve data for continents, countries, and cities. The `min_city_population` parameter can be adjusted to include more or fewer cities. Demonstrates how to access specific country data and search for cities by name.

from geonamescache import GeonamesCache

gc = GeonamesCache(min_city_population=1000)

continents = gc.get_continents()
print(f"Number of continents: {len(continents)}")

countries = gc.get_countries()
print(f"Number of countries: {len(countries)}")

cities = gc.get_cities()
print(f"Number of cities (min_population=1000): {len(cities)}")

# Example: Get data for a specific country (Spain)
spain_data = gc.get_countries().get('ES')
if spain_data:
    print(f"\nSpain data: {spain_data['name']} (Population: {spain_data.get('population')})")

# Example: Search for cities by name
london_cities = gc.search_cities('London')
print(f"\nFound {len(london_cities)} cities named 'London':")
for city in london_cities[:3]: # Print first 3 results
    print(f"- {city['name']}, {city['countrycode']} (Population: {city['population']})")

view raw JSON →