Number of keywords in header
[nkeys,morekeys] = fits.getHdrSpace(fptr)
[nkeys,morekeys] = fits.getHdrSpace(fptr) returns the number of existing keywords (not counting the END keyword) and the amount of space currently available for more keywords. It returns morekeys = -1 if the header has not yet been closed. Note that the CFITSIO library will dynamically add space if required when writing new keywords to a header so in practice there is no limit to the number of keywords that can be added to a header.
This function corresponds to the fits_get_hdrspace (ffghsp) function in the CFITSIO library C API.