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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file geoip_location_checker-0.1.2.tar.gz.
File metadata
- Download URL: geoip_location_checker-0.1.2.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fdaae263c33791ca786c9d20cd2c3bd9da6fa146e5800752f2bd1c8e1712de98
|
|
| MD5 |
bd07473dbaa99521214fb0c1ae871575
|
|
| BLAKE2b-256 |
9ab4098759d59391666f87266c6adeace7b676ad39f884fea4a5f66087e21df9
|
File details
Details for the file geoip_location_checker-0.1.2-cp311-cp311-manylinux_2_28_x86_64.whl.
File metadata
- Download URL: geoip_location_checker-0.1.2-cp311-cp311-manylinux_2_28_x86_64.whl
- Upload date:
- Size: 625.6 kB
- Tags: CPython 3.11, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
55dad0d0ed54c65762c59c58619f911fb62090835b5d3634323b374391e04da4
|
|
| MD5 |
30064e4ff04e43c9a87eac5ae2f33b28
|
|
| BLAKE2b-256 |
74f5fbe26c82de19ff3e819b8427d840dd3e24a01501bc6d046b92d8d8f7cb7d
|
File details
Details for the file geoip_location_checker-0.1.2-cp311-cp311-manylinux_2_28_aarch64.whl.
File metadata
- Download URL: geoip_location_checker-0.1.2-cp311-cp311-manylinux_2_28_aarch64.whl
- Upload date:
- Size: 616.3 kB
- Tags: CPython 3.11, manylinux: glibc 2.28+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1fa81f91038dd8032b2adecb0f1c567be9b77cf639850bf5d782070f72a8333b
|
|
| MD5 |
41dd74744e71f334aa32168f5be8847e
|
|
| BLAKE2b-256 |
cedc8b0c00acc046a2817879d3d62064bc1a223abb5670455eca24b75512a0b7
|