UnifiedInputRegistry#

class astropy.io.registry.UnifiedInputRegistry[source]#

Bases: _UnifiedIORegistryBase

Read-only Unified Registry.

New in version 5.0.

Examples

First let’s start by creating a read-only registry.

>>> from astropy.io.registry import UnifiedInputRegistry
>>> read_reg = UnifiedInputRegistry()

There is nothing in this registry. Let’s make a reader for the Table class:

from astropy.table import Table

def my_table_reader(filename, some_option=1):
    # Read in the table by any means necessary
    return table  # should be an instance of Table

Such a function can then be registered with the I/O registry:

read_reg.register_reader('my-table-format', Table, my_table_reader)

Note that we CANNOT then read in a table with:

d = Table.read('my_table_file.mtf', format='my-table-format')

Why? because Table.read uses Astropy’s default global registry and this is a separate registry. Instead we can read by the read method on the registry:

d = read_reg.read(Table, 'my_table_file.mtf', format='my-table-format')

Methods Summary

get_reader(data_format, data_class)

Get reader for data_format.

read(cls, *args[, format, cache])

Read in data.

register_reader(data_format, data_class, ...)

Register a reader function.

unregister_reader(data_format, data_class)

Unregister a reader function.

Methods Documentation

get_reader(data_format, data_class)[source]#

Get reader for data_format.

Parameters:
data_formatstr

The data format identifier. This is the string that is used to specify the data type when reading/writing.

data_classclass

The class of the object that can be written.

Returns:
readercallable()

The registered reader function for this format and class.

read(cls, *args, format=None, cache=False, **kwargs)[source]#

Read in data.

Parameters:
clsclass
*args

The arguments passed to this method depend on the format.

formatstr or None
cachebool

Whether to cache the results of reading in the data.

**kwargs

The arguments passed to this method depend on the format.

Returns:
object or None

The output of the registered reader.

register_reader(data_format, data_class, function, force=False, priority=0)[source]#

Register a reader function.

Parameters:
data_formatstr

The data format identifier. This is the string that will be used to specify the data type when reading.

data_classclass

The class of the object that the reader produces.

functionfunction

The function to read in a data object.

forcebool, optional

Whether to override any existing function if already present. Default is False.

priorityint, optional

The priority of the reader, used to compare possible formats when trying to determine the best reader to use. Higher priorities are preferred over lower priorities, with the default priority being 0 (negative numbers are allowed though).

unregister_reader(data_format, data_class)[source]#

Unregister a reader function.

Parameters:
data_formatstr

The data format identifier.

data_classclass

The class of the object that the reader produces.