Skip to article frontmatterSkip to article content

Overview

planets

PyPI Version Build Status Documentation Status Updates

Library to provide planetary constants

Package Structure

This package uses modern Python packaging with pyproject.toml for configuration and Hatch for build management. See the changelog file for more information about changes.

Development with Hatch

This project uses Hatch for build management, testing, and publishing:

# Install Hatch
pip install hatch

# Activate development environment
hatch shell

# Run tests
hatch run test:pytest

# Build package
hatch build

# Install in development mode
pip install -e .

Features

API Usage

You can access planetary data programmatically in your Python code:

# Import specific planets
from planets import Earth, Mars, Jupiter

# Access planetary properties
print(f"Earth's radius: {Earth.R} meters")
print(f"Mars' gravity: {Mars.g} m/s²")
print(f"Jupiter's sidereal length of year [s]: {Jupiter.year} seconds")

# Get list of all available bodies (new helper function)
from planets import get_all_bodies

available_bodies = get_all_bodies()
print(f"Available bodies: {available_bodies}")

# Retrieve body attributes with units
radius_km = Earth.R / 1000
orbit_years = Earth.year / (365.25 * 24 * 3600)
print(f"Earth's radius: {radius_km:.1f} km")
print(f"Earth's orbital period: {orbit_years:.2f} years")

Command Line Interface

The package includes a command-line interface for quick access to planetary data:

# List all available planetary bodies
planets --list

# Show all attributes for a specific body with units
planets --body Earth

# Show version information
planets --version

# Show help information
planets --help

Example output for planets --body Mars:

Attributes for Mars:
-------------------
S               = 589.2 W/m²
Tsavg           = 210.0 K
Tsmax           = 290.0 K
albedo          = 0.25 fraction
day             = 88775.244147 seconds
eccentricity    = 0.0934
emissivity      = 0.95 fraction
g               = 3.71 m/s²
name            = Mars
obliquity       = 25.19 radians
psurf           = 636.0 Pa
rAU             = 1.52366231 AU
rsm             = 2.27939366e+11 meters
year            = 59354294.4 seconds

Data Sources

Since version 0.6, planetary radii data is read directly from the official NASA SPICE Planetary Constants Kernel (PCK) version 0.11. This ensures that all radius values are consistent with the most widely used planetary constants in the scientific community. The package automatically downloads and parses the necessary SPICE kernel files using the pooch library.

SPICE PCK data provides authoritative values for:

Credits

Planetary Database

Modified by Paul Hayne from the “planets.py” library by Raymond T. Pierrehumbert

Last modified: June, 2017

Sources:

  1. http://nssdc.gsfc.nasa.gov/planetary/factsheet/
  2. Lang, K. (2012). Astrophysical data: planets and stars. Springer Science & Business Media.

Python packaging

This package was created with Cookiecutter and the forked michaelaye/cookiecutter-pypackage-conda project template.