yera.config.storage.write
Persist edits to yera.toml and pyproject.toml while keeping human-oriented layout.
Why tomlkit (and not tomli + tomli-w, or tomllib + a writer)? Those paths parse
TOML into a plain dict and write it back with a fresh serialiser. The whole file is
re-emitted, so comments, spacing, and section order outside our edits are lost. That is
especially bad for pyproject.toml, which people hand-edit and share with Ruff, Hatch,
and so on.
tomlkit loads the file into a document — a structured representation that still carries the original layout. We only assign into the tables Yera cares about; the rest of the file is left as-is on save.
Public functions are the supported mutations. Private helpers load or save that document, ensure nested tables exist, and run a small mutator that returns whether anything changed worth writing to disk (so we skip useless rewrites where that matters).
Symbols
delete_yera_toml
delete_yera_toml() → NoneRemove the resolved yera.toml path; do nothing if it is already absent.
remove_all_hubs
remove_all_hubs() → NoneClear every key under [hubs] (named hubs and default).
Does not write when there is no hubs table, when hubs is not a TOML table,
or when [hubs] is already empty—nothing to change on disk.
remove_all_models
remove_all_models(
model_type: str | None = None,
) → NoneRemove model entries from [models].
When model_type is given, clears only that type's array. When omitted, clears all type arrays entirely.
Does not write when there is no models table or the target is
already empty.
Parameters
If set, remove only models of this type. If None,
remove all models across all types.
remove_all_profiles
remove_all_profiles() → NoneClear every profile under [profiles.profiles] and unset default.
Does not write when there is no profiles table or it is already empty.
remove_all_providers
remove_all_providers() → NoneClear every key under [providers].
Does not write when there is no providers table or it is already empty.
remove_from_pyproject_yera
remove_from_pyproject_yera(
key: str,
) → NoneRemove [tool.yera].<key> when it exists.
Does not write the file when [tool] or [tool.yera] is absent, or when
key is not present under [tool.yera], so the manifest is left unchanged.
Raises
No writable pyproject.toml for this project.
remove_from_pyproject_yera_overrides
remove_from_pyproject_yera_overrides(
key: str,
) → NoneRemove [tool.yera.overrides].<key> when it exists.
Does not write when [tool], [tool.yera], or [tool.yera.overrides] is
absent, or when key is not present. When the overrides table becomes empty after
removal, drops the empty overrides table from [tool.yera].
Raises
No writable pyproject.toml for this project.
remove_hub_entry
remove_hub_entry(
name: str,
) → NoneDrop [hubs.<name>]; clear default too when it pointed at name.
Does not write the file when there is no [hubs] table (nothing to change).
remove_model_from_universe
remove_model_from_universe(
model_type: str,
model_id: str,
connection: str,
) → NoneRemove one model entry from [[models.<type>]] matching model_id and connection.
Does not write when no matching entry exists.
Parameters
Model type key, e.g. "llm".
Yera-internal dot-delimited model id.
Connection name the model was discovered under.
remove_models_for_connection
remove_models_for_connection(
provider_type: str,
connection_name: str,
) → NoneRemove all model entries across all types for a specific provider connection.
Iterates every model type array in [models] and drops entries where
both provider matches provider_type and connection matches
connection_name. Does not write when nothing matches.
Parameters
Provider type key, e.g. "aws".
Connection name, e.g. "work".
remove_profile
remove_profile(
profile_name: str,
) → NoneDrop [profiles.profiles.<name>].
Clears default too when it pointed at profile_name. Does not write
when the profile is absent.
Parameters
Yera profile name to remove.
remove_provider
remove_provider(
provider_type: str,
) → NoneDrop [providers.<type>] and all its connections.
Does not write when the provider is absent.
Parameters
Provider type key to remove, e.g. "aws".
remove_provider_connection
remove_provider_connection(
provider_type: str,
connection_name: str,
) → NoneDrop [providers.<type>.connections.<name>].
Does not write when the provider or connection is absent.
Parameters
Provider type key, e.g. "aws".
Connection name to remove, e.g. "work".
write_hub_default
write_hub_default(
name: str,
) → NoneSet [hubs] default to name without removing existing [hubs.*] URL tables.
write_hub_entry
write_hub_entry(
name: str,
url: str,
) → NoneDefine or replace [hubs.<name>] with the given url; other hub entries stay put.
write_model_to_universe
write_model_to_universe(
model: BaseModelConfig,
) → NoneAppend or replace a model entry in [[models.<type>]] in yera.toml.
Derives model type from model.type. If an entry with the same id
and connection already exists it is replaced in-place; otherwise the
entry is appended.
Parameters
A validated model config object to write.
write_models_to_universe
write_models_to_universe(
models: list[BaseModelConfig],
) → NoneWrite multiple model entries to yera.toml in a single file operation.
Parameters
List of validated model config objects to write.
write_profile
write_profile(
profile: Profile,
) → NoneWrite or replace [profiles.profiles.<name>] in yera.toml.
Serialises the full profile — name, optional description, non-empty provider
bindings, and non-empty model defaults — into a tomlkit table and assigns it
under [profiles.profiles]. Creates the [profiles] and
[profiles.profiles] tables if absent. Empty provider and model-default
fields are omitted from the written entry.
Parameters
Validated profile object to persist. The profile's name
field is used as the table key.
write_profile_default
write_profile_default(
profile_name: str,
) → NoneSet [profiles] default to profile_name.
Parameters
Yera profile name to set as default.
write_provider_connection
write_provider_connection(
provider_type: str,
connection_name: str,
connection_data: dict[str, TomlValue],
) → NoneDefine or replace [providers.<type>.connections.<name>] with connection_data.
Creates the [providers], [providers.<type>], and
[providers.<type>.connections] tables if absent.
Parameters
Provider type key, e.g. "aws".
Connection name, e.g. "work".
Connection fields to write, e.g.
{"region": "eu-west-1", "credentials": ["access_key_id"]}.
write_pyproject_yera_cred_group
write_pyproject_yera_cred_group(
name: str,
) → NoneSet [tool.yera.overrides] cred-group to name; other pyproject.toml content stays intact.
Creates [tool], [tool.yera], and [tool.yera.overrides] when missing.
name is stripped of leading and trailing whitespace before writing.
Raises
No writable pyproject.toml for this project.
tool, tool.yera, or tool.yera.overrides exists but is not a table.
name is empty or whitespace-only after stripping.
write_setting_to_yera_toml
write_setting_to_yera_toml(
key: str,
value: TomlValue,
) → NoneSet [settings].<key> to value; leave every other section of yera.toml as-is.
write_to_pyproject_yera
write_to_pyproject_yera(
key: str,
value: TomlValue,
) → NoneSet [tool.yera].<key> to value; all other pyproject.toml content stays intact.
Creates [tool] / [tool.yera] when missing.
Raises
No writable pyproject.toml for this project.
tool or tool.yera exists but is not a table (malformed file).
write_to_pyproject_yera_profile
write_to_pyproject_yera_profile(
profile_name: str,
) → NoneSet [tool.yera.profiles] default to profile_name in pyproject.toml.
Creates [tool], [tool.yera], and [tool.yera.profiles] if absent.
Parameters
Yera profile name to set as the project-level active profile.
Raises
No writable pyproject.toml for this project.