Python API Reference¶
The okf_schema.api module provides a clean, typed Python interface for all okf-schema operations.
Bundle operations¶
- okf_schema.api.validate_bundle(bundle_path, schema_db=None)¶
Validate an OKF bundle.
- Parameters:
bundle_path (
str|Path) – Path to the OKF bundle directory.schema_db (
str|Path|None) – Optional directory containing JSON/YAML schema files. If not provided, the_schemasubdirectory inside the bundle is used automatically when it exists.
- Return type:
- Returns:
A
Reportwith all errors and warnings.- Raises:
FileNotFoundError – When bundle_path does not exist.
NotADirectoryError – When bundle_path is not a directory.
- okf_schema.api.format_bundle(bundle_path, check=False, diff=False)¶
Format frontmatter in all concept files of an OKF bundle.
- Parameters:
bundle_path (
str|Path) – Path to the OKF bundle directory.check (
bool) – IfTrue, do not modify files; only report changes needed.diff (
bool) – IfTrue, include unified diff in results without modifying.
- Return type:
list[FormattedResult]- Returns:
List of
FormattedResult, one per markdown file.- Raises:
FileNotFoundError – When bundle_path does not exist.
NotADirectoryError – When bundle_path is not a directory.
- okf_schema.api.lint_bundle(bundle_path, check=False, diff=False, links=False)¶
Lint frontmatter in all concept files of an OKF bundle.
Converts block-style (multi-line) lists to inline notation so that frontmatter stays compact. This is important for coding agents that load only the first n lines of a file.
- Parameters:
bundle_path (
str|Path) – Path to the OKF bundle directory.check (
bool) – IfTrue, do not modify files; only report changes needed.diff (
bool) – IfTrue, include unified diff in results without modifying.links (
bool) – IfTrue, also updatelinksandbacklinksfrontmatter fields based on markdown body content.
- Return type:
list[FormattedResult]- Returns:
List of
FormattedResult, one per markdown file.- Raises:
FileNotFoundError – When bundle_path does not exist.
NotADirectoryError – When bundle_path is not a directory.
- okf_schema.api.list_bundle(bundle_path)¶
List all concepts in an OKF bundle.
- Parameters:
bundle_path (
str|Path) – Path to the OKF bundle directory.- Return type:
list[ConceptSummary]- Returns:
Sorted list of
ConceptSummaryobjects.- Raises:
FileNotFoundError – When bundle_path does not exist.
NotADirectoryError – When bundle_path is not a directory.
- okf_schema.api.show_bundle(bundle_path, concept_path)¶
Show a single concept’s frontmatter and body.
- Parameters:
bundle_path (
str|Path) – Path to the OKF bundle directory.concept_path (
str) – Relative path to the concept markdown file.
- Return type:
- Returns:
A
ConceptDetailwith frontmatter dict and body text.- Raises:
FileNotFoundError – When the concept file does not exist.
- okf_schema.api.index_bundle(bundle_path)¶
Regenerate all
index.mdfiles in an OKF bundle.For each directory containing markdown files, generates or updates an
index.mdlisting child concepts and subdirectories. Preserves bundle-root frontmatter if present.- Parameters:
bundle_path (
str|Path) – Path to the OKF bundle directory.- Return type:
list[IndexUpdate]- Returns:
List of
IndexUpdaterecords describing what changed.- Raises:
FileNotFoundError – When bundle_path does not exist.
NotADirectoryError – When bundle_path is not a directory.
- okf_schema.api.search_bundle(bundle_path, query)¶
Search concepts in an OKF bundle.
Performs a case-insensitive substring search across
title,description,type, andtagsfrontmatter fields.- Parameters:
bundle_path (
str|Path) – Path to the OKF bundle directory.query (
str) – Search string.
- Return type:
list[SearchResult]- Returns:
Sorted list of matching
SearchResultobjects.- Raises:
FileNotFoundError – When bundle_path does not exist.
NotADirectoryError – When bundle_path is not a directory.
- okf_schema.api.stats_bundle(bundle_path)¶
Compute statistics for an OKF bundle.
- Parameters:
bundle_path (
str|Path) – Path to the OKF bundle directory.- Return type:
- Returns:
A
BundleStatsobject with file counts, link counts, type/tag distributions, and directory counts.- Raises:
FileNotFoundError – When bundle_path does not exist.
NotADirectoryError – When bundle_path is not a directory.
- okf_schema.api.graph_bundle(bundle_path)¶
Build a concept link graph for an OKF bundle.
Parses all internal markdown links in concept bodies and returns an adjacency dictionary mapping each concept’s relative path to the list of concept paths it links to.
- Parameters:
bundle_path (
str|Path) – Path to the OKF bundle directory.- Returns:
{concept_path: [linked_path, ...]}.- Return type:
dict[str,list[str]]- Raises:
FileNotFoundError – When bundle_path does not exist.
NotADirectoryError – When bundle_path is not a directory.
- okf_schema.api.backlinks_bundle(bundle_path, targets)¶
Find all concepts that link to any of the given target concepts.
For each target path, scans every concept in the bundle and returns a backlink record for each concept that contains an internal markdown link pointing to that target. Reserved files (
index.md,log.md) are excluded as sources. Self-links are ignored.Targets may be given with or without the
.mdextension.- Parameters:
bundle_path (
str|Path) – Path to the OKF bundle directory.targets (
list[str]) – List of relative concept paths to find backlinks for.
- Return type:
list[BacklinkResult]- Returns:
Sorted list of
BacklinkResultrecords, one per backlink. Results are ordered by(target, source).- Raises:
FileNotFoundError – When bundle_path does not exist.
NotADirectoryError – When bundle_path is not a directory.