Project

swisseph

0.0
The project is in a healthy, maintained state
Native bindings for the Swiss Ephemeris library (http://www.astro.com/swisseph/)
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

>= 5.16, < 5.27
~> 0.3.4
 Project Readme

Swisseph

Swiss Ephemeris for Ruby

Gem Version

Native Ruby bindings for the Swiss Ephemeris library (v2.10.3a), providing high-precision astronomical calculations for astrological applications.

History & Motivation

This gem is a modernized fork of the original aakara/swe4r. Since the original project has been abandoned, this version was created to:

  • Ensure compatibility with modern Ruby versions.
  • Automate the build process using CMake.
  • Provide more idiomatic Ruby aliases and convenience methods.
  • Maintain active support for the latest Swiss Ephemeris releases.

Convenience Features

Shorthand Methods

All swe_* methods are also available without the swe_ prefix:

# Traditional way:
Swisseph.swe_julday(2024, 1, 1, 12.0)

# Modern shorthand:
Swisseph.julday(2024, 1, 1, 12.0)

Module Aliases

For even shorter code, you can use the Sweph alias:

Sweph.julday(2024, 1, 1, 12.0)

Installation

gem install swisseph

Or add to your Gemfile:

gem 'swisseph'

Build Requirements

This gem requires CMake 3.14 or later to build from source. CMake is used to automatically download the Swiss Ephemeris library from GitHub during installation.

Installing CMake:

  • macOS: brew install cmake
  • Ubuntu/Debian: sudo apt-get install cmake
  • Windows: Download from cmake.org

Building swetest CLI

The Swiss Ephemeris includes swetest, a command-line tool for testing calculations. To build it:

rake swetest:build

Then copy the binary to your PATH:

cp ext/swisseph/swisseph_src/swetest ~/bin/

Quick Examples

Calculate Planetary Position

require 'swisseph'

# Get Julian day for May 14, 2012 at 10:15
jd = Sweph.julday(2012, 5, 14, 10.25)

# Calculate Sun position using Moshier ephemeris
sun = Sweph.calc_ut(jd, Sweph::SE_SUN, Sweph::SEFLG_MOSEPH | Sweph::SEFLG_SPEED)

puts "Sun longitude: #{sun[0]}°"
puts "Sun latitude: #{sun[1]}°"

Calculate House Cusps

require 'swisseph'

jd = Sweph.julday(2012, 5, 14, 10.25)
lat, lon = 45.45, -112.18

# Calculate Placidus houses
cusps, angles = Sweph.houses(jd, lat, lon, 'P')

puts "Ascendant: #{angles[0]}°"
puts "House 1: #{cusps[1]}°"

Supported Functions

The gem provides full coverage of the Swiss Ephemeris API. All functions are available in both swe_prefix and shorthand forms.

Category Key Functions
Planets calc_ut, calc, get_orbital_elements, pheno_ut
Fixed Stars fixstar_ut, fixstar2_ut, fixstar_mag
Houses houses, houses_ex, house_pos, house_name
Eclipses sol_eclipse_when_glob, lun_eclipse_when, sol_eclipse_where
Transits solcross_ut, mooncross_ut, rise_trans
Time julday, revjul, utc_to_jd, deltat, sidtime
Utilities set_ephe_path, set_topo, get_planet_name, split_deg

Constants

The gem provides constants for planets, calculation flags, and more:

# Bodies
Swisseph::SE_SUN, SE_MOON, SE_MERCURY, SE_VENUS, SE_MARS...
# Flags
Swisseph::SEFLG_MOSEPH, SEFLG_SWIEPH, SEFLG_SPEED, SEFLG_SIDEREAL...
# Houses
'P' (Placidus), 'K' (Koch), 'E' (Equal), 'C' (Campanus)...

Ephemeris Files

The Moshier ephemeris (SEFLG_MOSEPH) is built-in and requires no files.

For high-precision calculations, a minimal set of Swiss Ephemeris data files is automatically included during installation. For extended time ranges or asteroid files, download them from astro.com and configure:

Sweph.set_ephe_path('/path/to/ephemeris/files')

Documentation

License

GPL-2.0-or-later. See LICENSE for details. Swiss Ephemeris library is (C) Astrodienst AG.