Skip to main content

Python bindings for sgp4-predict satellite pass prediction

Reason this release was yanked:

Released v0.1.0

Project description

sgp4-predict — Python bindings

PyPI License: MIT OR Apache-2.0

Python bindings for the sgp4-predict Rust library, providing typed satellite pass prediction from Two-Line Element (TLE) data.

Installation

pip install sgp4-predict

Requires Python 3.10+.

Quick start

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

# Sentinel-2C 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)

# Ground station: Glasgow
glasgow = GroundObserver(latitude_deg=55.86, longitude_deg=-4.25, altitude=40.0)

# Find passes over the next 24 hours
window = Interval(
    start=datetime(2025, 12, 22, tzinfo=timezone.utc),
    end=datetime(2025, 12, 23, tzinfo=timezone.utc),
)

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

    # Iterate observations over just this transit — pass it directly as an interval
    step = timedelta(seconds=10)
    for t, obs in predictor.observation_iter(glasgow, transit, step):
        print(f"  {t}: az={obs.azimuth_deg:.1f}° el={obs.elevation_deg:.1f}°")

Core concepts

TLE data

TLEs are the standard input format for SGP4 propagation. Fresh TLEs can be obtained from sources such as CelesTrak. SGP4 accuracy degrades with TLE age — for LEO satellites, TLEs older than 3–7 days should be treated with caution. Use predictor.tle_age_seconds(now) to check.

Units

All values are in SI units unless noted otherwise:

Quantity Unit
Position metres
Velocity m/s
Range metres
Range rate m/s (positive = receding)
Azimuth / elevation radians (use _deg properties for degrees)
Altitude (apsis) metres above WGS-84 equatorial radius
GroundObserver lat/lon input degrees
GroundObserver altitude input metres

API reference

Interval and IntervalRange

All iterator methods and max_elevation accept any object that exposes .start and .end datetime properties — the IntervalRange protocol. Transit and Illumination satisfy this protocol automatically, so they can be passed directly wherever an interval is expected.

Interval is a concrete helper for constructing a plain datetime interval:

from sgp4_predict import Interval, IntervalRange

window = Interval(start=datetime(..., tzinfo=timezone.utc), end=datetime(..., tzinfo=timezone.utc))

# isinstance check works at runtime
assert isinstance(window, IntervalRange)   # True
assert isinstance(transit, IntervalRange)  # True — Transit satisfies the protocol

Tle

Holds the raw TLE strings. No parsing happens here.

tle = Tle(satellite_name="ISS", line_1="1 25544U ...", line_2="2 25544 ...")

tle.satellite_name  # str
tle.line_1  # str
tle.line_2  # str

GroundObserver

A fixed point on Earth's surface. Lat/lon are accepted in degrees.

gs = GroundObserver(latitude_deg=51.5, longitude_deg=-0.1, altitude=10.0)

gs.latitude_deg   # float — geodetic latitude (degrees, positive north)
gs.longitude_deg  # float — geodetic longitude (degrees, positive east)
gs.altitude  # float — metres above WGS-84 ellipsoid

Predictor

The main entry point. Pre-computes SGP4 constants.

p = Predictor.from_tle(tle)  # from a Tle object — raises ValueError on malformed TLE
p = Predictor(elements)      # from a pre-parsed Elements (OMM JSON) object
p.epoch                      # datetime (UTC) — element epoch
p.tle_age_seconds(now)       # float — seconds since epoch (positive = past)

Propagation

sv = p.propagate(t)          # StateVectorTeme — satellite state at UTC datetime t

Point observation

obs = p.observe_at(t, observer)  # Observation — az/el/range from observer at time t

Iterators

All iterators are lazy and implement the Python iterator protocol. Every method that takes a time range accepts any IntervalRange — an Interval, a Transit, an Illumination, or any object with .start and .end.

window = Interval(start, end)

# State vectors at regular intervals
for t, sv in p.prediction_iter(window, step):
    ...  # t: datetime, sv: StateVectorTeme

