Skip to main content

High-performance SRTM elevation data library

Project description

htg - High-performance SRTM Elevation Library

PyPI License: MIT

Ultra-fast SRTM elevation queries in Python. Built with Rust, delivering 3.5x faster performance than the most popular Python SRTM library.

Python bindings for the htg Rust library, providing blazingly fast elevation queries from SRTM .hgt files with sub-microsecond latency.

Installation

pip install srtm

Quick Start

import srtm

# Create service with up to 100 cached tiles
service = srtm.SrtmService("/path/to/srtm", cache_size=100)

# Query elevation (Mount Fuji)
elevation = service.get_elevation(35.3606, 138.7274)
print(f"Elevation: {elevation}m")  # 3776

# Interpolated query for smoother results
elevation = service.get_elevation_interpolated(35.3606, 138.7274)
print(f"Elevation: {elevation:.2f}m")  # 3776.42

# Check cache performance
stats = service.cache_stats()
print(f"Cache hit rate: {stats.hit_rate:.1%}")

Utility Functions

import srtm

# Convert coordinates to filename
filename = srtm.lat_lon_to_filename(35.5, 138.7)
print(filename)  # "N35E138.hgt"

# Parse filename to coordinates
coords = srtm.filename_to_lat_lon("N35E138.hgt")
print(coords)  # (35, 138)

# Void value constant
print(srtm.VOID_VALUE)  # -32768

SRTM Data

Download SRTM .hgt files from:

Performance

htg-python delivers exceptional performance through its Rust core and PyO3 bindings, significantly outperforming traditional Python SRTM libraries.

Benchmarks vs Popular Python Libraries

Comparison using local .hgt files only (fair, apples-to-apples test):

Library Implementation Per Query Throughput vs htg-python
htg-python Rust + PyO3 0.41 μs 2,419,110 q/s 1.0x (baseline) ⚡
srtm.py Pure Python (256 ⭐) 1.43 μs 697,654 q/s 3.5x slower
srtm4 Python + C++ subprocess 99,630 μs 10 q/s 241,017x slower

Key findings:

  • 3.5x faster than srtm.py (most popular, fair comparison)
  • 241,000x faster than srtm4 (subprocess overhead dominates)
  • Sub-microsecond latency - queries complete in 0.41 microseconds
  • 2.4 million queries/second on a single thread

Benchmark environment: Python 3.12, macOS (Apple Silicon). See BENCHMARKS.md for full methodology.

Why So Fast?

  • Zero-copy memory access: Memory-mapped I/O eliminates data copying
  • No subprocess overhead: Direct Rust function calls via PyO3 (unlike srtm4's subprocess approach)
  • Optimized compilation: LLVM optimizations with inline expansion
  • Efficient caching: In-memory LRU cache vs disk-based caching

Real-World Performance

import srtm
service = srtm.SrtmService("/path/to/data", cache_size=100)

# Single query: ~0.4 microseconds (sub-millisecond!)
elevation = service.get_elevation(35.3606, 138.7274)

# Batch queries: ~147k per second on a single thread
for lat, lon in coordinates:
    elevation = service.get_elevation(lat, lon)

Production-ready: Can handle millions of requests per second with multiple cores.

License

MIT

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

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

srtm-0.3.0-cp312-cp312-win_amd64.whl (371.1 kB view details)

Uploaded CPython 3.12Windows x86-64

srtm-0.3.0-cp312-cp312-manylinux_2_34_x86_64.whl (536.0 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

srtm-0.3.0-cp312-cp312-macosx_11_0_arm64.whl (475.1 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

File details

Details for the file srtm-0.3.0-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: srtm-0.3.0-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 371.1 kB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for srtm-0.3.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 9a092ddb6ec3e9d88d3986aca0111497e078f3842d7a02dddd7d103f205ab175
MD5 91001d27d5ac73cca13ad7c427451bec
BLAKE2b-256 0f717ff5cbd1cf0ecb2e1cd18f9e3f1c8750c2babae59705565295cd76fec47d

See more details on using hashes here.

Provenance

The following attestation bundles were made for srtm-0.3.0-cp312-cp312-win_amd64.whl:

Publisher: release.yml on pedrosanzmtz/htg

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file srtm-0.3.0-cp312-cp312-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for srtm-0.3.0-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 0332cb8e87632fe1e88d1e5d9e2fa551ffd487f1552dcd9a84b4efe2206c3130
MD5 cec209922caf28d4ac5ed2c2f55db353
BLAKE2b-256 833ff29416bf900207153903e2d42c62dd9ca263c132392aac1128e90e6db8d7

See more details on using hashes here.

Provenance

The following attestation bundles were made for srtm-0.3.0-cp312-cp312-manylinux_2_34_x86_64.whl:

Publisher: release.yml on pedrosanzmtz/htg

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file srtm-0.3.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for srtm-0.3.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c5a3ed807c387d3cfeca1f5e3860baae19e51d96ed8fbb1db8e60994607874c3
MD5 123399d59bf920a576e57c5427b62240
BLAKE2b-256 6837a4ce0fc16f7b299ddd8a2cac15d7b49e3db854b7e7365c33898f109784c5

See more details on using hashes here.

Provenance

The following attestation bundles were made for srtm-0.3.0-cp312-cp312-macosx_11_0_arm64.whl:

Publisher: release.yml on pedrosanzmtz/htg

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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