Registry / data / spiceypy

spiceypy

JSON →
library8.1.2pypypi✓ verified 85d ago

SpiceyPy is a Python wrapper for NASA's NAIF CSPICE Toolkit, providing tools for computing ephemeris, attitude, event finding, and geometry for spacecraft and celestial bodies. It enables Python users to leverage the powerful CSPICE library. The library is actively maintained with frequent releases, currently at version 8.1.0, and often includes performance enhancements and new features.

pip install spiceypy
INSTALL
IMPORT
SIG · SPICEYPY
S
spiceypy
datapythonv8.1.2
Install
3.9s avg
Import
883ms
Disk
96MB
Pass rate
5/ 10
Env Coverage5 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v8.1.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
glibc
py 3.10
✕ build_error
1/2 runs
py 3.11
✕ build_error
✓ 3.7s
py 3.12
✕ build_error
✓ 3.6s
py 3.13
✕ build_error
✓ 3.8s
py 3.9
✓ —
✓ 4.3s
96MB installed
● package 96MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

spiceypy
import spiceypy as spice
Cyice
from spiceypy import cyice
Introduced in v7.0.0 for C-accelerated SPICE functions. Use `cyice` functions for performance-critical applications.

This quickstart demonstrates loading a leap second kernel (LSK) using `spice.furnsh()`, converting a UTC time string to Ephemeris Time (ET) with `spice.str2et()`, and then calculating the position of Earth relative to the Sun using `spice.spkpos()`. It's crucial to download and correctly point to actual SPICE kernel files (LSK, PCK, SPK, FK, IK, CK) from the NAIF website for real applications. The example includes a placeholder for a kernel path.

import spiceypy as spice import os # A simple kernel file for demonstration # In a real application, you would download these from NAIF # For local testing, ensure naif0012.tls is in the script's directory # or specify its full path. kernel_path = os.path.join(os.path.dirname(__file__), 'naif0012.tls') if not os.path.exists(kernel_path): # This is a dummy for demonstration. You would fetch a real kernel. print(f"Warning: '{kernel_path}' not found. Please download from NAIF if this isn't a test.") # Example: You'd typically download like this (replace with actual URL and process) # import urllib.request # url = 'https://naif.jpl.nasa.gov/pub/naif/generic_kernels/lsk/naif0012.tls' # urllib.request.urlretrieve(url, kernel_path) # Load a leap second kernel (LSK) to define Ephemeris Time (ET) try: spice.furnsh(kernel_path) except spice.exceptions.SpiceyPyError as e: print(f"Failed to load kernel: {e}. Skipping calculations.") exit() # Convert a UTC string to Ephemeris Time (ET) utc_time = '2023-01-01 T00:00:00' et = spice.str2et(utc_time) print(f"UTC: {utc_time} -> ET: {et}") # Get position of Earth relative to the Sun # Observer: SUN, Target: EARTH, Reference Frame: J2000, Aberration Correction: NONE pos, lt = spice.spkpos('EARTH', et, 'J2000', 'NONE', 'SUN') print(f"Position of Earth relative to Sun (km): {pos}") # Unload all kernels spice.unload(kernel_path) # Alternatively, spice.kclear() clears all loaded kernels
Debug
Known issues
gotchaFailing to load necessary SPICE kernels (e.g., Leap Seconds, PCK, SPK) via `spice.furnsh()` is the most common pitfall. Many SPICE functions will fail with cryptic errors or return incorrect results without the required data loaded into the kernel pool.
fix
Always call `spice.furnsh()` with paths to the required kernel files before performing any SPICE computations. Use `spice.kclear()` to unload all kernels or `spice.unload()` for specific ones when done.
affects: All versions
breakingThe order of `NotFound` exception checks and error handling was swapped in v8.0.0. This change aims to prevent spurious `NotFound` exceptions but might subtly alter error propagation for code that previously relied on the exact timing or order of these checks.
fix
Review error handling logic for SPICE functions that return a `found` flag. Ensure your code correctly handles both `NotFound` exceptions and the `found` flag where applicable. The intent is improved robustness, so existing code *should* ideally become more stable, but edge cases might require adaptation.
affects: >=8.0.0
gotchaSpiceyPy v7.0.0 introduced `cyice`, a Cython-accelerated submodule for performance. While largely 'drop-in', functions called via `cyice.function_name` are C-extensions. Debugging or introspection might differ slightly from the `ctypes`-based `spiceypy` functions. Installation on unusual platforms or without appropriate build tools can also be more complex without pre-built wheels.
fix
For performance-critical code, consider explicitly importing and using `cyice` functions (`from spiceypy import cyice`). If installation issues arise, ensure you have a C compiler (e.g., GCC, MSVC) and `numpy` installed, or look for pre-built wheels for your specific Python version and OS.
affects: >=7.0.0
gotchaSPICE functions typically operate using Ephemeris Time (ET), which is seconds past J2000 epoch. Direct use of Python's `datetime` objects or UTC strings often requires conversion via functions like `spice.str2et()` and `spice.et2utc()`. Incorrectly mixing time systems is a common source of errors.
fix
Always convert your input times to ET using `spice.str2et()` or similar functions before passing them to SPICE routines. Convert results back to UTC or `datetime` as needed for display or further processing using `spice.et2utc()`.
affects: All versions
Errors
Common errors & fixes
SPICE(NOKERNELDATA): No kernel data available for object/frame 'EARTH' at time...
A required SPICE kernel (e.g., an SPK for ephemeris, or PCK for planetary constants) has not been loaded using `spice.furnsh()`.
fix
Before calling SPICE functions, ensure all necessary kernels are loaded: `spice.furnsh('/path/to/my_kernel.bsp')`, `spice.furnsh('/path/to/my_lsk.tls')`, etc. Consult NAIF documentation to understand which kernels are needed for your specific calculation.
FileNotFoundError: [Errno 2] No such file or directory: '/path/to/missing_kernel.bsp'
The file path provided to `spice.furnsh()` does not exist or is incorrect.
fix
Verify that the kernel file exists at the specified path and that the path is spelled correctly. Use absolute paths or ensure the file is in a location accessible by your script.
TypeError: argument of type 'int' is not iterable
A SPICEyPy function expected an array-like input (e.g., a NumPy array or list of numbers) but received a scalar value.
fix
Ensure inputs match the expected type. For functions expecting an array, pass a `numpy.array([value])` even for single values. Consult the function's docstring for expected input types and shapes.
Upgrade
Version history
8.1.2latest on PyPI · released Jun 14, 2026
Audit
Dependencies
numpyrequiredRequired for array operations and numerical data handling within SPICE functions.
Agent activity
19 hits · last 30 days
node
10
Amazon
1
OpenAI (training)
1
Resources
spiceypy — pip install spiceypy · libregistry