Nominatim OSM API Module (Legacy)

0.1 · abandoned · verified Thu Apr 16

This Python library, version 0.1, is an unmaintained client module for accessing an OpenStreetMap Nominatim API. Released in 2014, it is designed for Python 2.7. For current Nominatim web service access, `geopy` is recommended. For direct access to a local Nominatim database, the actively maintained `nominatim-api` and `nominatim-db` packages should be used.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use the legacy `nominatim` library to perform reverse geocoding against a *local or self-hosted* Nominatim instance. It highlights the `ReverseGeocoder` class and its `geocode` method. Due to the library's age, the example uses Python 2.7 print syntax and explicitly warns that for modern applications, especially those using the public Nominatim API, `geopy` is the recommended alternative.

import os
from nominatim import ReverseGeocoder

# This legacy library is designed to connect to a self-hosted Nominatim instance.
# The URL would point to your local Nominatim reverse.php endpoint.
# For public Nominatim API, use the 'geopy' library instead.

# Example for a local/self-hosted Nominatim (requires a running Nominatim PHP frontend)
# Note: This code uses Python 2.7 print syntax and assumes a local Nominatim setup.
# To run on modern Python, this example would need significant modification.

try:
    # Assuming a local Nominatim installation available at this URL
    # The actual URL might vary based on your Nominatim server setup.
    # This is illustrative for the *original* library's intended use.
    nominatim_url = os.environ.get('NOMINATIM_LOCAL_URL', 'http://127.0.0.1/nominatim/reverse.php?format=json')
    client = ReverseGeocoder(nominatim_url)
    
    # Example coordinates (Melbourne, Australia)
    latitude = -37.856206
    longitude = 145.233980
    
    print(f"Attempting to reverse geocode {latitude}, {longitude} using legacy nominatim library...")
    response = client.geocode(latitude, longitude)

    if response and 'full_address' in response:
        print(f"Full Address: {response['full_address']}")
    elif response:
        print(f"Raw response (no 'full_address'): {response}")
    else:
        print("No response or error from Nominatim.")

except ImportError:
    print("Error: The 'nominatim' library is not installed or requires Python 2.7.")
except Exception as e:
    print(f"An error occurred: {e}")

# For modern Python and public Nominatim API, consider geopy:
# from geopy.geocoders import Nominatim
# geolocator = Nominatim(user_agent="my-app-name")
# location = geolocator.reverse("52.509669, 13.376294")
# print(location.address)

view raw JSON →