API reference
Public API grouped by module.
ledgercore.config
Shared ledger workspace config discovery and namespaced mapping selection. This module does not parse TOML or define tool-specific schemas.
LEDGER_PROJECT_MANIFESTCanonical manifest path segment:
".ledger/ledger.toml".LEDGER_PROJECT_LOCAL_CONFIGCanonical machine-local override path segment:
".ledger/ledger.local.toml".LEDGER_LEGACY_SHARED_CONFIGSCompatibility aliases for schema-version-1 shared config discovery.
LEDGER_CONFIG_FILENAMESCanonical hidden-first names:
(".ledger.toml", "ledger.toml").ledger_config_filenames(*legacy, include_visible=True)Append caller-provided legacy names after canonical names.
locate_ledger_config(start, *, legacy_filenames=(), ...)Locate a canonical config or legacy fallback.
LedgerProjectLocatorFrozen dataclass with
project_root,config_root,manifest_path,local_config_path,source, andis_legacy.locate_ledger_project(start, *, legacy_tool_filenames=(), default=False)Locate a canonical
.ledger/ledger.tomlproject manifest or a legacy fallback.select_project_config(document, *, table_name="project")Select the optional shared project mapping.
select_tool_config(document, tool_name, *, table_name="tools")Select a required tool mapping.
ledgercore.atomic
Atomic UTF-8 text writes and race-safe file creation.
Function |
Description |
|---|---|
|
Write text to a file atomically using a temp file and |
|
Create a new file atomically using exclusive creation flags. |
ledgercore.errors
Shared exception hierarchy with stable error codes.
Class |
Code |
Description |
|---|---|---|
|
|
Base exception for all ledgercore errors. |
|
|
Raised for missing or invalid shared config tables. |
|
|
Raised for invalid or unresolvable Ledger-family layouts. |
|
|
Base exception for storage-related errors. |
|
|
Raised when an atomic write operation fails. |
|
|
Raised when front matter parsing or writing fails. |
|
|
Raised when a JSON store operation fails. |
|
|
Raised when a YAML store operation fails. |
|
|
Raised when a path fails validation. |
|
|
Raised when an ID does not match the expected format. |
All exceptions accept an optional code keyword argument to override the default code.
ledgercore.frontmatter
YAML front matter reader/writer and source file iteration.
Symbol |
Description |
|---|---|
|
Literal type: |
|
Body preservation and newline normalization policy. |
|
Literal type: |
|
Literal type: |
|
Literal type: |
|
Boolean-compatible placeholder parsing mode. |
|
Frozen collection of all front matter rendering options. |
|
Parse front matter from in-memory text. |
|
Render ordered metadata and body. |
|
Merge metadata updates into in-memory text. |
|
Read a YAML front matter document, returning |
|
Write a YAML front matter document. |
|
Iterate source files matching given extensions in sorted order. |
|
Iterate markdown files in sorted order. |
|
Compatibility alias for |
|
Compatibility alias for |
ledgercore.ids
Prefixed numeric ID formatting, parsing, next-ID generation, and slug helpers.
Symbol |
Description |
|---|---|
|
Frozen dataclass: |
|
Configurable ID format with optional segment support. Methods: |
|
Simpler ID format for compatibility. Methods: |
|
Parse a prefixed numeric ID and return the number. |
|
Return the next prefixed ID given existing IDs. |
|
Lowercase, trim, collapse non-alphanumeric runs to dashes. |
ledgercore.io
UTF-8 text helpers, newline normalization, content hash, text merging.
Function |
Description |
|---|---|
|
Convert CRLF and CR to LF. |
|
Create parent directories as needed. |
|
Read UTF-8 text from a file. |
|
Write UTF-8 text to a file, creating parent directories. |
|
Return a stable SHA-256 hex digest of UTF-8 text. |
|
Collapse whitespace and truncate safely. |
|
Combine text blocks without excessive blank lines. |
ledgercore.jsonio
Validated JSON object/array loading and deterministic JSON writing.
Function |
Description |
|---|---|
|
Load and validate a JSON object. |
|
Load and validate a JSON array. |
|
Render configurable deterministic JSON text. |
|
Write JSON with configurable indentation and compact mode. |
|
Render compact sorted-key JSON for hashing. |
ledgercore.jsonl
Recoverable JSON Lines object loading and deterministic writing.
Symbol |
Description |
|---|---|
|
Frozen line issue: |
|
Valid |
|
Valid object plus its source line number. |
|
Line-aware valid rows plus recoverable issues. |
|
Object rows keyed by a selected string field plus issues. |
|
Literal type: |
|
Load object rows while preserving source line numbers. |
|
Load object rows into a keyed map with recoverable issues. |
|
Load object rows while reporting malformed lines. |
|
Write compact object rows atomically by default. |
ledgercore.paths
Safe relative POSIX path validation, config discovery, config-relative resolution.
Symbol |
Description |
|---|---|
|
Check whether path is relative to parent. |
|
Validate that a path is a safe relative POSIX path. |
|
Validate and resolve a relative path under a base directory. |
|
Resolve a path and reject paths outside the base. |
|
Return a safe POSIX base-relative path string. |
|
Resolve a safe relative path with optional existence checking. |
|
Walk from start upward, returning the first matching file, or None. |
|
Frozen dataclass: |
|
Find a config file and return a |
|
Resolve a relative path relative to the config file’s directory. |
ledgercore.manifest, ledgercore.overrides, and ledgercore.tomlio
Schema 3 is the normal project layout. StorageKind is one of project, external, user-data, or cache. LedgerProjectManifest, LedgerRegistration, and MountDefinition are frozen values. LedgerLocalOverrides contains only overrides for existing tools and mounts.
Symbol |
Description |
|---|---|
|
Strict schema-3 mapping parser. |
|
Strict schema-aware local overlay parser. |
|
Locate, read, overlay, and return a loaded project. |
|
Read schema 2 or schema 3 TOML. |
|
Atomically write schema 3 TOML. |
|
Read a schema-3 local overlay. |
|
Atomically write or delete an empty overlay. |
|
Return immutable local values without writing. |
ledgercore.storage_paths
Pure path helpers derive .ledger/<tool>/config.toml, project mounts, external mounts below <root>/<tool>/<uuid>/<mount>, user-data mounts, and checkout cache mounts below <cache>/<tool>/<uuid>/<checkout>/<mount>.
ledgercore.storage_binding
StorageBinding describes a .ledger-project.toml marker. initialize_storage_binding, initialize_config_binding, read_storage_binding, write_storage_binding, validate_storage_binding, and validate_ledger_layout_storage provide explicit marker lifecycle and read-only validation. storage_binding_to_mapping and storage_binding_from_mapping convert bindings to and from plain mappings for serialization in journals. initialize_external_store and validate_external_store manage .ledger-store.toml.
ledgercore.migration
plan_storage_migration resolves source and target layouts without writes.
execute_storage_migration performs a copy-only, fingerprint-verified atomic
activation transaction with StorageMigrationHooks and a durable schema-3
journal. mode="move" is rejected before mutation with a stable unsupported
strategy error. inspect_storage_migration strictly parses schema 3 and also
reads legacy schema-1/schema-2 journals. recover_storage_migration supports
auto, resume, rollback, and non-mutating dry_run; it proves ownership
before resuming, restoring, or cleaning paths and preserves source storage.
RecoveryAssessment reports phase, item states, owned paths, blockers, and the
recommended policy. Invalid or ambiguous journals raise
STORAGE_MIGRATION_JOURNAL_INVALID or
STORAGE_MIGRATION_MANUAL_INTERVENTION_REQUIRED. The
ledgercore.cli.migrate adapter exposes framework-neutral inspect/recover
responses using the ledgerwerk.cli.v1 JSON envelope.
ledgercore.layout compatibility facade
parse_ledger_project_manifest dispatches schema 2 and schema 3 mappings. The schema-2 layout dataclasses and provider vocabulary remain compatibility inputs and emit deprecation warnings. Schema-3 resolution is side-effect free and returns deterministic config and mount paths.
ledgercore.path_text
Human-authored path matching helpers. These functions do not authorize filesystem access.
Symbol |
Description |
|---|---|
|
Literal type: |
|
Decode literal |
|
Normalize Unicode, punctuation, slashes, whitespace, and case. |
ledgercore.hashing
Symbol |
Description |
|---|---|
|
Full, body, and canonical metadata SHA-256 values. |
|
Hash UTF-8 text. |
|
Hash bytes directly. |
|
Fingerprint components with front matter parser options. |
ledgercore.refs
Canonical cross-ledger resource references.
Symbol |
Description |
|---|---|
|
Literal type: |
|
Frozen dataclass with properties: |
|
Parse a canonical, file-safe, legacy, or local resource reference. |
|
Parse and require a ledger namespace. |
|
Parse a local kind-number ID without assigning a ledger. |
|
Return True if value is a valid resource ref. |
|
Lowercase and validate a short token. |
|
Lowercase, replace underscores with hyphens, and validate a resource kind. |
ledgercore.time
UTC timestamp generation with configurable precision and suffix style.
Symbol |
Description |
|---|---|
|
Supported |
|
Literal type: |
|
Normalize an aware datetime to UTC and render ISO-8601 text. |
ledgercore.yamlio
Validated YAML mapping loading and deterministic YAML writing.
Function |
Description |
|---|---|
|
Load and validate a YAML mapping. |
|
Write a YAML mapping with block style and a final newline. |