PyGeoHash is a Python module that provides functions for encoding and decoding geohashes to and from latitude and longitude coordinates, along with utilities for performing calculations and approximations with them. It is a simple, lightweight, and dependency-free library, with core operations implemented in C for high performance. The current version is 3.2.2, and it maintains an active release cadence, having undergone a major rewrite to v3.0.0 in early 2025, focusing on performance enhancements and a license change, followed by several minor updates.
pip install pygeohashVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to encode latitude/longitude coordinates into geohashes, control precision, decode geohashes back to coordinates, calculate approximate distances between geohashes, and find adjacent geohashes using the `pygeohash` library.
Review your codebase for direct dependencies on Numba/NumPy for `pygeohash`'s core functions. Adapt any license-sensitive usage. The new implementation is significantly faster and dependency-free for core functionality.
Ensure that latitude and longitude inputs are validated to be within their respective bounds (-90 <= lat <= 90, -180 <= lon <= 180) before passing them to `pygeohash` functions.
Always ensure geohash strings are valid before passing them to decoding or validation functions. You can use `pgh.is_valid_geohash(your_geohash_string)` for programmatic checks.
Install `pygeohash` using `pip install pygeohash` and import it as `import pygeohash as pgh` or `from pygeohash import encode, decode`.
Ensure the `latitude` argument passed to `pygeohash.encode()` or `pygeohash.encode_strictly()` is a float within the inclusive range of -90.0 to 90.0.
Provide a non-empty string that consists only of valid base32 geohash characters (0-9, b-h, j-k, m-n, p-z) to `pygeohash.decode()` or `pygeohash.assert_valid_geohash()`.
Set the `precision` argument in `pygeohash.encode()` to an integer value between 1 and 12 (inclusive).
Install the appropriate C/C++ build tools for your operating system (e.g., `sudo apt-get install build-essential` on Debian/Ubuntu, Xcode Command Line Tools on macOS, or Visual C++ Build Tools on Windows).