Fast FITS queries in Python

Nicolas Devillard ndevilla at
Thu Feb 24 08:28:41 CST 2000

Yet another module to help making keyword queries in FITS headers, either
in C or Python.

'qfits' is an ANSI C module that offers very fast keyword queries in
FITS headers, through the use of the mmap() system call on Unix. 'qfits'
is written in portable ANSI C and should compile on any Unix system that
offers the mmap() call, i.e. any modern Unix :-).

'qfits' has been extracted from the eclipse library to build a stand-alone
module, to make it accessible from Python. A wrapper module called
'qfits_wrap.c' has been generated using SWIG, making a callable
shared object from the Python interpreter. If you have SWIG, you can
straightaway build a callable module for Perl or Tcl (see

A wrapper class called '' is then offered on top of the shared
object, to make the queries more Python-like. Here is an example of an
interactive session using Qfits:

>>> from Qfits import *
>>> q = Qfits('vltframe.fits')
>>> q.get('naxis')
>>> q.get('MJD-OBS')
>>> q.get('DET.DIT')
>>> q.get('dpr.catg', pretty=1)
>>> q.get('simple', 'naxis', 'naxis1', 'naxis2', 'bscale', 'bzero')
('T', '2', '1024', '1024', None, None)

'qfits' is a good solution if you only want to retrieve known keywords
from a FITS header in a Python script, and you want to do it fast, without
need for a complete FITS library with bells and whistles (the distribution
tar file for 'qfits' is 12 kbytes).

'qfits' can be downloaded from the (bottom of the) following page:


More information about the AstroPy mailing list