  We derive analytic, closed form, numerically stable solutions for the total
flux received from a spherical planet, moon or star during an occultation if
the specific intensity map of the body is expressed as a sum of spherical
harmonics. Our expressions are valid to arbitrary degree and may be computed
recursively for speed. The formalism we develop here applies to the computation
of stellar transit light curves, planetary secondary eclipse light curves, and
planet-planet/planet-moon occultation light curves, as well as thermal
(rotational) phase curves. In this paper we also introduce STARRY, an
open-source package written in C++ and wrapped in Python that computes these
light curves. The algorithm in STARRY is six orders of magnitude faster than
direct numerical integration and several orders of magnitude more precise.
STARRY also computes analytic derivatives of the light curves with respect to
all input parameters for use in gradient-based optimization and inference, such
as Hamiltonian Monte Carlo (HMC), allowing users to quickly and efficiently fit
observed light curves to infer properties of a celestial body's surface map.