# Observations at regular intervals
for t, obs in p.observation_iter(observer, window, step):
    ...  # t: datetime, obs: Observation

# Visible passes
for transit in p.transits_iter(observer, window, min_elevation_deg=5.0):
    ...  # Transit

# Apogee / perigee events
for apsis in p.apsis_iter(window):
    ...  # Apsis

# Sunlit / eclipse windows
for illumination in p.illumination_iter(window):
    ...  # Illumination

Because Transit and Illumination satisfy IntervalRange, you can pass them directly:

# Iterate observations over exactly one transit
for t, obs in p.observation_iter(observer, transit, step):
    ...

# Predict over a sunlit window only
for t, sv in p.prediction_iter(illumination, step):
    ...

Transit detection and peak elevation

# Detect whether a transit is in progress at time t
# Returns Transit or None
transit = p.detect_transit(t, observer, min_elevation_deg=5.0)

# Find the peak elevation moment within an interval
# Returns (datetime, Observation) — raises RuntimeError if no peak found
t_peak, obs_peak = p.max_elevation(observer, window)

Illumination state

from sgp4_predict import IlluminationState

state = p.illumination_state(t)  # IlluminationState.Sunlit or .Eclipse

Return types

Transit

A window during which the satellite is above the minimum elevation. Satisfies IntervalRange.

transit.start             # datetime (UTC) — Acquisition of Signal (AoS)
transit.end               # datetime (UTC) — Loss of Signal (LoS)
transit.duration_seconds  # float

Observation

Point observation from a ground station.

obs.azimuth_deg   # float — degrees, 0 = North, clockwise
obs.elevation_deg # float — degrees above horizon
obs.range         # float — metres
obs.range_rate    # float — m/s, positive = receding

Apsis and ApsisEvent

from sgp4_predict import ApsisEvent

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

Illumination and IlluminationState

A contiguous sunlit or eclipse window. Satisfies IntervalRange.

from sgp4_predict import IlluminationState

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

Coordinate frames

propagate() returns a StateVectorTeme. You can walk the full frame chain manually:

sv_teme = p.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() # Observation

# Equivalent shorthand:
obs = p.observe_at(t, gs)

All three state vector types expose .position and .velocity as Vec3(x, y, z) in metres / m/s.

Advanced: Refinement

Root-finder configuration used to refine detected event times (transit boundaries, apsides, shadow crossings, peak elevation). A bracketed hybrid solver: Newton-Raphson steps when a derivative is available, secant/bisection otherwise, converging once the crossing time is pinned down to time_tolerance seconds.

from sgp4_predict import Refinement

ref = Refinement()
ref.time_tolerance = 1e-3  # seconds (default)
ref.max_iter       = 100   # (default)

p2 = p.with_refinement(ref)

Local development

Setup

cd sgp4-predict-py/
uv sync --extra dev

Commands

make dev    # compile the Rust extension in-place (maturin develop)
make test   # compile + run pytest
make stubs  # regenerate _sgp4_predict/__init__.pyi stub file
make lint   # ruff check + ruff format --check

No venv activation needed — make targets use uv run and resolve the local .venv automatically.

Stub files

Type stubs live in two files with different ownership:

File Ownership
python/sgp4_predict/_sgp4_predict/__init__.pyi Auto-generated — run make stubs to update after Rust changes
python/sgp4_predict/__init__.pyi Hand-maintained — owns IntervalRange, Interval, and the typed Predictor overrides

