{"id":2689,"library":"pygeohash","title":"Pygeohash","description":"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.","status":"active","version":"3.2.2","language":"en","source_language":"en","source_url":"https://github.com/wdm0006/pygeohash","tags":["geohash","geolocation","encoding","decoding","spatial-indexing","gis"],"install":[{"cmd":"pip install pygeohash","lang":"bash","label":"Basic Installation"},{"cmd":"pip install pygeohash[viz]","lang":"bash","label":"With Visualization Support"}],"dependencies":[{"reason":"Required for static geohash visualization functions if `[viz]` extra is installed.","package":"matplotlib","optional":true},{"reason":"Required for interactive geohash map visualizations if `[viz]` extra is installed.","package":"folium","optional":true}],"imports":[{"note":"The `pygeohash` library is a modern Python 3 compatible, dependency-free alternative to older, often Python 2-only, 'geohash' modules. Importing `geohash` directly will likely lead to an ImportError or an outdated, incompatible library.","wrong":"import geohash","symbol":"pygeohash","correct":"import pygeohash as pgh"}],"quickstart":{"code":"import pygeohash as pgh\n\n# Encode coordinates to a geohash string\nlatitude = 42.6\nlongitude = -5.6\ngeohash_full = pgh.encode(latitude, longitude)\nprint(f\"Full geohash: {geohash_full}\") # e.g., 'ezs42e44yx96'\n\n# Encode with custom precision (e.g., 5 characters)\ngeohash_short = pgh.encode(latitude, longitude, precision=5)\nprint(f\"Short geohash: {geohash_short}\") # e.g., 'ezs42'\n\n# Decode a geohash string back to coordinates\ndecoded_lat, decoded_lng = pgh.decode(geohash_short)\nprint(f\"Decoded: Latitude={decoded_lat}, Longitude={decoded_lng}\") # e.g., Latitude=42.6, Longitude=-5.6\n\n# Calculate approximate distance between two geohashes (in meters)\ndistance = pgh.geohash_approximate_distance('bcd3u', 'bc83n')\nprint(f\"Approximate distance: {distance} meters\") # e.g., 625441\n\n# Find an adjacent geohash\nadjacent_geohash = pgh.get_adjacent(geohash='kd3ybyu', direction='right')\nprint(f\"Adjacent geohash (right): {adjacent_geohash}\") # e.g., 'kd3ybyv'","lang":"python","description":"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."},"warnings":[{"fix":"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.","message":"PyGeoHash v3.0.0 introduced a complete rewrite of the core logic in CPython, removing previous dependencies like Numba and NumPy for core geohashing operations. The library also switched from a GPL-3.0 to an MIT license. Code relying on specific Numba/NumPy accelerated variants or the previous GPL license might break or behave differently.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"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.","message":"Input coordinates must be within valid geographical ranges: latitude between -90.0 and 90.0 degrees, and longitude between -180.0 and 180.0 degrees. Providing values outside these ranges will result in a `ValueError` for functions like `encode` and `encode_strictly`.","severity":"gotcha","affected_versions":"All"},{"fix":"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.","message":"Geohash strings must adhere to the base32 character set (0-9, b-h, j-k, m-n, p-z) and be between 1 and 12 characters long. Functions like `decode`, `decode_exactly`, and validation utilities (e.g., `assert_valid_geohash`) will raise a `ValueError` for invalid geohash formats (e.g., empty string, invalid characters, or excessive length).","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-04-10T00:00:00.000Z","next_check":"2026-07-09T00:00:00.000Z"}