Skip to main content

High-performance SRTM elevation data library

Project description

srtm - 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

Prebuilt wheels are available for Python 3.12+ on Linux (x86_64, aarch64), macOS (Apple Silicon, x86_64), and Windows (x86_64).

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)
# Returns None for void data or missing tiles
elevation = service.get_elevation(35.3606, 138.7274)
if elevation is not None:
    print(f"Elevation: {elevation}m")  # 3776

# Interpolated query for smoother results
# Returns None if any surrounding point is void
elevation = service.get_elevation_interpolated(35.3606, 138.7274)
if elevation is not None:
    print(f"Elevation: {elevation:.2f}m")  # 3776.42

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

srtm.py Compatibility

If you're migrating from srtm.py, use rounding="floor" for exact value parity. srtm.py uses math.floor() for grid cell selection, while htg defaults to round() (true nearest-neighbor). The difference is typically 1-3 meters at grid cell boundaries.

import srtm

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

# Default: true nearest-neighbor (round)
elevation = service.get_elevation(33.3448, -96.1592)  # 190

# srtm.py compatible: floor-based (southwest-biased)
elevation = service.get_elevation(33.3448, -96.1592, rounding="floor")  # 191

# Also works with batch queries
elevations = service.get_elevations_batch(coords, default=0, rounding="floor")

Batch Queries

Query multiple coordinates efficiently in a single call:

import srtm

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

coords = [
    (35.3606, 138.7274),  # Mount Fuji
    (27.9881, 86.9250),   # Mount Everest
    (46.8523, 9.1512),    # Piz Bernina
]

# Returns a list of elevations; uses default (0) for void/missing data
elevations = service.get_elevations_batch(coords, default=0)
print(elevations)  # [3776, 8752, 3148]

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:

Both .hgt and .hgt.zip files are supported. ZIP files are transparently extracted on first access.

Performance

srtm 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 srtm
srtm Rust + PyO3 0.41 us 2,419,110 q/s 1.0x (baseline)
srtm.py Pure Python (256 stars) 1.43 us 697,654 q/s 3.5x slower
srtm4 Python + C++ subprocess 99,630 us 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 Distribution

srtm-0.3.4.tar.gz (55.7 kB view details)

Uploaded Source

Built Distributions

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

srtm-0.3.4-cp313-cp313-win_amd64.whl (367.2 kB view details)

Uploaded CPython 3.13Windows x86-64

