Overview of Astropy File I/O#

Astropy provides two main interfaces for reading and writing data:

  • High-level Unified I/O interface that is designed to be consistent and easy to use. This allows working with different types of data such as tables, images, and even cosmologies.

  • Low-level I/O sub-packages that are directly responsible for reading and writing data in specific formats such as FITS or VOTable.

In general we recommend starting with the high-level interface unless you have a specific need for the low-level interface.

Comparison of high-level and low-level interfaces#

High-level Unified I/O

Low-level I/O

Use read() and write() class methods of output data class, e.g., data = QTable.read("data.fits") returns a QTable.

Interfaces are specific to format, e.g., hdus = fits.open("data.fits") returns an HDUList.

Read and write entire file at once.

Support varies, e.g., FITS has memory-mapped read access.

Automatically determine file format in common cases.

Specify format explicitly.

Help documentation via class method, e.g., QTable.read.help("fits").

Help documentation varies, e.g., help(fits.open) or API docs.