Yaml io
YAML load/dump helpers with safe loader/dumper defaults.
The module prefers yaml.CSafeLoader/yaml.CSafeDumper when available and
falls back to pure-Python safe implementations otherwise.
safe_dump_binary_io(data: Any, file_io: BinaryIO, *, allow_unicode: bool = True, encoding: str = 'utf-8', **kwargs: Any) -> None
¶
Serialize a Python object to an existing binary file-like object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Any
|
The Python object to dump to YAML. |
required |
file_io
|
BinaryIO
|
Writable binary file-like object. |
required |
allow_unicode
|
bool
|
Whether to allow non-ASCII characters in the output. |
True
|
encoding
|
str
|
The encoding to use for the byte string. |
'utf-8'
|
**kwargs
|
Any
|
Additional keyword arguments forwarded to |
{}
|
Raises:
| Type | Description |
|---|---|
yaml.YAMLError
|
If YAML serialization fails. |
Notes
Stream lifecycle is managed by the caller; this function does not close the file object.
Source code in src/pfmsoft/eve_snippets/yaml/yaml_io.py
safe_dump_bytes(data: Any, *, allow_unicode: bool = True, encoding: str = 'utf-8', **kwargs: Any) -> bytes
¶
Serialize a Python object to a YAML byte string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Any
|
The Python object to dump to YAML. |
required |
allow_unicode
|
bool
|
Whether to allow non-ASCII characters in the output. |
True
|
encoding
|
str
|
The encoding to use for the byte string. |
'utf-8'
|
**kwargs
|
Any
|
Additional keyword arguments forwarded to |
{}
|
Returns:
| Type | Description |
|---|---|
bytes
|
YAML byte string representation of |
Raises:
| Type | Description |
|---|---|
yaml.YAMLError
|
If YAML serialization fails. |
Source code in src/pfmsoft/eve_snippets/yaml/yaml_io.py
safe_dump_bytes_path(data: Any, file_path: Path, *, overwrite: bool = False, encoding: str = 'utf-8', allow_unicode: bool = True, **kwargs: Any) -> None
¶
Serialize a Python object to a YAML file in binary mode.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Any
|
The Python object to dump to YAML. |
required |
file_path
|
Path
|
Destination YAML file path. |
required |
overwrite
|
bool
|
Whether to overwrite the file if it already exists. |
False
|
encoding
|
str
|
File encoding to use. |
'utf-8'
|
allow_unicode
|
bool
|
Whether to allow non-ASCII characters in the output. |
True
|
**kwargs
|
Any
|
Additional keyword arguments forwarded to |
{}
|
Raises:
| Type | Description |
|---|---|
yaml.YAMLError
|
If YAML serialization fails. |
FileExistsError
|
If the target file exists and |
Source code in src/pfmsoft/eve_snippets/yaml/yaml_io.py
safe_dump_str(data: Any, *, allow_unicode: bool = True, **kwargs: Any) -> str
¶
Serialize a Python object to a YAML string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Any
|
The Python object to dump to YAML. |
required |
allow_unicode
|
bool
|
Whether to allow non-ASCII characters in the output. |
True
|
**kwargs
|
Any
|
Additional keyword arguments forwarded to |
{}
|
Returns:
| Type | Description |
|---|---|
str
|
YAML text representation of |
Raises:
| Type | Description |
|---|---|
yaml.YAMLError
|
If YAML serialization fails. |
Source code in src/pfmsoft/eve_snippets/yaml/yaml_io.py
safe_dump_str_path(data: Any, file_path: Path, *, overwrite: bool = False, encoding: str = 'utf-8', allow_unicode: bool = True, **kwargs: Any) -> None
¶
Serialize a Python object to a YAML file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Any
|
The Python object to dump to YAML. |
required |
file_path
|
Path
|
Destination YAML file path. |
required |
overwrite
|
bool
|
Whether to overwrite the file if it already exists. |
False
|
encoding
|
str
|
File encoding to use. |
'utf-8'
|
allow_unicode
|
bool
|
Whether to allow non-ASCII characters in the output. |
True
|
**kwargs
|
Any
|
Additional keyword arguments forwarded to |
{}
|
Raises:
| Type | Description |
|---|---|
yaml.YAMLError
|
If YAML serialization fails. |
FileExistsError
|
If the target file exists and |
Source code in src/pfmsoft/eve_snippets/yaml/yaml_io.py
safe_dump_text_io(data: Any, file_io: TextIO, *, allow_unicode: bool = True, **kwargs: Any) -> None
¶
Serialize a Python object to an existing file-like object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Any
|
The Python object to dump to YAML. |
required |
file_io
|
TextIO
|
Writable file-like object. |
required |
allow_unicode
|
bool
|
Whether to allow non-ASCII characters in the output. |
True
|
**kwargs
|
Any
|
Additional keyword arguments forwarded to |
{}
|
Raises:
| Type | Description |
|---|---|
yaml.YAMLError
|
If YAML serialization fails. |
Notes
Stream lifecycle is managed by the caller; this function does not close the file object.
Source code in src/pfmsoft/eve_snippets/yaml/yaml_io.py
safe_load(text: str | bytes) -> Any
¶
Parse YAML content from a string or bytes object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str | bytes
|
YAML text or bytes payload. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
Python object parsed from YAML content. |
Raises:
| Type | Description |
|---|---|
yaml.YAMLError
|
If YAML parsing fails. |
Source code in src/pfmsoft/eve_snippets/yaml/yaml_io.py
safe_load_IO(file_io: IO[str] | IO[bytes]) -> Any
¶
Parse YAML content from an existing file-like object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_io
|
IO[str] | IO[bytes]
|
Readable file-like object containing YAML text. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
Python object parsed from YAML content. |
Raises:
| Type | Description |
|---|---|
yaml.YAMLError
|
If YAML parsing fails. |
Notes
Stream lifecycle is managed by the caller; this function does not close the file object.
Source code in src/pfmsoft/eve_snippets/yaml/yaml_io.py
safe_load_path(file_path: Path) -> Any
¶
Parse a YAML file into Python objects.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
Path
|
Source YAML file path. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
Python object parsed from YAML content. |
Raises:
| Type | Description |
|---|---|
yaml.YAMLError
|
If YAML parsing fails. |
FileNotFoundError
|
If |