Skip to main content
`Ctrl`+`K`

# UnifiedInputRegistry

class astropy.io.registry.UnifiedInputRegistry

  Bases: `_UnifiedIORegistryBase`

  Read-only Unified Registry.

  Added 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)

    Get reader for `data_format`.

    Parameters:
      data_format `python:str`

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

      data_class class

        The class of the object that can be written.

    Returns:
      reader `python:callable()`

        The registered reader function for this format and class.

  read(cls, *args, format=None, cache=False, **kwargs)

    Read in data.

    Parameters:
      cls class
      *args

        The arguments passed to this method depend on the format.

      format `python:str` or `python:None`
      cache bool

        Whether to cache the results of reading in the data.

      **kwargs

        The arguments passed to this method depend on the format.

    Returns:
      `object` or `python:None`

        The output of the registered reader.

  register_reader(data_format, data_class, function, force=False, priority=0)

    Register a reader function.

    Parameters:
      data_format `python:str`

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

      data_class class

        The class of the object that the reader produces.

      function python:function

        The function to read in a data object.

      force bool, optional

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

      priority `python:int`, 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)

    Unregister a reader function.

    Parameters:
      data_format `python:str`

        The data format identifier.

      data_class class

        The class of the object that the reader produces.