Skip to content

ResultReaderRegistry

ResultReaderRegistry

ResultReaderRegistry()

Advanced dispatch table mapping format names and suffixes to readers.

The shared reader_registry already contains VTKHDF. Create a separate instance only when a tool needs its own format registrations; pass it as open_results(registry=...) to avoid modifying shared dispatch behavior.

Example
from femora.results.registry import ResultReaderRegistry
from femora.results.readers import VTKHDFResultReader
from femora.results import open_results

registry = ResultReaderRegistry()
registry.register("vtkhdf", VTKHDFResultReader, suffixes=".vtkhdf")
with open_results("results/response0.vtkhdf", registry=registry) as results:
    print(results.number_of_steps)

Attributes

registered_formats property

registered_formats: tuple[str, ...]

Return registered reader names.

registered_suffixes property

registered_suffixes: tuple[str, ...]

Return registered result suffixes.

Methods:

register

register(name: str, factory: ReaderFactory, *, suffixes: Union[str, Iterable[str]] = (), replace: bool = False) -> None

Register a factory without opening or converting a file.

Parameters:

Name Type Description Default
name str

Case-insensitive format name used by explicit format dispatch.

required
factory ReaderFactory

Callable accepting a path and any reader-specific options, returning a ResultReader.

required
suffixes Union[str, Iterable[str]]

Suffix string or iterable. A missing leading dot is added.

()
replace bool

Permit replacing conflicting names and suffix mappings.

False

Raises:

Type Description
ValueError

Name/suffix conflicts exist and replace is False.

create

create(path: Union[str, Path], *, format: Optional[str] = None, **options: Any) -> ResultReader

Instantiate a reader by explicit format name or file suffix.

Parameters:

Name Type Description Default
path Union[str, Path]

Recorder path; concrete readers check file existence/layout.

required
format Optional[str]

Registered name, or None to dispatch by the path suffix.

None
**options Any

Keyword options forwarded unchanged to the factory.

{}

Returns:

Name Type Description
ResultReader ResultReader

New instance. The caller owns its resources and must close it.

Raises:

Type Description
ResultFormatError

No matching reader factory is registered.