Skip to main content

Python bindings for sgp4-predict satellite pass prediction

Project description

sgp4-predict — Python bindings

Test PyPI Python versions License: MIT OR Apache-2.0

Python bindings for the sgp4-predict Rust library: satellite pass prediction from TLE or OMM data, with type stubs and native datetime support.

pip install sgp4-predict

Quick start

Find the passes over a ground station and sample each one:

from datetime import datetime, timedelta, timezone
from sgp4_predict import GroundObserver, Interval, Predictor, Tle

tle = Tle(
    "SENTINEL-2C",
    "1 60989U 24157A   25356.66913557  .00000141  00000+0  70244-4 0  9990",
    "2 60989  98.5671  69.0082 0001197  95.1447 264.9872 14.30821394 67740",
)
predictor = Predictor.from_tle(tle)

glasgow = GroundObserver(latitude_deg=55.86, longitude_deg=-4.25, altitude=40.0)

start = datetime(2025, 12, 22, tzinfo=timezone.utc)
window = Interval(start=start, end=start + timedelta(days=1))

for transit in predictor.transits_iter(glasgow, window, min_elevation_deg=5.0):
    print(f"AoS {transit.start} → LoS {transit.end} ({transit.duration_seconds:.0f}s)")

    # A Transit is itself an interval, so it can be passed straight back in.
    for t, obs in predictor.observation_iter(glasgow, transit, timedelta(seconds=10)):
        print(f"  {t}  az={obs.azimuth_deg:.1f}°  el={obs.elevation_deg:.1f}°")

Predictor

Construct from a Tle, or from Elements parsed from OMM JSON:

from sgp4_predict import Elements

predictor = Predictor.from_tle(tle)                  # raises ValueError if malformed
predictor = Predictor(Elements.from_json(omm_json))  # CCSDS OMM (Celestrak, Space-Track)

predictor.epoch                  # datetime (UTC) — element epoch
predictor.tle_age_seconds(now)   # float — positive means the epoch is in the past

SGP4 accuracy degrades with element age; treat LEO TLEs older than 3–7 days with caution. Fresh TLEs are available from CelesTrak.

Point queries

sv    = predictor.propagate(t)               # StateVectorTeme
obs   = predictor.observe_at(t, observer)    # Observation
state = predictor.illumination_state(t)      # IlluminationState.Sunlit or .Eclipse

# The pass in progress at t, or None
transit = predictor.detect_transit(t, observer, min_elevation_deg=5.0)

# Peak elevation within an interval; raises RuntimeError if there is no peak
t_peak, obs_peak = predictor.max_elevation(observer, window)

Iterators

All iterators are lazy. Every method taking a time range accepts any object with .start and .end datetime properties — an Interval, a Transit, an Illumination, or your own type.

for t, sv in predictor.prediction_iter(window, step): ...           # StateVectorTeme
for t, obs in predictor.observation_iter(observer, window, step): ...  # Observation
for transit in predictor.transits_iter(observer, window, min_elevation_deg=5.0): ...
for apsis in predictor.apsis_iter(window): ...                      # Apsis
for illumination in predictor.illumination_iter(window): ...        # Illumination

Predictor.with_refinement(Refinement(...)) returns a copy with a different root-finder configuration for event times; Refinement exposes time_tolerance (seconds, default 1e-3) and max_iter (default 100).

Return types

transit.start / .end          # datetime (UTC) — AoS / LoS
transit.duration_seconds      # float

obs.azimuth_deg               # float — degrees from north, clockwise, in (-180, 180]
obs.elevation_deg             # float — degrees above the horizon
obs.range                     # float — metres
obs.range_rate                # float — m/s, positive = receding

apsis.time                    # datetime (UTC)
apsis.event                   # ApsisEvent.Apogee or .Perigee
apsis.altitude                # float — metres above the WGS-84 equatorial radius

illumination.start / .end     # datetime (UTC)
illumination.state            # IlluminationState.Sunlit or .Eclipse
illumination.duration_seconds # float

Transit and Illumination are themselves intervals — isinstance(transit, IntervalRange) is True, and either can be passed wherever a window is expected.

Coordinate frames

propagate() returns a StateVectorTeme. The frame chain is available step by step if you need an intermediate:

sv_teme = predictor.propagate(t)   # StateVectorTeme
sv_ecef = sv_teme.to_ecef(t)       # StateVectorEcef  (GMST rotation)
sv_enu  = sv_ecef.to_enu(gs)       # StateVectorEnu   (geodetic to local ENU)
obs     = sv_enu.to_observation()  # equivalent to predictor.observe_at(t, gs)

All three expose .position and .velocity as Vec3(x, y, z).

Units

SI throughout: positions in metres, velocities and range rate in m/s, apsis altitude in metres above the WGS-84 equatorial radius. Angles are plain floats in degrees — every angular name is suffixed _deg.

Azimuth is measured clockwise from north over (-180, 180], so a southwesterly bearing is negative rather than the [0, 360) most tracking software reports.

Development

cd sgp4-predict-py/
uv sync --extra dev   # create .venv and install dev dependencies
make dev              # compile the Rust extension in-place (maturin develop)
make test             # compile + run pytest
make lint             # ruff check --fix + ruff format

make targets use uv run, so no venv activation is needed.

Type stubs live in two files: python/sgp4_predict/_sgp4_predict/__init__.pyi is generated by make stubs after Rust API changes and is not committed, while python/sgp4_predict/__init__.pyi is hand-maintained and owns IntervalRange, Interval, and the typed Predictor overrides.

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

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

