1import abc
2from typing import IO, AnyStr
3
4
[docs]
5class BaseExporter(abc.ABC):
6 """
7 Abstract base class for data exporters in the colander data converter.
8
9 This class defines the interface that all exporter implementations must follow.
10 Subclasses are responsible for implementing the actual export logic for their
11 specific format or destination.
12 """
13
[docs]
14 @abc.abstractmethod
15 def export(self, output: IO[AnyStr], **kwargs) -> None:
16 """
17 Export data to the specified output stream.
18
19 This abstract method must be implemented by all subclasses to define
20 how data should be exported to the given output stream. The method
21 signature allows for flexible output destinations (files, streams, etc.)
22 and customizable export behavior through keyword arguments.
23
24 Args:
25 output (IO[AnyStr]): The output stream where data will be written.
26 Can be a file object, :py:class:`~io.StringIO`, :py:class:`~io.BytesIO`, or any
27 object that implements the IO interface for either
28 text or binary data.
29 **kwargs: Variable keyword arguments that allow subclasses to accept
30 format-specific options. Common examples might include:
31
32 - encoding: Character encoding for text formats
33 - indent: Indentation level for structured formats like JSON
34 - delimiter: Field separator for delimited formats like CSV
35 - compression: Compression settings for binary formats
36
37 Raises:
38 NotImplementedError: Always raised by this abstract method to enforce implementation in subclasses.
39 """
40 raise NotImplementedError()