API
Public module
Public API for Sygaldry.
- class sygaldry.Artificery(*paths: str | Path, config: dict[str, Any] | None = None, source: str | None = None, overrides: dict[str, Any] | None = None, uses: dict[str, str] | None = None, cache: Instances | None = None, transient: bool = False)
Component factory that loads, merges, and resolves config into objects.
Artificery module
- class sygaldry.artificery.ConstructorSpec(target: str, args: tuple[Any, ...], kwargs: dict[str, Any], instance: str | None)
Constructor specification for a component.
- class sygaldry.artificery.Node(name: str, children: tuple[str, ...], bindings: dict[str, Any])
Intermediate node representation for optional IR usage.
- sygaldry.artificery.load_config_file(path: str | Path) dict[str, Any]
Load a config file without resolving components.
- Parameters:
path (str | pathlib.Path) – Path to a YAML or TOML config file.
- Returns:
Parsed and interpolated mapping.
- Return type:
- class sygaldry.artificery.ArtificeryLoader(path: str | Path)
Lightweight loader wrapper for config files.
- sygaldry.artificery.resolve_config(config: dict[str, Any], *, file_path: str | None = None, cache: Instances | None = None, transient: bool = False) dict[str, Any]
Resolve a config mapping into an instantiated object graph.
- class sygaldry.artificery.Artificery(*paths: str | Path, config: dict[str, Any] | None = None, source: str | None = None, overrides: dict[str, Any] | None = None, uses: dict[str, str] | None = None, cache: Instances | None = None, transient: bool = False)
Component factory that loads, merges, and resolves config into objects.
Loader module
Config loading with includes, deep merge, and interpolation.
Cache module
Instance cache with hash conflict detection.
- class sygaldry.cache.CacheEntry(value: Any, spec_hash: str)
Cached instance entry with hash for conflict detection.
- class sygaldry.cache.Instances
Per-factory cache keyed by (type_path, instance tag or spec hash).
- get(type_path: str, instance: str | None, *, expected_hash: str | None = None, file_path: str | None = None, config_path: str | None = None) Any
Return a cached instance if present.
- Parameters:
- Returns:
Cached instance if found, or
_NOT_FOUNDsentinel.- Return type:
- Raises:
ConfigConflictError – If the cached hash conflicts.
- set(type_path: str, instance: str | None, value: Any, *, spec_hash: str, file_path: str | None = None, config_path: str | None = None) Any
Insert or validate a cache entry.
- Parameters:
type_path (str) – Dotted type path used as cache key.
instance (str | None) – Optional instance tag.
value (object) – Resolved object instance.
spec_hash (str) – Hash for the constructor spec.
file_path (str | None) – Source config file path, if known.
config_path (str | None) – Dotted config path for context.
- Returns:
The inserted instance.
- Return type:
- Raises:
ConfigConflictError – If an existing entry conflicts.
- get_or_create(type_path: str, instance: str | None, args: tuple[Any, ...], kwargs: dict[str, Any], factory: Callable[[], Any], *, transient: bool = False, file_path: str | None = None, config_path: str | None = None) Any
Get or create a cached instance.
- Parameters:
type_path (str) – Dotted type path used as cache key.
instance (str | None) – Optional instance tag.
args (tuple[Any, ...]) – Resolved positional args.
factory (collections.abc.Callable[[], Any]) – Callable that constructs the instance.
transient (bool) – If True, bypass caching.
file_path (str | None) – Source config file path, if known.
config_path (str | None) – Dotted config path for context.
- Returns:
Cached or newly created instance.
- Return type:
Checker module
- class sygaldry.checker.CheckError(config_path: str, message: str, severity: str = 'error')
A type error found in a config file.
- sygaldry.checker.check(path: str | Path | None = None, *, type_checker: str | None = None, config: dict[str, Any] | None = None) list[CheckError]
Type check a sygaldry config file.
Either path or config must be provided. When config is given the config dict is used directly (useful from the CLI after loading and applying overrides). When path is given, the file is loaded via
load_config().- Parameters:
path – Path to a YAML/TOML config file.
type_checker – Which checker to run (
ty,basedpyright,pyright, ormypy). Auto-detected when None.config – Pre-loaded config dict.
- Returns:
List of type errors found.
Code generation module
- class sygaldry.codegen.SourceMapping(line: int, config_path: str)
Map a generated line number to a config path.
- class sygaldry.codegen.ComponentEntry(config_path: str, var_name: str, import_path: str, args: list[~typing.Any] = <factory>, kwargs: dict[str, ~typing.Any] = <factory>, is_func: bool = False)
A typed component extracted from the config.
- class sygaldry.codegen.PlainEntry(config_path: str, var_name: str, value: Any)
A plain (non-typed) config value.
- class sygaldry.codegen.RefExpression(target: str)
A reference expression to be emitted as a variable or attribute access.
- class sygaldry.codegen.AnalysisResult(components: list[~sygaldry.codegen.ComponentEntry] = <factory>, plains: list[~sygaldry.codegen.PlainEntry] = <factory>, topological_order: list[str] = <factory>, imports: dict[str, tuple[str, str]] = <factory>)
Result of analyzing a config dict.
- class sygaldry.codegen.ConfigAnalyzer(config: dict[str, Any])
Walk a loaded config dict and extract typed component specs.
- analyze() AnalysisResult
Analyze the config and return structured results.
- class sygaldry.codegen.CodeGenerator(analysis: AnalysisResult)
Generate Python source code from analysis results.
- generate() tuple[str, list[SourceMapping]]
Generate the full source code.
CLI module
Types module
Shared constants and import helpers.
- sygaldry.types.import_dotted_path(dotted_path: str, *, file_path: str | None = None, config_path: str | None = None) object
Import a dotted path and return the target object. Resolves the longest importable module prefix and then walks remaining attributes. Raising and ImportResolutionError with context if it fails.
- Parameters:
- Returns:
Imported module attribute or callable.
- Return type:
- Raises:
ImportResolutionError – If the module or attribute cannot be imported.
Errors
- exception sygaldry.errors.SygaldryError(message: str, file_path: str | None = None, config_path: str | None = None)
Base error for all Sygaldry failures.
- exception sygaldry.errors.LoadError(message: str, file_path: str | None = None, config_path: str | None = None)
Errors during file loading or parsing.
- exception sygaldry.errors.ParseError(message: str, file_path: str | None = None, config_path: str | None = None)
Parsing failures for YAML or TOML.
- exception sygaldry.errors.IncludeError(message: str, file_path: str | None = None, config_path: str | None = None)
Errors during include resolution or deep merge.
- exception sygaldry.errors.CircularIncludeError(message: str, file_path: str | None = None, config_path: str | None = None)
Circular include detected.
- exception sygaldry.errors.ValidationError(message: str, file_path: str | None = None, config_path: str | None = None)
Schema or config validation failures.
- exception sygaldry.errors.ConfigReferenceError(message: str, file_path: str | None = None, config_path: str | None = None)
Missing or invalid _ref targets.
- exception sygaldry.errors.CircularReferenceError(message: str, file_path: str | None = None, config_path: str | None = None)
Circular _ref detected.
- exception sygaldry.errors.InterpolationError(message: str, file_path: str | None = None, config_path: str | None = None)
Interpolation failures.
- exception sygaldry.errors.CircularInterpolationError(message: str, file_path: str | None = None, config_path: str | None = None)
Circular interpolation detected.
- exception sygaldry.errors.ImportResolutionError(message: str, file_path: str | None = None, config_path: str | None = None)
Import or dotted path resolution failures.
- exception sygaldry.errors.ResolutionError(message: str, file_path: str | None = None, config_path: str | None = None)
Errors during recursive resolution.
- exception sygaldry.errors.ConstructorError(message: str, file_path: str | None = None, config_path: str | None = None)
Constructor invocation failures.