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.5.tar.gz (60.0 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.5-cp313-cp313-win_amd64.whl (394.4 kB view details)

Uploaded CPython 3.13Windows x86-64

srtm-0.3.5-cp313-cp313-manylinux_2_34_x86_64.whl (570.3 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ x86-64

srtm-0.3.5-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (562.2 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ ARM64

srtm-0.3.5-cp313-cp313-macosx_11_0_arm64.whl (504.3 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

srtm-0.3.5-cp313-cp313-macosx_10_12_x86_64.whl (521.2 kB view details)

Uploaded CPython 3.13macOS 10.12+ x86-64

srtm-0.3.5-cp312-cp312-win_amd64.whl (395.0 kB view details)

Uploaded CPython 3.12Windows x86-64

srtm-0.3.5-cp312-cp312-manylinux_2_34_x86_64.whl (570.4 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

srtm-0.3.5-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (562.9 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ ARM64

srtm-0.3.5-cp312-cp312-macosx_11_0_arm64.whl (504.6 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

srtm-0.3.5-cp312-cp312-macosx_10_12_x86_64.whl (521.7 kB view details)

Uploaded CPython 3.12macOS 10.12+ x86-64

File details

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

File metadata

  • Download URL: srtm-0.3.5.tar.gz
  • Upload date:
  • Size: 60.0 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.5.tar.gz
Algorithm Hash digest
SHA256 67de660cb8b6d4c8b45459d3f945045e640a85df789982df2ba8c564e06a019b
MD5 fbe3d7080195be1f4b60ae0ecc4d2bad
BLAKE2b-256 a62dbf797128e306838aadfb529ed18a7684f3ce577ec712300e34d92640026c

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: srtm-0.3.5-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 394.4 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.5-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 28c197b2191316b50864806d041137588b31f112fa6d9288e613974e7a438825
MD5 c497f9c245feb1e6865be58b5fa74e2d
BLAKE2b-256 c4c53b999c3d81266a2060e12f1325465ff4ca90d2cf106904b3d1a190519fa8

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for srtm-0.3.5-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 2ae88f2c3b482bef4a0f642ae0b91c01b7f38d4b879dee7f827b0aebb152c175
MD5 052cd39fab7ba08a45c4381b0613afd8
BLAKE2b-256 2b6c2b10bd2982e1f24ec5d8f59899f4e4b4d4d8ff00bc2165a8a6c0fb49dd6e

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for srtm-0.3.5-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 675b20b2d6080b17d39206606f3c36bc902f1bc3c4f7702992cf8d69a5bc970f
MD5 9be622b5347ee926b1e9846b2c4bae92
BLAKE2b-256 12c4eabfe7d4842722d7e6636b6212579e2c12d39ec6ef8ec47834d077ed4baa

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for srtm-0.3.5-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ec0737db82ddb545f51d319175b28b6a793ef07cf94a4210ed49eafacf04e558
MD5 37bebc3e01367e3dd8a246252446c5bf
BLAKE2b-256 02ab2df29f04bc4bdda09c98dd62dde56bc782475c04b1573d7dd56e0ef09503

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for srtm-0.3.5-cp313-cp313-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 22387afd4561f3744854b953748fb586ca522536fde4ac152b9ce2f5ffc2c67f
MD5 b7a84581d1dd253a51e21289b342976b
BLAKE2b-256 47e488ddb85c14261ccfe3c23c4ac00b3459a1531f10a8aa643cd9863762d0be

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: srtm-0.3.5-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 395.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.5-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 799e4430f880a95494eca34d182886d12b14245c69ed6c427de62af84758ae80
MD5 31bc844ec5a5a20b4c7ce1b19f137836
BLAKE2b-256 971033c8f71e72a57298b2c26e0a13374ac1f88c779fa96bd0b088a9d99f557d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for srtm-0.3.5-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 9400bfec37a29fdafb759008eba9912154d57ccfacbfbd542bc8133105c86c67
MD5 b1db769931fdabf36dbffe87b3e5ee3a
BLAKE2b-256 aba057b4667c2772364f406c986de6f8ae4c8bddc1c561cbb8b90adde36822d0

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for srtm-0.3.5-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 081f2d5d93361314ac86f582b0d370aee5f97d63f00c426ee00fe424267cdf23
MD5 c8e843b318cb87c66a96877f790c4fcc
BLAKE2b-256 e73b29bb147fc00b44e2a4181e7a4f622db7b51bcef7f8798baefb2af5233293

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for srtm-0.3.5-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d3527ef155047d04fe1ff34881ec6cc3c248423402e0a74538d6b5a9eee8cca1
MD5 068c753b22ea7db605e7fa88e28768d7
BLAKE2b-256 a97314e36584d23ca45fa24af4d55a6ac139f10ed3e73380c3d7a7365d277989

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for srtm-0.3.5-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 7d1130ca7cbdb36057fd10cf78ffed1a71bc93efe1904443597cd30906c1df59
MD5 9c5551c885bad571cae8d7367d4d6eb3
BLAKE2b-256 d976ac7bc9205074f3569d586c449413591f4bf5f6e3967c1a2aa1c48bf5b463

See more details on using hashes here.

Provenance

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