srtm-0.3.4-cp313-cp313-manylinux_2_34_x86_64.whl (533.8 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ x86-64

srtm-0.3.4-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (524.3 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ ARM64

srtm-0.3.4-cp313-cp313-macosx_11_0_arm64.whl (473.7 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

srtm-0.3.4-cp313-cp313-macosx_10_12_x86_64.whl (484.5 kB view details)

Uploaded CPython 3.13macOS 10.12+ x86-64

srtm-0.3.4-cp312-cp312-win_amd64.whl (367.5 kB view details)

Uploaded CPython 3.12Windows x86-64

srtm-0.3.4-cp312-cp312-manylinux_2_34_x86_64.whl (533.5 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

srtm-0.3.4-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (524.4 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ ARM64

srtm-0.3.4-cp312-cp312-macosx_11_0_arm64.whl (473.6 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

srtm-0.3.4-cp312-cp312-macosx_10_12_x86_64.whl (484.6 kB view details)

Uploaded CPython 3.12macOS 10.12+ x86-64

File details

Details for the file srtm-0.3.4.tar.gz.

File metadata

  • Download URL: srtm-0.3.4.tar.gz
  • Upload date:
  • Size: 55.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for srtm-0.3.4.tar.gz
Algorithm Hash digest
SHA256 30405f8babb9031cf1d1d02ae7072d24c901a315f3e35f7a0a0349f88f1011db
MD5 4f46f6ff24003c97fc0abf81774b64e7
BLAKE2b-256 cb66bbb0b92562d973a275b04ad127afbba44dd1c5917cdbbdcbeb674b0b462e

See more details on using hashes here.

Provenance

The following attestation bundles were made for srtm-0.3.4.tar.gz:

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.4-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: srtm-0.3.4-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 367.2 kB
  • Tags: CPython 3.13, 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.4-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 94d1f9ed080fd044af5a34fd3d41f9ca11f19e410e4a258a06e18e0d1e30b40a
MD5 4e2873e73ed55e81367ec392b1dbda82
BLAKE2b-256 ed99c1633393524895811308cc54beacd0362bba6034af45067d3b929aa2b15d

See more details on using hashes here.

Provenance

The following attestation bundles were made for srtm-0.3.4-cp313-cp313-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.4-cp313-cp313-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for srtm-0.3.4-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 cbf77ffba365e50b5be9b51f2b43ef9132984b85b91a169f1d500640f68eebf3
MD5 67f9a4d0bd58c0e0df743437d736a340
BLAKE2b-256 d7182094aac8333c8659e61af93aefab98072879e731fd8d711d6626740cd4c4

See more details on using hashes here.

Provenance

The following attestation bundles were made for srtm-0.3.4-cp313-cp313-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.4-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for srtm-0.3.4-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 c99262d244134eba37b24b14346108726c04adc8042a4b85172e4aa5d23769da
MD5 fbf3d56d41ee5cb7b18a865095bf5975
BLAKE2b-256 0c3c08b545f45b070388f66a23b2edd296648426b5dd7621b177b2f0a9b866eb

See more details on using hashes here.

Provenance

The following attestation bundles were made for srtm-0.3.4-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.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.4-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for srtm-0.3.4-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 10d82a386aa50ba273e9a54235687a471f0a0d9bb7113f743ba7d0520d0e8bd0
MD5 fb18559600609a8dbf76b23b841d322e
BLAKE2b-256 23953d1568f3f31f40bc5c7486fe47006f1c7b96237aba93070062f4e35bab6d

See more details on using hashes here.

Provenance

The following attestation bundles were made for srtm-0.3.4-cp313-cp313-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.

File details

Details for the file srtm-0.3.4-cp313-cp313-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for srtm-0.3.4-cp313-cp313-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 78e11d0cf5f9f25aeec395b6bc94c563d48253089250a9021a484241398d08e4
MD5 851c3db21da31004c7fecc975adb380f
BLAKE2b-256 ea70c9dce1a27f9375205f6b5e0aee304b096ce3a85b7a96b4abeae5d5756918

See more details on using hashes here.

Provenance

The following attestation bundles were made for srtm-0.3.4-cp313-cp313-macosx_10_12_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.4-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: srtm-0.3.4-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 367.5 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.4-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 734588ae33bc6ffaf042f298b208a44d7208f1b1b77abf59fe0cc9b3a52915de
MD5 bb0bf8b46f4f89c01ed3b84eae68c905
BLAKE2b-256 36ce162aeed8ac24154657288665cbcf6989a3efb8bb8ba0c2536a8d18dc0c47

See more details on using hashes here.

Provenance

The following attestation bundles were made for srtm-0.3.4-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.4-cp312-cp312-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for srtm-0.3.4-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 dec9faf81c08a5f004b5d41199d538bd505a34e16788ae3de617097c599a71f8
MD5 73789b9d72fdf48dedc8b91d98e4bbba
BLAKE2b-256 3de68acf97b3404435f10ee24d4c0c8b70276998bf38b9ab9c6193e179222aae

See more details on using hashes here.

Provenance

The following attestation bundles were made for srtm-0.3.4-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.4-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for srtm-0.3.4-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 7214da0925c62dfe28dc964824bda4a7c4a0e040926c9b359f4f04050fc51293
MD5 5141c551b19981f0fe31a5bcc0ed124d
BLAKE2b-256 ade1a024470503479ac7d71cc84fff95b03ae5fe092db06d39bc73b7263bb886

See more details on using hashes here.

Provenance

The following attestation bundles were made for srtm-0.3.4-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.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.4-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for srtm-0.3.4-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7ba3b7f11db1cd83d24b3d049a881c10e025fb66433dd53155fe399bd42aa755
MD5 a39760308d7036d78b335c63d93c33c7
BLAKE2b-256 dae28a325fdc59b5e54d4ddfe444e29e51c644c62a871ba6b0e41100bffe703e

See more details on using hashes here.

Provenance

The following attestation bundles were made for srtm-0.3.4-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.

File details

Details for the file srtm-0.3.4-cp312-cp312-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for srtm-0.3.4-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 05be1ccedb3e5a98fe0b3e0b4cb5d169a08e3628f7e12ea5f04858794cf1d524
MD5 250b4e40b3b6b85e5f336fceb489c3ce
BLAKE2b-256 dbc2e39619355bfc55f1edec27d3f042d529de7731e39dc5f0d9c4b61fce50d6

See more details on using hashes here.

Provenance

The following attestation bundles were made for srtm-0.3.4-cp312-cp312-macosx_10_12_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.

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