Skip to main content

Offline geolocation and geocoding package using SQLite (~200000+ world cities)

Project description

GeoPointDB

Python Version License: MIT

GeoPointDB is a lightweight Python package for fast offline geolocation lookups. It provides an easy way to find city coordinates (latitude and longitude) using a local SQLite database containing approximately 200000+ world cities.

Features

  • Offline First: No internet connection required after installation
  • Fast Lookups: Uses SQLite for efficient querying
  • Simple API: Easy-to-use Python interface
  • Minimal Dependencies: Uses only Python standard library
  • Auto-setup: Automatically initializes the database on first use

Installation

You can install GeoPointDB using pip:

pip install geopointdb

Quick Start

Basic Usage

from geopointdb.getpoint import LatLonFinder

# Initialize the finder (automatically sets up the database on first run)
finder = LatLonFinder()

# Find cities by name (case-insensitive partial match)
cities = finder.find_city('New York')
for city in cities:
    print(f"{city['city']}, {city['country']}: {city['lat']}, {city['lon']}")

# Get coordinates for a specific city
coordinates = finder.get_coordinates('London')
if coordinates:
    lat, lon = coordinates
    print(f"London coordinates: {lat}, {lon}")

# Don't forget to close the connection when done
finder.close()

Using Context Manager

For better resource management, you can use the context manager pattern:

with LatLonFinder() as finder:
    coords = finder.get_coordinates('Tokyo')
    print(f"Tokyo coordinates: {coords}")

API Reference

LatLonFinder Class

__init__(self, db_file=None, csv_file=None)

Initialize the finder with optional custom database or CSV file paths.

  • db_file: Path to SQLite database file (default: worldcities.db in package directory)
  • csv_file: Path to CSV file for initial database creation (if database doesn't exist)

find_city(self, city_name)

Find cities by name (case-insensitive partial match).

  • city_name: Full or partial city name to search for
  • Returns: List of dictionaries containing city information (city, country, lat, lon)

get_coordinates(self, city_name)

Get coordinates for a specific city (exact match).

  • city_name: Exact city name (case-insensitive)
  • Returns: Tuple of (latitude, longitude) or None if not found

close(self)

Close the database connection. Always call this when done with the finder.

Database

The package includes a SQLite database (worldcities.db) with approximately 200000+ world cities. The database is automatically created from the included CSV file on first use if it doesn't exist.

Database Schema

The cities table has the following columns:

  • city: City name
  • country: Country name
  • lat: Latitude (decimal degrees)
  • lon: Longitude (decimal degrees)

Development

Prerequisites

  • Python 3.7+
  • Git

Setup

  1. Clone the repository:

    git clone https://github.com/Pulkit-Py/geopointdb.git
    cd geopointdb
    
  2. Create and activate a virtual environment:

    # Windows
    python -m venv venv
    .\venv\Scripts\activate
    
    # Unix/macOS
    python3 -m venv venv
    source venv/bin/activate
    
  3. Install development dependencies:

    pip install -r requirements-dev.txt
    pip install -e .
    

Running Tests

pytest

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

Support

For support, please open an issue on the GitHub repository.

Acknowledgements

Support

If you found this project helpful, consider:

  • Giving it a ⭐ on GitHub
  • Following me on social media
  • Sharing it with others who might find it useful

Made with ❤️ by Pulkit-Py From 🇮🇳 India

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

geopointdb-1.1.0.tar.gz (5.3 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

geopointdb-1.1.0-py3-none-any.whl (5.3 MB view details)

Uploaded Python 3

File details

Details for the file geopointdb-1.1.0.tar.gz.

File metadata

  • Download URL: geopointdb-1.1.0.tar.gz
  • Upload date:
  • Size: 5.3 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for geopointdb-1.1.0.tar.gz
Algorithm Hash digest
SHA256 7c3de2eda3466e6a1f9305d13e68af0a2e9aec54d5853880e8d7a3ba75b62c7a
MD5 a04fb85032b8e026cff1d291eade08d7
BLAKE2b-256 fd1a40ebc1d9770a99b1ea41ca7417045c87bbffe301db193a703ab489572c06

See more details on using hashes here.

File details

Details for the file geopointdb-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: geopointdb-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.3 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for geopointdb-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 25e49b06ae3e00429f9e2ca5ca74125d8abf25b07b9533a5bf1197a6dc19f6c3
MD5 57d8a5b40a79ec22122572854aab2290
BLAKE2b-256 89a56299939a825361ad0bc3424b2b1d42614fb88106fceea97fb6c9242768ec

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page