A high-performance WebAssembly interface to the Swiss Ephemeris astronomical library, providing precise planetary calculations for web-based astrology applications.
sweph-wasm is a modern WebAssembly implementation of the renowned Swiss Ephemeris library, specifically designed for web-based astrological applications. This project provides a complete, high-precision astronomical calculation engine that runs entirely in the browser, delivering professional-grade astrological computations with arc-second accuracy.
- Swiss Ephemeris Quality: Built on the same astronomical engine used by professional astrology software worldwide
- Single-File Deployment: Everything embedded into one JavaScript file with LZ4 compression (~1.9MB)
- 50+ Celestial Bodies: Major planets, Moon, Sun, plus 50 numbered asteroids (Ceres, Pallas, Juno, Vesta, etc.)
- Complete Astrological Suite: Planetary positions, house systems, nodes, apsides, aspects, and more
- High Precision: Arc-second accuracy for dates 1800-2400 CE, suitable for research and professional use
- Modern Web Standards: Pure WebAssembly with JSON API, no dependencies, works offline
- Comprehensive House Systems: Placidus, Koch, Whole Sign, Equal, Regiomontanus, Campanus, and more
- Professional Astrology Software: Birth charts, transits, progressions, solar returns
- Astrological Research: Academic and statistical studies with precise calculations
- Mobile Astrology Apps: Lightweight, fast calculations for iOS/Android web apps
- Educational Tools: Teaching astronomy and astrology with accurate data
- API Services: Backend calculations for astrology websites and services
- Personal Projects: Hobbyist astrology applications and experiments
- WebAssembly Core: Compiled with Emscripten for maximum performance
- Embedded Ephemeris: No external file dependencies, works offline
- Memory Efficient: Smart memory management with automatic cleanup
- Cross-Platform: Runs identically on all modern browsers and Node.js
- Developer Friendly: Simple JSON API with comprehensive documentation
- Production Ready: Battle-tested Swiss Ephemeris engine with 25+ years of development
Perfect for developers building astrology applications, researchers needing precise astronomical data, or anyone wanting professional-quality astrological calculations in a modern web environment.
- Complete Astrological Calculations: Planetary positions, house systems, nodes, apsides, and asteroids
- Single-File Deployment: Embedded ephemeris data with LZ4 compression
- High Precision: Arc-second accuracy for dates 1800-2400 CE
- Modern WebAssembly: Optimized for performance and small bundle size
- Comprehensive API: JSON output format for easy JavaScript integration
- All House Systems: Placidus, Koch, Whole Sign, Equal, and more
- Swiss Ephemeris Quality: Same precision as professional astronomy software
- Emscripten SDK
- Make build system
- Web server for testing (or use
emrun)
# Clone the repository
git clone <repository-url>
cd sweph-wasm
# Build the WebAssembly module
cd lib/src
make embedded
# Install to web directory
make install
# Run the test application
cd ../../
emrun index.htmlThis creates a single JavaScript file (astro-embedded.js) containing all ephemeris data and WebAssembly code.
| Target | Description | Output | Size |
|---|---|---|---|
embedded |
Single-file production build (recommended) | astro-embedded.js |
~1.9MB |
development |
Multi-file debug build | .js + .wasm + .data |
~4.2MB |
install |
Deploy embedded build to js/ directory |
Ready for web | - |
clean |
Remove all build artifacts | - | - |
cd lib/src
# Production build (recommended)
make embedded && make install
# Development build (for debugging)
make development && make install-dev
# Clean build artifacts
make clean
# Show build information
make infosweph-wasm/
βββ lib/src/
β βββ astro.c # Main WebAssembly interface
β βββ Makefile # Build system
β βββ eph/ # Swiss Ephemeris data files
β β βββ sepl_18.se1 # Major planets (Sun through Pluto)
β β βββ semo_18.se1 # Moon ephemeris (high precision)
β β βββ seas_18.se1 # Major asteroids (Ceres, Pallas, Juno, Vesta, Chiron)
β β βββ se00005s.se1 to se00050s.se1 # Numbered asteroids 5-50
β βββ ../sweph/src/ # Swiss Ephemeris source code
βββ js/ # Output directory for built files
βββ index.html # Test application
βββ README.md
The ephemeris files are sourced from the official Swiss Ephemeris repository and provide:
- Date Range: 1800-2400 CE (high precision)
- Planets: Sun through Pluto + 50 numbered asteroids
- Accuracy: Arc-second precision for planetary positions
- Coordinate Systems: Tropical zodiac, geocentric positions
- File Format: Native Swiss Ephemeris
.se1format
sepl_18.se1- Major planets (Sun through Pluto)semo_18.se1- Lunar ephemeris (high precision)seas_18.se1- Major asteroids (Ceres, Pallas, Juno, Vesta, Chiron)se00005s.se1tose00050s.se1- Numbered asteroids 5-50 (46 additional asteroids)
| Number | Name | Significance |
|---|---|---|
| 1 | Ceres | Largest asteroid, dwarf planet, nurturing |
| 2 | Pallas | Wisdom, creative intelligence |
| 3 | Juno | Marriage, partnerships, loyalty |
| 4 | Vesta | Hearth, devotion, sacred flame |
| 5 | Astraea | Justice, innocence, purity |
| 10 | Hygiea | Health, healing, hygiene |
| 16 | Psyche | Soul, psychology, transformation |
| 19 | Fortuna | Fortune, luck, chance |
| 26 | Proserpina | Transformation, underworld |
| 433 | Eros | Love, passion, desire |
This library provides comprehensive calculations for planetary nodes and apsides (orbital extreme points):
- Ascending Node: Where a planet's orbit crosses the ecliptic plane going north
- Descending Node: Where a planet's orbit crosses the ecliptic plane going south
- Perihelion: Closest point to the Sun in the planet's orbit
- Aphelion: Farthest point from the Sun in the planet's orbit
| Method | Description | Best For |
|---|---|---|
| 0 (Mean) | Mean orbital elements | Traditional astrology, long-term trends |
| 1 (Osculating) | Instantaneous orbital elements | Precise timing, current conditions |
| 2 (Barycentric) | Solar system center of mass | Outer planets, research |
| 4 (Focal Point) | Focal points instead of apsides | Alternative calculation method |
// Calculate nodes for all major planets
const nodesPtr = Module._getPlanetaryNodes(2023, 12, 25, 12, 0, 0, 1, 50000);
const nodesData = JSON.parse(Module.UTF8ToString(nodesPtr));
// Access planetary nodes
nodesData.nodes.forEach(planet => {
console.log(`${planet.name} North Node: ${planet.ascending_node.long_s}`);
console.log(`${planet.name} South Node: ${planet.descending_node.long_s}`);
console.log(`${planet.name} Perihelion: ${planet.perihelion.long_s}`);
console.log(`${planet.name} Aphelion: ${planet.aphelion.long_s}`);
});
// Calculate nodes for a specific planet (Mars = planet 4)
const marsNodesPtr = Module._getSinglePlanetNodes(4, 2460310.0, 1, 10000);
const marsNodes = JSON.parse(Module.UTF8ToString(marsNodesPtr));- Karmic Astrology: Lunar nodes for soul purpose and lessons
- Planetary Cycles: Understanding orbital patterns and timing
- Harmonic Astrology: Advanced techniques using nodal positions
- Mundane Astrology: Planetary nodes in world events
- Eclipse Prediction: Nodes determine eclipse locations
- Spiritual Astrology: Soul evolution through nodal analysis
All functions return JSON strings with calculation results:
// Complete birth chart
const chartPtr = Module._get(year, month, day, hour, minute, second,
lonG, lonM, lonS, lonEW, latG, latM, latS, latNS, houseSystem);
const chart = JSON.parse(Module.UTF8ToString(chartPtr));
// Planetary positions only
const planetsPtr = Module._getPlanets(year, month, day, hour, minute, second);
const planets = JSON.parse(Module.UTF8ToString(planetsPtr));
// House cusps and angles
const housesPtr = Module._getHouses(year, month, day, hour, minute, second,
lonG, lonM, lonS, lonEW, latG, latM, latS, latNS, houseSystem);
const houses = JSON.parse(Module.UTF8ToString(housesPtr));
// Single planet position
const planetPtr = Module._getPlanet(planetId, year, month, day, hour, minute, second);
const planet = JSON.parse(Module.UTF8ToString(planetPtr));
// Julian Day calculation
const jdPtr = Module._getJulianDay(year, month, day, hour, minute, second);
const julianDay = JSON.parse(Module.UTF8ToString(jdPtr));
// Asteroid calculations
const asteroidsPtr = Module._getAsteroids(year, month, day, hour, minute, second, 1, 50, 100000);
const asteroids = JSON.parse(Module.UTF8ToString(asteroidsPtr));
// Specific asteroids by number
const specificPtr = Module._getSpecificAsteroids(year, month, day, hour, minute, second, "1,2,3,4,433", 50000);
const specificAsteroids = JSON.parse(Module.UTF8ToString(specificPtr));
// Planetary nodes and apsides
const nodesPtr = Module._getPlanetaryNodes(year, month, day, hour, minute, second, 1, 50000);
const planetaryNodes = JSON.parse(Module.UTF8ToString(nodesPtr));
// Single planet nodes (Mars = 4)
const marsNodesPtr = Module._getSinglePlanetNodes(4, 2460310.0, 1, 10000);
const marsNodes = JSON.parse(Module.UTF8ToString(marsNodesPtr));// Calculate birth chart for December 25, 2023, 12:00 PM in London
const result = Module._get(2023, 12, 25, 12, 0, 0, // Date/time
0, 5, 30, "W", // Longitude: 0Β°5'30"W
51, 30, 0, "N", // Latitude: 51Β°30'0"N
"P"); // Placidus houses
const chartData = JSON.parse(Module.UTF8ToString(result));
// Access results
console.log("Sun position:", chartData.planets[0].long, "degrees");
console.log("Sun sign:", chartData.planets[0].long_s);
console.log("Ascendant:", chartData.ascmc[0].long_s);
console.log("Midheaven:", chartData.ascmc[1].long_s);| Function | Purpose | Returns |
|---|---|---|
_get() |
Complete astrological chart | Planets + houses + angles |
_getPlanets() |
Planetary positions only | Planet data array |
_getHouses() |
House cusps and angles | House system data |
_getPlanet() |
Single planet calculation | Individual planet data |
_getPlanetaryNodes() |
Nodes and apsides for all planets | Orbital extreme points |
_getSinglePlanetNodes() |
Nodes for specific planet | Single planet orbital data |
_getAsteroids() |
Asteroid positions by range | Multiple asteroid data |
_getSpecificAsteroids() |
Specific asteroids by number | Selected asteroid data |
_getJulianDay() |
Date to Julian Day conversion | Calendar conversion |
_degreesToDMS() |
Format degrees as DMS | Formatted coordinate string |
Supported house systems (use single character codes):
| Code | System | Description |
|---|---|---|
P |
Placidus | Most popular modern system |
K |
Koch | Popular in Europe |
W |
Whole Sign | Ancient system, each sign = house |
E |
Equal | 30Β° houses from Ascendant |
R |
Regiomontanus | Medieval system |
C |
Campanus | Medieval great circle system |
O |
Porphyry | Divides quadrants equally |
T |
Topocentric | Modern Polich/Page system |
The project includes a test application (index.html) that demonstrates all API functions:
# Run test server
emrun index.html
# Or use any local web server
python -m http.server 8000
# Then visit http://localhost:8000For detailed astronomical and astrological background, see:
All calculations use:
- Tropical Zodiac: 0Β° Aries = Spring Equinox
- Geocentric Coordinates: Earth-centered positions
- Ecliptic Reference: Mean ecliptic and equinox of date
- Longitude Range: 0-360Β° (Aries 0Β° to Pisces 30Β°)
- Latitude Range: -90Β° to +90Β° (South negative, North positive)
- Bundle Size: 1.9MB (single file, compressed)
- Load Time: ~500ms on 3G connection
- Calculation Speed: Complete birth chart in <10ms
- Memory Usage: ~8MB runtime memory
- Browser Support: All modern browsers with WebAssembly
// Set custom ephemeris file location
Module._setEphemerisPath("/custom/eph/path/");// Free memory for large result strings
const resultPtr = Module._get(/* ... */);
const result = Module.UTF8ToString(resultPtr);
Module._freeMemory(resultPtr);try {
const result = JSON.parse(Module.UTF8ToString(resultPtr));
if (result.error) {
console.error("Calculation error:", result.error_msg);
}
} catch (e) {
console.error("JSON parsing failed:", e.message);
}- Browser: WebAssembly support (all modern browsers)
- Server: Any web server (CORS restrictions apply to file:// protocol)
- Memory: 8MB+ available JavaScript heap
- Network: ~2MB initial download for embedded build
# Ensure Emscripten is installed and activated
source /path/to/emsdk/emsdk_env.sh
# Navigate to source directory
cd lib/src
# Development build with debug symbols
make development
# Production build with maximum optimization
make embedded
# Verify build
make verifyTo add more ephemeris files:
- Download additional
.se1files from Swiss Ephemeris repository - Place files in
lib/src/eph/directory - Rebuild:
make clean && make embedded
This project uses the Swiss Ephemeris library, which is available under:
- GPL v2+ for open source applications
- Commercial License for proprietary applications
See Swiss Ephemeris Licensing for details.
Contributions welcome! Please ensure:
- Code follows the existing style
- All tests pass:
make verify - Documentation is updated for API changes
- Commit messages are descriptive
For issues related to:
- WebAssembly Interface: Open an issue in this repository
- Swiss Ephemeris Calculations: Consult official documentation
- Astronomical Questions: See Swiss Ephemeris manual