The hand-maintained stub is committed to the repository. The auto-generated one is not committed and must be built with make stubs.

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.0.1rc1.tar.gz (254.1 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.0.1rc1-cp310-abi3-win_amd64.whl (391.0 kB view details)

Uploaded CPython 3.10+Windows x86-64

sgp4_predict-0.0.1rc1-cp310-abi3-musllinux_1_2_x86_64.whl (788.0 kB view details)

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

sgp4_predict-0.0.1rc1-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (591.1 kB view details)

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

sgp4_predict-0.0.1rc1-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (572.4 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ARM64

sgp4_predict-0.0.1rc1-cp310-abi3-macosx_11_0_arm64.whl (516.0 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

sgp4_predict-0.0.1rc1-cp310-abi3-macosx_10_12_x86_64.whl (512.0 kB view details)

Uploaded CPython 3.10+macOS 10.12+ x86-64

File details

Details for the file sgp4_predict-0.0.1rc1.tar.gz.

File metadata

  • Download URL: sgp4_predict-0.0.1rc1.tar.gz
  • Upload date:
  • Size: 254.1 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.0.1rc1.tar.gz
Algorithm Hash digest
SHA256 969eab8a959e473cd61741f4ad9edcfa2caa0d58851bd68851ad82bbd096f263
MD5 8e204b93f26b3e401147d495c50b02f6
BLAKE2b-256 c44d8e41a155018f0b1f3fb91864e71c376bf4b7d676b52d252d5a04cc19ec6d

See more details on using hashes here.

Provenance

The following attestation bundles were made for sgp4_predict-0.0.1rc1.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.0.1rc1-cp310-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for sgp4_predict-0.0.1rc1-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 b3686ee8d19566df4c2a7b6436b56f1a8a8176b71565808d22c9621e03680b82
MD5 8da0b84314bd09ef62894c6a98c8ccb4
BLAKE2b-256 b46aa9ea6ef5b30cb5c0a064b81e054c28327a5dca0765a59877507210af4001

See more details on using hashes here.

Provenance

The following attestation bundles were made for sgp4_predict-0.0.1rc1-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.0.1rc1-cp310-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for sgp4_predict-0.0.1rc1-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 4dd51d0d03f59cc4912331cc41681bfe6b40ed7f232b8b8d1dd6e0b789b035fc
MD5 638ed47f7f02e46e89b9e2a8b698fc17
BLAKE2b-256 506367ca15b8bf161894f528d12ab33d792bfa17ce50fbff151e7676476787f8

See more details on using hashes here.

Provenance

The following attestation bundles were made for sgp4_predict-0.0.1rc1-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.0.1rc1-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for sgp4_predict-0.0.1rc1-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c9bee429fb87535fc2cbe3a6d981b50e9ff32299a48a32d7889409a57fcef695
MD5 126394eae79d20f9d495b1e1c8528563
BLAKE2b-256 d2bff50abc10fb85137a6fc56964b64cec049c45f4bbafec70adc44208eca3a0

See more details on using hashes here.

Provenance

The following attestation bundles were made for sgp4_predict-0.0.1rc1-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.0.1rc1-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for sgp4_predict-0.0.1rc1-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 d487586c0d4bcee6de820c2aac4ba5cad1cfffc7923239b182535463b82108e9
MD5 701f8dcfd057b2042e1d5ee0a9d1086c
BLAKE2b-256 c96375918b09d981bc0972c0dd72414358726ddaf46523136aece614fb796c12

See more details on using hashes here.

Provenance

The following attestation bundles were made for sgp4_predict-0.0.1rc1-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.0.1rc1-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for sgp4_predict-0.0.1rc1-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b0ee4ec4aaf4c0b43c699aacffde456470940b4cff1c6bf31cf9efe555767ee1
MD5 2590434172da86aceb3bbb4f009158e3
BLAKE2b-256 52e074c8985d5adf0a448a71393de2791110114371b4e71f9f392662d9e622f4

See more details on using hashes here.

Provenance

The following attestation bundles were made for sgp4_predict-0.0.1rc1-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.0.1rc1-cp310-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for sgp4_predict-0.0.1rc1-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 f6f51c9f087e0721d67ad6ef6e7d50817d90d8dbc5739418b726917f647c9838
MD5 6beeb037b6ecb7bcb7d5b7b06dc48ad2
BLAKE2b-256 1d18b061c8daf76ea799245ff83c222b4cb0f2237ec6eec71e1e34b5a02916c6

See more details on using hashes here.

Provenance

The following attestation bundles were made for sgp4_predict-0.0.1rc1-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