Read and write TOML config files using Pydantic BaseClasses.
Warning
This module is an internal implementation detail which may change
between releases without notice (see
Versioning and Compatibility).
dump
dump(
model: BaseModel,
fp: BinaryIO,
*,
exclude_none: bool = True,
) -> None
Serialize data class as a TOML formatted stream to file-like object.
Parameters:
-
model
(BaseModel)
–
Config model instance to write.
-
fp
(BinaryIO)
–
File-like bytes stream to write to.
-
exclude_none
(bool, default:
True
)
–
Skip writing none attributes.
Source code in proxystore/utils/config.py
| def dump(
model: BaseModel,
fp: BinaryIO,
*,
exclude_none: bool = True,
) -> None:
"""Serialize data class as a TOML formatted stream to file-like object.
Args:
model: Config model instance to write.
fp: File-like bytes stream to write to.
exclude_none: Skip writing none attributes.
"""
data_dict = model.model_dump(exclude_none=exclude_none)
tomli_w.dump(data_dict, fp)
|
dumps
dumps(
model: BaseModel, *, exclude_none: bool = True
) -> str
Serialize data class to a TOML formatted string.
Parameters:
-
model
(BaseModel)
–
Config model instance to write.
-
exclude_none
(bool, default:
True
)
–
Skip writing none attributes.
Returns:
-
str
–
TOML string of data class.
Source code in proxystore/utils/config.py
| def dumps(model: BaseModel, *, exclude_none: bool = True) -> str:
"""Serialize data class to a TOML formatted string.
Args:
model: Config model instance to write.
exclude_none: Skip writing none attributes.
Returns:
TOML string of data class.
"""
data_dict = model.model_dump(exclude_none=exclude_none)
return tomli_w.dumps(data_dict)
|
load
Parse TOML from a binary file to a data class.
Parameters:
-
model
(type[BaseModelT])
–
Config model type to parse TOML using.
-
fp
(BinaryIO)
–
File-like bytes stream to read in.
Returns:
-
BaseModelT
–
Model initialized from TOML file.
Source code in proxystore/utils/config.py
| def load(model: type[BaseModelT], fp: BinaryIO) -> BaseModelT:
"""Parse TOML from a binary file to a data class.
Args:
model: Config model type to parse TOML using.
fp: File-like bytes stream to read in.
Returns:
Model initialized from TOML file.
"""
return loads(model, fp.read().decode())
|
loads
loads(model: type[BaseModelT], data: str) -> BaseModelT
Parse TOML string to data class.
Parameters:
-
model
(type[BaseModelT])
–
Config model type to parse TOML using.
-
data
(str)
–
Returns:
-
BaseModelT
–
Model initialized from TOML file.
Source code in proxystore/utils/config.py
| def loads(model: type[BaseModelT], data: str) -> BaseModelT:
"""Parse TOML string to data class.
Args:
model: Config model type to parse TOML using.
data: TOML string to parse.
Returns:
Model initialized from TOML file.
"""
data_dict = tomllib.loads(data)
return model.model_validate(data_dict, strict=True)
|