PyEphem high precision astronomy in Python

PyEphem brings functionality for Python that the NAIF SPICE package has for C, FORTRAN, IDL, and MATLAB. Specifically, performing high-precision astronomical calculations. AstroPy has more comprehensive astronomical functions.

PyEphem local sunrise & sunset

    import ephem
    import datetime

    # lat/lon must be strings'42.3462'
    Boston.lon='-71.0978' =

    sun = ephem.Sun()

    print("Next sunrise in Boston will be: ",ephem.localtime(Boston.next_rising(sun)))
    print("Next sunset in Boston will be: ",ephem.localtime(Boston.next_setting(sun)))


  • elevation is NOT considered by PyEphem, modeled after XEphem for sunrise / sunset, and there aren’t any plans to do so. Thus, if your sunrise/sunset observer is above Earth, you must add additional calculations.