sgp4_predict-0.1.0.tar.gz (264.0 kB view details)

Uploaded Source

Built Distributions

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

sgp4_predict-0.1.0-cp310-abi3-win_amd64.whl (395.0 kB view details)

Uploaded CPython 3.10+Windows x86-64

sgp4_predict-0.1.0-cp310-abi3-musllinux_1_2_x86_64.whl (792.1 kB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ x86-64

sgp4_predict-0.1.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (595.1 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ x86-64

sgp4_predict-0.1.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (576.3 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ARM64

sgp4_predict-0.1.0-cp310-abi3-macosx_11_0_arm64.whl (520.1 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

sgp4_predict-0.1.0-cp310-abi3-macosx_10_12_x86_64.whl (516.1 kB view details)

Uploaded CPython 3.10+macOS 10.12+ x86-64

File details

Details for the file sgp4_predict-0.1.0.tar.gz.

File metadata

  • Download URL: sgp4_predict-0.1.0.tar.gz
  • Upload date:
  • Size: 264.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for sgp4_predict-0.1.0.tar.gz
Algorithm Hash digest
SHA256 8b90aa4bd82bb23fa0ebe7f2833b7ddbe6cf9ce67b61f793df718fb56ab84291
MD5 d612839ec247fcec117c51b2dfeebfc3
BLAKE2b-256 ffec57e45fed63d3c640fb20d4100cfa901c9dc5f76931df3d78942d2db35d2c

See more details on using hashes here.

Provenance

The following attestation bundles were made for sgp4_predict-0.1.0.tar.gz:

Publisher: release.yml on steg87/sgp4-predict

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file sgp4_predict-0.1.0-cp310-abi3-win_amd64.whl.

File metadata

  • Download URL: sgp4_predict-0.1.0-cp310-abi3-win_amd64.whl
  • Upload date:
  • Size: 395.0 kB
  • Tags: CPython 3.10+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for sgp4_predict-0.1.0-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 f07e23ff47a989c4799f8593cda1f0a3dc3354e00f67946b1b3401bbf159c873
MD5 accaacde5032b9b79410821b9950c85e
BLAKE2b-256 064ad6cae981d0fb4250726537090aa743a9d0b37ea426d67214311ccd8aaa3f

See more details on using hashes here.

Provenance

The following attestation bundles were made for sgp4_predict-0.1.0-cp310-abi3-win_amd64.whl:

Publisher: release.yml on steg87/sgp4-predict

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file sgp4_predict-0.1.0-cp310-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for sgp4_predict-0.1.0-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 08683e02bdbfbc57e54cbceda3f55b9434e47fd463d2019810a02725cb0f05dc
MD5 578d92a9edf772b41ab410e643863194
BLAKE2b-256 adb06d9dbf2d90cf261a63779f3263caede161662c4af5819876ea883bc872cb

See more details on using hashes here.

Provenance

The following attestation bundles were made for sgp4_predict-0.1.0-cp310-abi3-musllinux_1_2_x86_64.whl:

Publisher: release.yml on steg87/sgp4-predict

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file sgp4_predict-0.1.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for sgp4_predict-0.1.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d728a3220bacf9ff8f7d3f68e4e2669348343aada2d4fe09fd57eb9111ac38a9
MD5 37695233c388ed27fea12188719f302f
BLAKE2b-256 2dec7a2aa672be8d39693c571c7a712106c82ee9ebf23c97bfa7e74daf6da259

See more details on using hashes here.

Provenance

The following attestation bundles were made for sgp4_predict-0.1.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release.yml on steg87/sgp4-predict

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file sgp4_predict-0.1.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for sgp4_predict-0.1.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 e5ae8bd65f090969d0c2684a3df7dfb2c83e1232b6a62a48335c3354a7aaafef
MD5 1aef6a5e55c526cd846e88f5dabb076a
BLAKE2b-256 8c87aec553c3e9d28d228d776ba28dd9cd159010a5586f06eed075ab801b690f

See more details on using hashes here.

Provenance

The following attestation bundles were made for sgp4_predict-0.1.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: release.yml on steg87/sgp4-predict

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file sgp4_predict-0.1.0-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for sgp4_predict-0.1.0-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 148c791ad77ec6be8427daa0a9a5b0c239041ac435bc4565710ba83b2b2d1356
MD5 0495007face5447a87c8d28066b0e150
BLAKE2b-256 c0073a71bb654ba9222628359b7647db4d87f22af3e42689d003543cc3b0fc3a

See more details on using hashes here.

Provenance

The following attestation bundles were made for sgp4_predict-0.1.0-cp310-abi3-macosx_11_0_arm64.whl:

Publisher: release.yml on steg87/sgp4-predict

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file sgp4_predict-0.1.0-cp310-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for sgp4_predict-0.1.0-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 1dbcb9dfdd47b22a237ceb2c95652153382bda97d3de20753b73135eb12a5a78
MD5 fe8bee852c8824e90ca58bb9dbc21896
BLAKE2b-256 11179c0a2d996eb9ad6d4d341507db24dfab78356ba94c4a5e701248d17dc476

See more details on using hashes here.

Provenance

The following attestation bundles were made for sgp4_predict-0.1.0-cp310-abi3-macosx_10_12_x86_64.whl:

Publisher: release.yml on steg87/sgp4-predict

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