Zero-dependency theoretical air distance calculations using Haversine and Vincenty.
Project description
distance_engine
distance_engine is a production-oriented Python package for computing the theoretical geometric air distance between two coordinate points. It is designed for airport-to-airport distance use cases where your service layer already knows the coordinates and needs a clean, typed, zero-runtime-dependency engine.
This package calculates theoretical geometric distance only.
- It is not actual flown distance.
- It is not airline mileage-credit distance.
- It is not fare, routing, or frequent-flyer program logic.
Supported Methods
Haversine
Haversine treats the Earth as a sphere and uses the mean Earth radius. It is fast, simple, and useful when you want a solid approximation with minimal computational cost.
Vincenty (inverse)
Vincenty uses an ellipsoidal Earth model and is more appropriate when theoretical airport-to-airport distance should be closer to the WGS-84 reference ellipsoid. This package uses WGS-84 by default.
Vincenty is iterative and can fail to converge for some extreme pairs, especially near-antipodal points. In that case, the package can either:
- raise
VincentyDidNotConvergeError, or - fall back to Haversine when
fallback_to_haversine=True
When fallback is used, the returned result has:
method="vincenty_fallback_haversine"converged=Falseellipsoid=None
Why No Third-Party Runtime Dependencies
distance_engine intentionally keeps runtime dependencies empty.
- Easier to audit
- Easier to vendor or embed
- Easier to integrate into backend services and scripts
- Lower long-term maintenance cost
- No dependency on heavyweight geospatial libraries when you only need these two formulas
Build and release tools such as build and twine are optional developer tooling only. They are not runtime dependencies of the package.
Installation
Local development install
python3.12 -m pip install -e .
Future PyPI install
python3.12 -m pip install distance_engine
Quick Start
Python API
from distance_engine import Point, distance, haversine_distance, vincenty_distance
origin = Point(1.35, 103.99)
destination = Point(51.47, -0.45)
result = distance(origin, destination)
print(result.kilometers)
print(result.miles)
print(result.nautical_miles)
print(result.initial_bearing_deg)
print(result.final_bearing_deg)
fast_result = haversine_distance(origin, destination)
precise_result = vincenty_distance(origin, destination)
Tuple inputs
from distance_engine import distance
result = distance((1.35, 103.99), (51.47, -0.45), method="haversine")
print(result.kilometers)
Keyword coordinate inputs
from distance_engine import distance
result = distance(
lat1=1.35,
lon1=103.99,
lat2=51.47,
lon2=-0.45,
method="vincenty",
)
print(result.meters)
CLI
Run the module directly:
python3.12 -m distance_engine \
--lat1 1.35 \
--lon1 103.99 \
--lat2 51.47 \
--lon2 -0.45 \
--method vincenty
JSON output:
python3.12 -m distance_engine \
--lat1 1.35 \
--lon1 103.99 \
--lat2 51.47 \
--lon2 -0.45 \
--method vincenty \
--json
Fallback example:
python3.12 -m distance_engine \
--lat1 0.0 \
--lon1 0.0 \
--lat2 0.5 \
--lon2 179.7 \
--method vincenty \
--fallback-to-haversine
Input And Output
Inputs are decimal-degree coordinates.
- Latitude must be within
[-90, 90] - Longitude is normalized into
[-180, 180]
Returned DistanceResult contains:
meterskilometersmilesnautical_milesmethodellipsoidconvergedinitial_bearing_degfinal_bearing_deg
Limitations
- Theoretical geometric distance is not actual flown distance.
- Theoretical geometric distance is not frequent-flyer credited mileage.
- Haversine is a spherical approximation.
- Vincenty can fail to converge for some extreme point pairs.
- This package does not resolve airport codes or consult airport databases.
- This package does not model route restrictions, winds, ATC deviations, SID/STAR, or airway structure.
Method Notes
Haversine computes the great-circle distance on a sphere using the mean Earth radius. It is appropriate when speed and simplicity matter more than ellipsoidal precision.
Vincenty inverse solves the geodesic distance on an ellipsoid iteratively. In this package it uses WGS-84 by default, which is often a better fit for airport-to-airport theoretical distance.
Development
Run tests:
python3.12 -m unittest discover -s tests -v
Editable install:
python3.12 -m pip install -e .
Build And Release
Install build tooling:
python3.12 -m pip install build twine
Build source and wheel distributions:
python3.12 -m build
Check the built distributions:
python3.12 -m twine check dist/*
Upload to TestPyPI:
python3.12 -m twine upload --repository testpypi dist/*
Upload to PyPI:
python3.12 -m twine upload dist/*
Intended Integration Model
This package is the core distance engine only. A later business layer can sit on top of it to map airport codes to coordinates and then apply airline-specific rules, fare logic, or loyalty program behavior.
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 Distribution
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 distance_engine-0.1.1.tar.gz.
File metadata
- Download URL: distance_engine-0.1.1.tar.gz
- Upload date:
- Size: 14.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ceb78c1657b5263bdb7de59f7dec9ba6b829f9406af8408e92f2a9082626032a
|
|
| MD5 |
3675a8d3f6e6e9f14b91b74fef67f46d
|
|
| BLAKE2b-256 |
ff5591c36c34aac9e6d1d7af13a61852175b2d6627bf44af97079ded4fa97535
|
File details
Details for the file distance_engine-0.1.1-py3-none-any.whl.
File metadata
- Download URL: distance_engine-0.1.1-py3-none-any.whl
- Upload date:
- Size: 14.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4b94244d0686bd75fe6f61a7d97f16187a8e09193c55e3c8b7826d0c8366157e
|
|
| MD5 |
c3d0a1e9662759b1ccf2e79d232eba57
|
|
| BLAKE2b-256 |
36d9b6e1769c9840e6c0a3ad6ae60c3bf9e5ea8d73318623d9aa06c78649b22a
|