Registry / data / reverse-geocode

reverse-geocode

JSON →
library1.6.6pypypi✓ verified 87d ago

Reverse Geocode is a Python library (current version 1.6.6) for offline reverse geocoding. It translates latitude/longitude coordinates into the nearest known country, state, and city using a k-d tree structure built from GeoNames data. This is particularly useful for batch processing a large number of coordinates without relying on external web APIs. The project maintains an infrequent release cadence.

pip install reverse-geocode
INSTALL
IMPORT
SIG · REVERSE-GEOCODE
R
reverse-geocode
datapythonv1.6.6
Install
7.3s avg
Import
1295ms
Disk
233MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.6.6 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 1.333s · 234MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 7.3s · import 1.257s · 225MB
233MB installed
● package 233MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

reverse_geocode
import reverse_geocode
from reverse_geocode import search
The primary functions `search` and `get` are typically accessed directly as methods of the imported module object.

This quickstart demonstrates how to perform reverse geocoding for both single and multiple latitude/longitude coordinates using the `get()` and `search()` functions, respectively. The results include country code, city, latitude, longitude, population, state, and country.

import reverse_geocode # Example for a single coordinate melbourne_coord = (-37.81, 144.96) result_single = reverse_geocode.get(melbourne_coord) print(f"Single result: {result_single}") # Example for multiple coordinates coordinates = ( (40.71427000, -74.00597000), # New York City (-37.81, 144.96) # Melbourne ) results_batch = reverse_geocode.search(coordinates) print(f"Batch results: {results_batch}")
Debug
Known issues
gotchaAccuracy Limitation: This library performs point-based lookups using a k-d tree and GeoNames data, not polygon-based lookups. As such, it provides an *approximate* location (nearest known city, state, country) rather than a precise address, which may not be suitable for applications requiring high geocoding precision.
fix
For precise address-level reverse geocoding, consider using external API-based solutions like Geoapify, Geocodio, or Google Maps Platform.
affects: All versions
gotchaData Source Limitations: By default, the K-D tree is populated with cities from GeoNames having a population greater than 1000. This means smaller towns or very specific points might not be accurately resolved. For custom or more granular data sources, a specific CSV format (`lat`, `lon`, `name`, `admin1`, `admin2`, `cc`) must be provided.
fix
If default data is insufficient, prepare a custom CSV file with the required header and columns, then initialize the geocoder with it using `rg.RGeocoder(stream=io.StringIO(open('custom_source.csv', encoding='utf-8').read()))` (requires importing `io`).
affects: All versions
gotchaPotential SciPy Dependency Conflict: A related project, `reverse_geocoder_whl` (an improvement upon this library), noted a breaking change in SciPy 1.11, requiring `scipy < 1.11` for compatibility. While not explicitly stated for `reverse-geocode` itself, users might encounter compatibility issues or errors with newer SciPy versions due to shared underlying algorithms and data structures.
fix
If errors related to SciPy arise, try downgrading your SciPy installation to a version below 1.11, e.g., `pip install 'scipy<1.11'`.
affects: All versions when using SciPy >= 1.11
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'reverse_geocode'
The `reverse-geocode` library has not been installed in your current Python environment.
fix
Install the library using pip: `pip install reverse-geocode`
TypeError: 'float' object is not iterable
The `reverse_geocode.search()` method expects an iterable of (latitude, longitude) tuples, even if you are querying only one coordinate. Passing single float values directly will result in this error. The `get()` method expects a single (latitude, longitude) tuple.
fix
For `search()`, pass a list or tuple of coordinate tuples, e.g., `reverse_geocode.search([(lat, lon)])` for one, or `reverse_geocode.search([(lat1, lon1), (lat2, lon2)])` for multiple. For `get()`, pass a single coordinate tuple, e.g., `reverse_geocode.get((lat, lon))`.
Output includes: 'Loading formatted geocoded file...'
This is not an error but a normal verbose message indicating that the library is loading its internal GeoNames data into memory. This typically happens only on the first call to a geocoding function within a Python session.
fix
No fix is required as this is expected behavior. The message will not appear on subsequent calls unless the `RGeocoder` instance is re-initialized.
Upgrade
Version history
1.6.6latest on PyPI · released May 15, 2025
Audit
Dependencies
scipyrequiredUsed for K-D tree implementation to efficiently find nearest neighbors.
numpyrequiredFundamental package for numerical computing in Python, often used with SciPy for array operations.
Agent activity
10 hits · last 30 days
node
8
Amazon
1
OpenAI (training)
1
Resources
reverse-geocode — pip install reverse-geocode · libregistry