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%}")

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.3.tar.gz (53.3 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.3-cp313-cp313-win_amd64.whl (365.5 kB view details)

Uploaded CPython 3.13Windows x86-64

srtm-0.3.3-cp313-cp313-manylinux_2_34_x86_64.whl (532.5 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ x86-64

srtm-0.3.3-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (522.7 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ ARM64

srtm-0.3.3-cp313-cp313-macosx_11_0_arm64.whl (472.3 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

srtm-0.3.3-cp313-cp313-macosx_10_12_x86_64.whl (482.8 kB view details)

Uploaded CPython 3.13macOS 10.12+ x86-64

srtm-0.3.3-cp312-cp312-win_amd64.whl (365.9 kB view details)

Uploaded CPython 3.12Windows x86-64

srtm-0.3.3-cp312-cp312-manylinux_2_34_x86_64.whl (532.2 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

srtm-0.3.3-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (522.9 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ ARM64

srtm-0.3.3-cp312-cp312-macosx_11_0_arm64.whl (472.0 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

srtm-0.3.3-cp312-cp312-macosx_10_12_x86_64.whl (482.9 kB view details)

Uploaded CPython 3.12macOS 10.12+ x86-64

File details

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

File metadata

  • Download URL: srtm-0.3.3.tar.gz
  • Upload date:
  • Size: 53.3 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.3.tar.gz
Algorithm Hash digest
SHA256 68d54efab0064355b02d3cf663eba92daab5d67096f300ef45cb17743bfe085f
MD5 e65be35f05623747c2e758dadb947725
BLAKE2b-256 c84bed61a269a7f3f1df6371371cf615cf5c2dadbbc21cf06476bab95955d256

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: srtm-0.3.3-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 365.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.3-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 4e31bd4a14e0972f11f2c7b13e400eea46af0023e41e84cb899218e639e706b1
MD5 5d389001ff87b9bf666f57d4c6f05864
BLAKE2b-256 4ef03dfe09b33d337da192c6dc43432e41f14ada30561533b53b0b3dee73676f

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for srtm-0.3.3-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 9268fcc1a8c65d349291f26415e4c631f0fcf0756b2f431498c2699b4f622dbd
MD5 d33d591959b9fd1386d3bc611baa033d
BLAKE2b-256 4f50dcdf3b285a087abfaee2d86ec4a9d73b361f4aa850cbfbfcee1bfa544d74

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for srtm-0.3.3-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 a25aabfbdb9a681eafe5197f8c34a293109f2dc12e100efa80c3220c46e01214
MD5 cb1f21dbeea16807e428f4e7f6270b77
BLAKE2b-256 b07db2c7b3700170037ec248e4e91cb2d52d4dfd9448eb22f42e86d7f05053b4

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for srtm-0.3.3-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e0e04f29deb8d1521bfc8b24d0ea23c554eaf67a40f0a27d9a61ab3438e52d2a
MD5 5cb8fcb2e5be359411a5b9e356f869f3
BLAKE2b-256 c5299f4ada16b8a72a750ef3176a21f9412253835d51fc5dc0789fb7a0590fa9

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for srtm-0.3.3-cp313-cp313-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 b813a35b1d14918532fca5962eedfa80dea3c391cd8245c9dc5ff6aad68caf37
MD5 85610d5a84a6f2f693fc0a62a4ae8751
BLAKE2b-256 288d4bbe36c0405afcccbd408cc4864fa2e3e8b0f75ca836d0b0d075386f2757

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: srtm-0.3.3-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 365.9 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.3-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 35127f0e0a9f8a353f929c646db77191158ab86c8420157997fbfbc9087ad927
MD5 42b55cb4b95922ba69b148f402cc638d
BLAKE2b-256 e102b20b5606bce2dd15831499aca35b2e5ad0f00c3c0b1ef468440d322e77c7

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for srtm-0.3.3-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 744a489d07b436a98f604f10b7a24a47c641a1eb3cb121f92a6e5b4650813e81
MD5 06d118988d26a82c3ef51b882049ca1d
BLAKE2b-256 f4e6c481168f68ef4d3df52dc368cc2e5fd2c4955426b60062d0f1b143408577

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for srtm-0.3.3-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 29680fa7a7fd3165de3a453f2cdb49c886cd114bc905e14fffcb58cd81164edc
MD5 cd13e5f0dafbcf4c73b445ad3196910f
BLAKE2b-256 64781f78f90fd1b326390e648611ae423f8a502cd97706bf63aec4f76768f001

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for srtm-0.3.3-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 bc915c429db37956fc56a5b580c0eaa5bd61eba244fe4ce498d56856dbfa6c7f
MD5 1780172632177ed4382b69ec12baeb3e
BLAKE2b-256 37bad44bdef019a505af1d39b52ab43e80b52e4afe95583fdf8b5697564a6b92

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for srtm-0.3.3-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 af1f12c868e34c9cb29c7697503501f9a26f10b6695458421f990adcc5159d20
MD5 dc3eecc95ab1e44be0e18f25de6890b3
BLAKE2b-256 db3ce17965a6ba99eecf6a42f314565e09d959b4d5e762ad25db2c5ac1676e3d

See more details on using hashes here.

Provenance

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