Skip to main content

LocatePy

LocatePy is a lightweight, fast reverse-geolocation utility for Python.
It maps latitude/longitude coordinates to administrative boundaries using a prebuilt SQLite database with R-Tree spatial indexing and compressed WKB geometries for exact geometry verification.

This project is designed to be:

  • Fast — minimal dependencies, only Shapely
  • Lightweight — SQLite + compressed geometries
  • Offline-first — no API calls, no internet required

Features

  • Reverse geolocation from (lat, lon) → Country / District / Municipal
  • Spatial lookup via SQLite R-Tree
  • Geometry checks powered by Shapely
  • Compressed WKB for efficient storage
  • Simple API
  • Data for geolocation provided by geoboundaries.org

Usage

Basic Example

from locatepy.locatepy import LocatePy

locator = LocatePy()
result = locator.locate(lat=43.6532, lon=-79.3832)

print(result.country) # Canada
print(result.district) # Ontario
print(result.municipal) # Toronto

Returned Object

locate() returns a LocateResult dataclass:

LocateResult(
    country: str,    # ADM0
    district: str,   # ADM1
    municipal: str   # ADM2
)

If no match is found:

LocateResult("UNKNOWN", "UNKNOWN", "UNKNOWN")

Installation

pip install locatepy

Dependencies

LocatePy requires:

  • Python 3.9+
  • shapely
  • Ships with a prebuilt SQLite database

Geometry Storage

  • Municipal geometries stored as zlib-compressed WKB
  • Bounding boxes stored in the R-Tree (minx, maxx, miny, maxy)

How It Works

  1. A Point(lon, lat) is created using Shapely
  2. The SQLite R-Tree is queried for candidate municipalities
  3. Candidate geometries are:
    • Decompressed from zlib
    • Loaded from WKB
  4. A precise shapely covers test determines containment
  5. The matching admin hierarchy is returned

This approach avoids expensive full-table scans and keeps memory usage low.

Performance Notes

  • R-Tree bounding box filtering reduces geometry checks dramatically
  • Geometry decompression occurs only for candidate matches
  • No internet connection required

Limitations

  • Resolution and accuracy depend entirely on the source boundary data provided by geoboundaries.org
  • Does not currently support:
    • Reverse geocoding to street/address level
    • Multi-match results
    • Assumes WGS84

License

MIT License

LocatePy — simple, fast, offline reverse geolocation.

Metadata

Release files for locatepy 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for locatepy 1.0.0
File Size Uploaded Provenance Actions
locatepy-1.0.0.tar.gz 79.9 MB Without provenance Details for locatepy-1.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for locatepy 1.0.0
File Interpreter ABI Platform Actions
locatepy-1.0.0-py3-none-any.whl Python 3 none any Details for locatepy-1.0.0-py3-none-any.whl

Total release size: 159.9 MB

Release files / locatepy-1.0.0.tar.gz

Download URL locatepy-1.0.0.tar.gz
Size 79.9 MB
Tags Source
SHA-256 checksum
How to use checksums
7189c78984a394434e5b753731cd4b91dd57a844bfcc652c5beeef0a6730f393
BLAKE2b-256 checksum
How to use checksums
3e66145420dd129534049bbb005b014c27a5669fbb8f8679a77d9b4ec091273f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.3

Release files / locatepy-1.0.0-py3-none-any.whl

Download URL locatepy-1.0.0-py3-none-any.whl
Size 79.9 MB
Tags Python 3
SHA-256 checksum
How to use checksums
95b35ae97117520c0337441a827a945963184ebad1420767ab7990dd9ff528fd
BLAKE2b-256 checksum
How to use checksums
3fec2d2a2d263bb6bedae07dea6ad4173dad414f39ed89efa451403782944951
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.3

Security for locatepy 1.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page