Skip to main content

A Python-wrapped Rust Location Checker

Project description

Public README for location_checker Package


location_checker

A Python extension module for geographic operations, including country lookups, Haversine distance calculations, and travel time verification. This module is implemented in Rust using the pyo3 library for Python bindings, offering high performance and reliability.

Features

  • Country Lookup: Identify the country (or countries) corresponding to a given latitude and longitude.
  • Distance Calculation: Calculate the Haversine distance between two locations.
  • Travel Time Verification: Verify if travel between two locations is feasible within a specified time based on a realistic speed limit.

Installation

To build and install the package, you need Rust and Python installed on your system. Install the package using:

pip install maturin
maturin develop

Alternatively, for a production build:

maturin build
pip install ./target/wheels/location_checker-*.whl

Usage

Here’s an example demonstrating how to use the location_checker module:

Example

from location_checker import Location, LocationChecker

# Initialize the LocationChecker
checker = LocationChecker()

# Load the country boundaries
checker.load_boundaries()

# Define locations
loc1 = Location(latitude=37.7749, longitude=-122.4194, timestamp="2024-12-01T10:00:00Z")  # San Francisco
loc2 = Location(latitude=34.0522, longitude=-118.2437, timestamp="2024-12-01T14:00:00Z")  # Los Angeles

# Get the country of a location
countries = checker.get_country(loc1)
print(f"San Francisco is in: {countries}")

# Calculate the distance between two locations
distance = checker.calculate_distance(loc1, loc2)
print(f"Distance between San Francisco and Los Angeles: {distance:.2f} meters")

# Verify travel feasibility
feasible = checker.verify_travel_time(loc1, loc2)
print(f"Is it feasible to travel between San Francisco and Los Angeles in the given time? {feasible}")

API Documentation

Location

Represents a geographic location.

  • Location(latitude: float, longitude: float, timestamp: Optional[str] = None)
    • latitude: Latitude in degrees (-90 to 90).
    • longitude: Longitude in degrees (-180 to 180).
    • timestamp: Optional RFC3339 formatted datetime string.

LocationChecker

Performs operations related to locations.

  • load_boundaries() -> None

    • Loads country boundaries into memory.
  • get_country(location: Location) -> List[str]

    • Identifies the country (or countries) for a given location.
  • calculate_distance(location1: Location, location2: Location) -> float

    • Calculates the Haversine distance between two locations (in meters).
  • verify_travel_time(start_location: Location, end_location: Location) -> bool

    • Verifies if travel between two locations within the given timestamps is feasible.

Tests

Here’s an example of a test case for the package:

test_location_checker.py

from location_checker import Location, LocationChecker


def test_location_checker():
    checker = LocationChecker()

    # Load boundaries
    checker.load_boundaries()

    # Test location creation
    loc1 = Location(latitude=37.7749, longitude=-122.4194, timestamp="2024-12-01T10:00:00Z")
    loc2 = Location(latitude=34.0522, longitude=-118.2437, timestamp="2024-12-01T14:00:00Z")

    # Test country lookup
    countries = checker.get_country(loc1)
    assert len(countries) > 0, "Country lookup failed"

    # Test distance calculation
    distance = checker.calculate_distance(loc1, loc2)
    assert distance > 0, "Distance calculation failed"

    # Test travel feasibility
    feasible = checker.verify_travel_time(loc1, loc2)
    assert feasible, "Travel time verification failed"

    print("All tests passed!")


if __name__ == "__main__":
    test_location_checker()

License

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

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

geoip_location_checker-0.1.3.tar.gz (15.9 kB view details)

Uploaded Source

Built Distributions

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

geoip_location_checker-0.1.3-cp311-cp311-manylinux_2_28_x86_64.whl (625.6 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ x86-64

geoip_location_checker-0.1.3-cp311-cp311-manylinux_2_28_aarch64.whl (616.2 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ ARM64

File details

Details for the file geoip_location_checker-0.1.3.tar.gz.

File metadata

  • Download URL: geoip_location_checker-0.1.3.tar.gz
  • Upload date:
  • Size: 15.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.2

File hashes

Hashes for geoip_location_checker-0.1.3.tar.gz
Algorithm Hash digest
SHA256 525696f3c1a7dbf0d557f43e1557c0ec1e02c5ae6e55099283e9014b95ce1ecb
MD5 57a46e20c04ea9df682ddac9e1ce2e7f
BLAKE2b-256 46b59c66920bce904c5455fec26feefe76aaab642092257ddf12e28915eb0a74

See more details on using hashes here.

File details

Details for the file geoip_location_checker-0.1.3-cp311-cp311-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for geoip_location_checker-0.1.3-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 aa536610da58fc378026eee555839dd90039a5cdfe98ec4013ae07db82c95ee5
MD5 8acada1a5d53375df0bf7b387b80d013
BLAKE2b-256 1730037ed1a06c5e8f5984761478b87ed34a30eb9a4fc6d74a3171023461e17e

See more details on using hashes here.

File details

Details for the file geoip_location_checker-0.1.3-cp311-cp311-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for geoip_location_checker-0.1.3-cp311-cp311-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 c4fb62ee4d77b372dbbf9c689219580539b1c40bb6a2807c7a198e1d87e0d01b
MD5 087e0da12bcfd8824e32ee94d295a96a
BLAKE2b-256 04ed5d2f2c15accd4d3111b44ffad703b5225a4ef3cd1204f4e1b03dcbec51b9

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