read_brand_yml
=False) read_brand_yml(path, as_data
Read a Brand YAML file.
Reads a Brand YAML file or finds and reads a project-specific _brand.yml
file and returns a validated ~brand_yml.Brand
instance.
To find a project-specific _brand.yaml
file, pass the project directory or __file__
(the path of the current Python script). brand_yml.read_brand_yml
will look in that directory or any parent directory for a _brand.yml
, brand/_brand.yml
or _brand/_brand.yml
file. Note that it starts the search in the directory passed in and moves upward to find the Brand YAML file; it does not search into subdirectories of the current directory.
Parameters
path: str | Path
-
The path to the Brand YAML file or a directory where
_brand.yml
is expected to be found. Typically, you can pass__file__
from the calling script to find_brand.yml
in the current directory or any of its parent directories. as_data: bool = False
-
When
True
, returns the raw brand data as a dictionary parsed from the YAML file. WhenFalse
, returns a validated :class:Brand
object.
Returns
Name | Type | Description |
---|---|---|
Brand | dict | A validated :class:brand_yml.Brand object with all fields populated according to the Brand YAML file (as_data=False , default) or the raw brand data as a dictionary (as_data=True ). |
Raises
Name | Type | Description |
---|---|---|
FileNotFoundError | Raises a FileNotFoundError if no brand configuration file is found within the given path. |
|
ValueError | ValueError or other validation errors are raised from pydantic if the Brand YAML file is invalid. |
Examples
from brand_yml import read_brand_yml
= read_brand_yml(__file__)
brand = read_brand_yml("path/to/_brand.yml") brand