Decorate a function to act as the sniffer for this format.

State: Stable as of 0.4.0.

The function should take one argument which will be an implementation of either io.TextIOBase or io.BufferedReader depending on if the format is text or binary, respectively.

The sniffer will always receive a filehandle which is pointing to the beginning of the file. It must return a tuple of bool and a dict of suggested keyword arguments (if any) to pass to the reader.


Keyword arguments are not permitted in sniffers. Sniffers may not raise exceptions; if an exception is thrown by a sniffer, the user will be asked to report it on our issue tracker.


override : bool, optional

If True, the existing sniffer will be overriden.



When override is False and a sniffer is already registered for this format.


>>> from import Format
>>> # If developing a new format for skbio, use the create_format()
>>> # factory instead of this constructor.
>>> myformat = Format('myformat')
>>> @myformat.sniffer()
... def myformat_sniffer(fh):
...     check = == "myformat"
...     if check:
...         version = int(
...         return True, {'version': version}
...     return False, {}
>>> myformat_sniffer(["myformat2\n", "some content\n"])
(True, {'version': 2})
>>> myformat_sniffer(["something else\n"])
(False, {})