Skyfield: HomeTable of ContentsAPI Reference

API Reference — Opening Files

See Downloading and Using Data Files for an explanation of how Skyfield programs use an instance of the Loader class described below to download and open the data files they need in order to operate.

The loader class

class skyfield.iokit.Loader(directory, verbose=True, expire=False)

A tool for downloading and opening astronomical data files.

A default Loader that saves data files to the current working directory can be imported directly from the Skyfield API:

from skyfield.api import load

But users can also create a Loader of their own, if there is another directory they want data files saved to, or if they want to specify different options. The directory is created automatically if it does not yet exist:

from skyfield.api import Loader
load = Loader('~/skyfield-data')

The options are:

If set to False, then the loader will not print a progress bar to the screen each time it downloads a file. (If the standard output is not a TTY, then no progress bar is printed anyway.)
(This option is no longer supported.)

Once a Loader is created, it can be called like a function to open, or else to download and open, a file whose name it recognizes:

planets = load('de405.bsp')

Each loader also supports an attribute and a few methods.


The directory where this loader looks when trying to open a file, and where it downloads files that have not been downloaded yet.


Return the path to filename in this loader’s directory.


Return the URL Skyfield will try downloading for a given filename.

tle_file(url, reload=False, filename=None, ts=None, skip_names=False)

Load and parse a TLE file, returning a list of Earth satellites.

Given a URL or local path to an ASCII text file, this loads a series of TLE “Two-Line Element” sets and returns a list of EarthSatellite objects for them. See Earth Satellites.

See the open() method for the meaning of the reload and filename parameters.

See the parse_tle_file() function for the meaning of the ts and skip_names parameters.

open(url, mode='rb', reload=False, filename=None, backup=False)

Open a file, downloading it first if it does not yet exist.

Unlike when you call a loader directly like my_loader(), this method does not attempt to parse or interpret the file; it simply returns an open file object.

The url can be either an external URL, or else the path to a file on the current filesystem. A relative path will be assumed to be relative to the base directory of this loader object.

If a URL was provided and the reload parameter is true, then any existing file will be removed before the download starts.

The filename parameter lets you specify an alternative local filename instead of having the filename extracted from the final component of the URL.

timescale(delta_t=None, builtin=True)

Open or download three time scale files, returning a Timescale.

delta_t — Lets you override the standard ∆T tables by providing your own ∆T offset in seconds. For details, see Setting a Custom Value For ∆T.

builtin — Set this to False to download new copies of the three official files that supply recent ∆T measurements and the current schedule of UTC leap seconds. By default, Skyfield uses copies of the three files that it ships with and installs alongside its code. For details, see Downloading new timescale files.

Standalone functions


Open a file on your local drive, using its extension to guess its type.

This routine only works on .bsp ephemeris files right now, but will gain support for additional file types in the future.

from skyfield.api import load_file
planets = load_file('~/Downloads/de421.bsp')
skyfield.iokit.parse_tle_file(lines, ts=None, skip_names=False)

Parse lines of TLE satellite data, yielding a sequence of satellites.

Given a sequence lines of byte strings (which can be an open binary file, which acts like a sequence of lines in Python), this routine yields an EarthSatellite for each pair of adjacent lines that start with "1 " and "2 " and have 69 or more characters each. If the line preceding a TLE is not part of another TLE, it is used as the satellite’s .name.

If you pass a ts timescale, Skyfield will use it to build the .epoch date attribute on each satellite; otherwise a timescale derived from Skyfield’s built-in leap second files will be used.

If for a particular file you see random lines of text being interpreted as satellite names, set skip_names to True and Skyfield will not try to store satellite names.

See Earth Satellites for details. An exception is raised if the attempt to parse a pair of candidate lines as TLE lines fails.