{"id":9770,"library":"geolib","title":"geolib - Geohash encoding and decoding","description":"geolib is a Python library providing functionality for geohash encoding, decoding, and associated operations like bounding box calculation. It is currently at version 1.0.7 and has a relatively stable, infrequent release cadence, indicating a mature and well-defined feature set.","status":"active","version":"1.0.7","language":"en","source_language":"en","source_url":"https://github.com/joyanujoy/geolib","tags":["geohash","geospatial","location","coordinates"],"install":[{"cmd":"pip install geolib","lang":"bash","label":"Install stable version"}],"dependencies":[],"imports":[{"note":"The primary geohash functions (encode, decode, bbox) reside within the 'geohash' submodule, not directly on the top-level 'geolib' module.","wrong":"import geolib; geolib.encode(...)","symbol":"geohash","correct":"from geolib import geohash"}],"quickstart":{"code":"from geolib import geohash\n\n# Example: Encode latitude and longitude into a geohash string\nlatitude = 39.04\nlongitude = -77.48\nprecision = 9 # Desired geohash length\n\nencoded_hash = geohash.encode(latitude, longitude, precision)\nprint(f\"Encoded geohash for ({latitude}, {longitude}) with precision {precision}: {encoded_hash}\")\n\n# Example: Decode a geohash string back to latitude and longitude\ndecoded_lat, decoded_lon = geohash.decode(encoded_hash)\nprint(f\"Decoded coordinates from {encoded_hash}: Latitude={decoded_lat}, Longitude={decoded_lon}\")\n\n# Example: Get the bounding box for a geohash\nbbox_coords = geohash.bbox(encoded_hash)\nprint(f\"Bounding box for {encoded_hash}: {bbox_coords}\")","lang":"python","description":"This quickstart demonstrates encoding geographical coordinates into a geohash, decoding a geohash back to coordinates, and calculating the bounding box for a given geohash string."},"warnings":[{"fix":"Carefully choose the `precision` value (typically an integer between 1 and 12) based on the required spatial resolution for your application. Higher precision means a longer geohash and greater detail.","message":"The `precision` parameter in `geohash.encode()` directly controls the length and granularity of the resulting geohash. An incorrect precision can lead to hashes that are either too coarse for the desired accuracy or unnecessarily long, impacting storage and comparison efficiency.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Always be mindful of the expected return type for each `geohash` function and destructure/access results accordingly. For `decode`, expect `lat, lon = geohash.decode(...)`; for `bbox`, expect `box_dict = geohash.bbox(...)`.","message":"The return types for core functions vary: `geohash.encode` returns a string, `geohash.decode` returns a tuple `(latitude, longitude)`, and `geohash.bbox` returns a dictionary with 'n', 's', 'e', 'w' keys for the bounding box corners. This inconsistency can lead to type errors if not handled explicitly.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Prioritize using `geolib` with Python 3. If Python 2 compatibility is absolutely required, ensure all string inputs are consistently handled (e.g., explicitly converted to unicode) and thoroughly test all geohash operations.","message":"While `geolib` officially supports Python >=2.7 (excluding 3.0-3.3), using it with Python 2.x in new projects is strongly discouraged. Encoding/decoding issues related to string types (unicode vs bytes) or default encodings can arise more easily in Python 2 environments, leading to subtle bugs.","severity":"gotcha","affected_versions":"<=1.0.7 on Python 2.x"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"Import the 'geohash' submodule explicitly: `from geolib import geohash`. Then, call functions as `geohash.encode(...)`, `geohash.decode(...)`, etc.","cause":"Users often attempt to call geohash functions directly on the top-level 'geolib' module after `import geolib`, instead of accessing them through the 'geohash' submodule.","error":"AttributeError: module 'geolib' has no attribute 'encode'"},{"fix":"Ensure that `latitude` and `longitude` variables are converted to `float` or `int` before being passed to `geohash.encode()`. Example: `geohash.encode(float(lat_str), float(lon_str), precision)`.","cause":"Latitude and longitude values passed to `geohash.encode()` are strings instead of the expected numeric types (float or int).","error":"TypeError: float argument required, not str"}]}