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.2.tar.gz (53.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.2-cp313-cp313-win_amd64.whl (364.4 kB view details)

Uploaded CPython 3.13Windows x86-64

srtm-0.3.2-cp313-cp313-manylinux_2_34_x86_64.whl (529.7 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ x86-64

srtm-0.3.2-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (521.1 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ ARM64

srtm-0.3.2-cp313-cp313-macosx_11_0_arm64.whl (469.2 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

srtm-0.3.2-cp313-cp313-macosx_10_12_x86_64.whl (481.0 kB view details)

Uploaded CPython 3.13macOS 10.12+ x86-64

srtm-0.3.2-cp312-cp312-win_amd64.whl (364.8 kB view details)

Uploaded CPython 3.12Windows x86-64

srtm-0.3.2-cp312-cp312-manylinux_2_34_x86_64.whl (529.7 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

srtm-0.3.2-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (521.3 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ ARM64

srtm-0.3.2-cp312-cp312-macosx_11_0_arm64.whl (469.0 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

srtm-0.3.2-cp312-cp312-macosx_10_12_x86_64.whl (481.2 kB view details)

Uploaded CPython 3.12macOS 10.12+ x86-64

File details

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

File metadata

  • Download URL: srtm-0.3.2.tar.gz
  • Upload date:
  • Size: 53.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.2.tar.gz
Algorithm Hash digest
SHA256 f97ebe147ac9c911ef85c9a2d6c82bd4f77945b0120daf44f3bbfab9445e99f5
MD5 4554695b11960bf803cfdaf91cf5cec2
BLAKE2b-256 e4446d62e6ae6fc5ecadd336f118f5d9a852a8550b19d8440eb6ac598b84060e

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: srtm-0.3.2-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 364.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.2-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 3cf1545de3a5d778253a49677550decb9a376cab2f03c2868deef56d3e06473f
MD5 1cdacfdebd985df52139413e873427c8
BLAKE2b-256 1128364b136b5d9033ce309c468118c3e6200c1650a854c752ac7f27d6d42831

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for srtm-0.3.2-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 fbfd211161614b990289ac951f8f9f344063028eaeaaf00eeb00ace774ab1603
MD5 ffa5cbaccfe91b633b1775c3f2f50359
BLAKE2b-256 b1f3d88886e3f89eb34dd637d22080bb73440f5033c790aa7ea891e803f9dcac

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for srtm-0.3.2-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 1af2b55a16a9496925c4b315d47d66d5ddd659fd3746187a2220bf31673fd78a
MD5 297ea5c351f03db95dcf96ae27f6c525
BLAKE2b-256 bc845bba065304718380dac57c4556f125d7eaf561664fb2cd953684c71680ef

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for srtm-0.3.2-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f7764fd487694d3799b88a5e50ac3ea5fd41ccfb9fde635114ddba4258200099
MD5 1c71c5331469fb5e703d837f56049a08
BLAKE2b-256 87b5aa4b0f5cdd829f3796026df59d22afd5f507f34483a37fc29d587aef900b

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for srtm-0.3.2-cp313-cp313-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 2f6b71d57d7115e2bb339474b1e91c62e4bf945c0bf0fd7d836bfc58d70a92de
MD5 20960bbed29b27c581a3c6ecc5ed3a0d
BLAKE2b-256 8508c4d6b1c87add866ef33f70a893113909072d09cd6181334e34c1b3a583b1

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: srtm-0.3.2-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 364.8 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.2-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 2bd02d2f266811d8fdbaad7454f3c77faa77da32d2ea9ef1c4ee343565530c99
MD5 c5e9d53d00737732619f88694d60b811
BLAKE2b-256 77a62b76f07db8055ac4e8b38a96238bd605be6cf941b5c3807a432d5567ccfa

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for srtm-0.3.2-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 bcbb1655888fdc4246aef19b516fbb9fcf5f49aa9d2186ff72ab42f7f91a623c
MD5 2450bf27faa4a4e74a2d826f0fc7f33f
BLAKE2b-256 fe76a740dd31228884329fa4022720f5fe9df0f1434ca200381086d023e93269

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for srtm-0.3.2-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 355d457da85f5d8e4c4d8d7a75e4dce213482cc78e3e451f63d379c9a51d4d0c
MD5 6b8f7b6e0e9bef2e8166545fdde48751
BLAKE2b-256 260a40f7be662973e2a88304d785c21db83e7456336be09dc5375c6f9ff55f94

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for srtm-0.3.2-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 51dfc7651aa4bb296316f49b67afcd211e4a743bc4965c751457fd8ac5f705d4
MD5 bb8e35624f32df4c74f86a301fa67757
BLAKE2b-256 3afbf30f17af3a9a9cf9b7d79e678891d7878c8bd298f2e4c72e99baacbeef0d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for srtm-0.3.2-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 063d419f8ea1bd8b30657735780b18dfd70e46c4d838f204db4bfd1113641f6d
MD5 9f3cd3973a662556d1d7e1334fd94196
BLAKE2b-256 b744f983a9664a13ee9acda3bce08816b805b4cf4423bca3e57109f8fb7ffdd0

See more details on using hashes here.

Provenance

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