Scientific computing2026In-house product build
lxephemeris

Legacy C ephemeris, rebuilt in memory-safe Rust

We replaced Swiss Ephemeris, a 1990s C library, and its Python wrappers with lxephemeris: one memory-safe Rust core, proven against 37,416 reference vectors before it went to production.

lxephemeris
22
legacy bugs fixed in the rewrite
37,416
reference vectors, 0 failures
12.8 µs
per body with speed
  • Scientific computing
  • In-house product build
  • 2026
The challenge

A 30-year-old C core under modern products

Most astrology and astronomy backends still compute positions with Swiss Ephemeris, a C library written in the 1990s. Python products reach it through wrappers such as pyswisseph and Kerykeion, or switch to PyEphem, another C core.

Read more

The age shows in production. The C library keeps global mutable state, so concurrent requests can leak settings into each other. It falls back silently when a data file is missing. House systems break near the poles, and every call crosses the C boundary in a slow loop.

We set out to build one engine that is safe under parallel load, gives the same answer in every language and can prove it is right.

The approach

A clean-room rewrite, not a translation

A line-by-line port would have carried the old bugs, and the old license, into the new code. We rebuilt the engine clean-room instead: no one on the project opened the Swiss Ephemeris source.

Read more

The math comes from published standards: NASA JPL DE440s ephemerides, IAU 2006/2000A precession and nutation, and peer-reviewed papers for houses, lunar points and fixed stars. Each model has a written passport with its equations, constants and citations.

The old engine served only as a black box. We ran the unmodified binary in a separate process to record reference values, then checked every result against it and against NASA JPL Horizons.

The architecture spec went through two audit rounds by Anthropic Claude and OpenAI Codex before it was approved, and senior engineers reviewed every change.

What we built

One Rust core, four ways to use it

lxephemeris-core is 100% safe Rust: unsafe code is forbidden at compile time, there is no global state and no locks. The same core ships as a Rust crate, a Python package, a Node.js and TypeScript package, and a CLI. All three SDKs agree to within 1e-12 degrees.

Read more
  1. 01

    Starts with zero files

    A built-in analytical model covers 3000 BCE to 3000 CE. With NASA JPL DE440s loaded, error stays under 0.003 arcseconds.

  2. 02

    Polar-safe houses

    All 23 house systems, with an explicit policy for latitudes where a system breaks, instead of a silent fallback.

  3. 03

    Analytical velocities

    Speeds come from one analytical pass, not three-point finite differences.

  4. 04

    Parallel batches

    Batch runs use every core through Rayon and release the Python GIL.

  5. 05

    Drop-in migration

    A SweAdapter lets pyswisseph code move over without rewriting call sites.

Proof

Checked against NASA, the IAU and the old engine

37,416 golden reference vectors from NASA JPL Horizons, IAU SOFA and USNO run across 145+ Rust tests, 18 Python and 12 Node.js test suites, with zero failures.

Read more

A 32-thread stress test runs more than 8,192 mixed chart calculations at once and measures 0.0 ULP of state bleed between them.

22 bugs inherited from Swiss Ephemeris, PyEphem and Kerykeion are fixed, each with a written proof and a guard in the test grid. One example: Kerykeion clamps latitude at 66 degrees, which puts the Ascendant 7.85 degrees off in Svalbard.

The outcome

Results

  1. 01

    12.8 µs per body

    One position with speed on a release build; a full natal chart takes about 150 to 240 µs.

  2. 02

    8.1 ms per batch

    1,000 positions computed in parallel.

  3. 03

    One engine instead of six libraries

    Planets, 68 minor bodies, fixed stars, eclipses and event solvers in one package.

  4. 04

    Open source

    Version 1.0 shipped in October 2026 to crates.io, PyPI and npm, and now powers AstroAPI and Astrolium.

Why it is called lxephemeris

Swiss Ephemeris carries the name of the country where it was made. Ours was made in Lisbon, so it carries the city's short name instead: LX.

The same path for your legacy code

The method carries over to any old core your product depends on: write the contract down, record reference results from the old system, rebuild in a memory-safe stack and prove parity before you switch.

If your product sits on aging C, C++ or an unmaintained library, we can scope that path for you.

Your story next

Tell us the outcome.
We will write your case study

Discovery in two weeks. ROI proposal after. Public case study optional, by your choice.