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]

Preloading Tiles

Warm the cache at startup to avoid cold-start latency (useful when tiles are on NFS):

import srtm

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

# Preload all tiles
stats = service.preload()
print(f"Loaded {stats.tiles_loaded} tiles in {stats.elapsed_ms}ms")

# Preload only CONUS + Hawaii tiles
stats = service.preload(bounds=[
    (24.0, -125.0, 50.0, -66.0),   # CONUS
    (19.0, -161.0, 22.0, -154.0),  # Hawaii
])

# Non-blocking preload (runs in background thread)
service.preload(blocking=False)

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.6.tar.gz (60.8 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.6-cp313-cp313-win_amd64.whl (395.5 kB view details)

Uploaded CPython 3.13Windows x86-64

srtm-0.3.6-cp313-cp313-manylinux_2_34_x86_64.whl (572.8 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ x86-64

srtm-0.3.6-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (562.5 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ ARM64

srtm-0.3.6-cp313-cp313-macosx_11_0_arm64.whl (506.1 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

srtm-0.3.6-cp313-cp313-macosx_10_12_x86_64.whl (523.1 kB view details)

Uploaded CPython 3.13macOS 10.12+ x86-64

srtm-0.3.6-cp312-cp312-win_amd64.whl (396.0 kB view details)

Uploaded CPython 3.12Windows x86-64

srtm-0.3.6-cp312-cp312-manylinux_2_34_x86_64.whl (572.8 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

srtm-0.3.6-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (563.0 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ ARM64

srtm-0.3.6-cp312-cp312-macosx_11_0_arm64.whl (506.3 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

srtm-0.3.6-cp312-cp312-macosx_10_12_x86_64.whl (523.7 kB view details)

Uploaded CPython 3.12macOS 10.12+ x86-64

File details

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

File metadata

  • Download URL: srtm-0.3.6.tar.gz
  • Upload date:
  • Size: 60.8 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.6.tar.gz
Algorithm Hash digest
SHA256 021ca8f09a45e094d1986916b6a53408a1faed22b0fa98a2b474eb6e1ae4391b
MD5 6a0cb885acb9e43f401137e49726429b
BLAKE2b-256 10890f3532a875c2c4b356913b32b01e48a278f8d8d60be9b30af102a7a25d40

See more details on using hashes here.

Provenance

The following attestation bundles were made for srtm-0.3.6.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.6-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: srtm-0.3.6-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 395.5 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.6-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 6dafda346e95ca26675da3e89006e39afcb944fd28d93ca34041da8b41b5721b
MD5 67dbb070cfa36e82a55ba647c259945f
BLAKE2b-256 caa85db9a91761114aea191aa93ac4031b4c0dc681a78b57940db352da919b8b

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for srtm-0.3.6-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 ce3dfb89eecacfcff31c07ab392d32326b6a46307935eb6e43c4bce790978871
MD5 d41edc16e0873d9eccf80b1d2a096da4
BLAKE2b-256 5d4ceb1580e6eacfe49ceaf5917cbb5ea897c4be3690155c1d7bb4422c970893

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for srtm-0.3.6-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 a2b0185b76c9192958040002d581448a13bc764939612c0ff5ac9ef114dde6d2
MD5 96e19d446cac12319c4f4df33406316e
BLAKE2b-256 a313e95660fb093aa0717c11a2b34f51e93e0d863e3bbef30fd5796a5f05efc1

See more details on using hashes here.

Provenance

The following attestation bundles were made for srtm-0.3.6-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.6-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for srtm-0.3.6-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 735012e426873da461dbdddd38e57e58b37d8352bc86afced9cd78b6e0bb0ffb
MD5 30bcdd6da9b23e7a37cb74a986017dbc
BLAKE2b-256 35f95b73b0e60fd1c5dc7007033ac5f3536db300ffb8a777bda586f74e9d47e7

See more details on using hashes here.

Provenance

The following attestation bundles were made for srtm-0.3.6-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.6-cp313-cp313-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for srtm-0.3.6-cp313-cp313-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 1594763f8056d2088ef1c857ce418544535f5aa73de3d69da23d1f9b49f4c208
MD5 dae299ef0ee4e0b7dc05ce5f1d36b413
BLAKE2b-256 a26f0e79625ca182986aab6fd1cdfc641d4af262b14d0f1260080772256c022f

See more details on using hashes here.

Provenance

The following attestation bundles were made for srtm-0.3.6-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.6-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: srtm-0.3.6-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 396.0 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.6-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 93c69275bf94101617f40e70f60bfc4cbd81e528062e01d497fcadc06ffeca0c
MD5 14d4ec45f8adff4c683cbc023a687407
BLAKE2b-256 656dc831345bac70d9cc7dceb337a087d37a909fbaad0e5402427ec625d7a473

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for srtm-0.3.6-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 bce9c46ed1d07db753322de91d75b6b4a9e89e11815b1ab7bd35aa949d223ef6
MD5 19cdea9a037de035f2458416a8cddd34
BLAKE2b-256 45bc2e4e2bec3276cfa087e964d2965e23dee378c0b8b123e5e1d58ce4d5c810

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for srtm-0.3.6-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 9f4a46a42c7ce35c24d6f2d6ad43f11094d87a353d46ea2eaf27d140b047b28b
MD5 3d7e41cc76ac48a8eddacf2763f2eb05
BLAKE2b-256 a8c4898f35fa68a147ac3534004e9af174dcc96e62b9b8dad5e330bedad4b4c8

See more details on using hashes here.

Provenance

The following attestation bundles were made for srtm-0.3.6-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.6-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for srtm-0.3.6-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 eb7984854934324b7a616473493c4975995c6557ba9ad09ff48fda81deb74521
MD5 6123cb9cd1950a8ebfd9941a4d23b31c
BLAKE2b-256 f491ff28e06561ecd6f4b6feaae6edaeb0ab5e1bf41877a84f08f3cada0c7c84

See more details on using hashes here.

Provenance

The following attestation bundles were made for srtm-0.3.6-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.6-cp312-cp312-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for srtm-0.3.6-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 0e7a45e58d677a1c6672fd96f7b00970270c519921eddeafa6b5745dcbfb5494
MD5 fb83bcd1dddfb089bba3c5aff0f5ab5c
BLAKE2b-256 c34295e3e4255015c438784b1eb73261a7225fca0e3832b29708d913fd7182f6

See more details on using hashes here.

Provenance

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