ExportMixin¶
Provides export functionality for the file manager. The ExportMixin contains operations for exporting data to different formats.
Methods¶
to_current_format¶
Export data to the current file's format using the manager's strategy.
Returns:
- str: String content in the current format
Example:
to_json¶
Export data to JSON format.
Parameters:
- pretty (bool): If True, formats with indentation
Returns:
- str: JSON string
Example:
to_yaml¶
Export data to YAML format.
Returns:
- str: YAML string
Example:
to_toml¶
Export data to TOML format.
Returns:
- str: TOML string
Example:
export_section¶
def export_section(
self,
section_path: str,
format: str = "json",
output_path: Optional[Union[str, Path]] = None,
) -> Union[str, Path]
Export a specific section to a file or return as string.
Parameters:
- section_path (str): Dot-separated path to the section
- format (str): Output format ("json", "yaml", "toml")
- output_path (Optional[Union[str, Path]]): Optional output file path. If None, returns string
Returns:
- Union[str, Path]: String content or output file path
Example:
# Returns JSON string
json_str = fm.export_section("database", "json")
# Saves to file
fm.export_section("api", "yaml", "api_config.yaml")
export_to_file¶
Export the entire data to a file in the specified format.
Parameters:
- output_path (Union[str, Path]): Output file path
- format (Optional[str]): Output format. If None, inferred from file extension
Returns:
- Path: Output file path
Example: