Skip to content

API Reference parrot.knowledge.pageindex.okf.bundle

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot.knowledge.pageindex.okf.bundle

View source

OKF v0.1 bundle import/export for PageIndex.

Provides two public functions:

  • :func:export_okf_bundle — Writes a PageIndex tree as an OKF v0.1 compliant directory bundle. Files are grouped by concept type (policies/, controls/, etc.), pageindex:// URIs are rewritten to relative markdown paths, and AI-Parrot-specific fields (node_id, resource) are stripped from frontmatter.

  • :func:import_okf_bundle — Reads an OKF bundle directory into a new PageIndex tree. YAML frontmatter is parsed from each .md file; unknown type values are mapped to :data:ConceptType.OTHER. Markdown hyperlinks in bodies are resolved to relates_to edges.

Round-trip guarantee: export → import preserves concept_id, type, relates_to, and body content.

Design notes (spec §2, §3 Modules 3 & 4):

  • Export follows the project_sidecars() iteration pattern.
  • Import uses two passes: first to collect concept_ids, second to resolve links.
  • index.md files are generated on export and skipped on import.
  • URI rewriting handles only pageindex:// scheme URIs; absolute URLs and anchor-only links are left unchanged.

Alias ConceptType

Re-exported from parrot.knowledge.pageindex.okf.ontology.ConceptType.

Class ExportReport

Result of an OKF bundle export operation.

Fields:

Field Type Default Description
tree_name str Name of the exported PageIndex tree.
output_dir str Absolute path of the bundle directory.
files_written int 0 Number of .md files written (excludes index.md).
index_generated bool False Whether a root index.md was generated.
uris_rewritten int 0 Total number of pageindex:// URIs rewritten.

Class ImportReport

Result of an OKF bundle import operation.

Fields:

Field Type Default Description
tree_name str Name of the newly created PageIndex tree.
input_dir str Absolute path of the source bundle directory.
nodes_created int 0 Number of PageIndex nodes created.
edges_created int 0 Number of relates_to edges created.
types_mapped dict[str, str] Mapping of raw type string → ConceptType.value.
unknown_types list[str] List of raw type strings that were unmapped (→ OTHER).

Alias JSONTreeStore

Re-exported from parrot.knowledge.pageindex.store.JSONTreeStore.

Alias NodeContentStore

Re-exported from parrot.knowledge.pageindex.content_store.NodeContentStore.

Alias RelationType

Re-exported from parrot.knowledge.pageindex.okf.ontology.RelationType.

Alias derive_concept_id

Re-exported from parrot.knowledge.pageindex.okf.concept_id.derive_concept_id.

Function export_okf_bundle

Export a PageIndex tree as an OKF v0.1 compliant directory bundle.

Creates a directory hierarchy grouped by concept type: policies/, controls/, sections/, etc. Each .md file contains OKF-standard YAML frontmatter (no node_id, no pageindex:// URIs) followed by the body content.

A root index.md is generated via :func:~parrot.knowledge.pageindex.okf.projection.generate_index_md.

export_okf_bundle(tree: dict, tree_name: str, content_store: NodeContentStore, output_dir: Path) -> ExportReport

Parameter Type Default Description
tree dict OKF-enriched PageIndex tree dict.
tree_name str Name of the tree (used in URI rewriting and index title).
content_store NodeContentStore :class:~parrot.knowledge.pageindex.content_store.NodeContentStore for loading sidecar bodies.
output_dir Path Destination directory. Created if absent.

Returns: ExportReport — class:ExportReport with counts of files written and URIs rewritten.

Alias flatten_concept_id_for_filename

Re-exported from parrot.knowledge.pageindex.okf.projection.flatten_concept_id_for_filename.

Alias generate_index_md

Re-exported from parrot.knowledge.pageindex.okf.projection.generate_index_md.

Function import_okf_bundle

Import an OKF bundle directory into a new PageIndex tree.

Reads all .md files in input_dir recursively (skipping index.md). For each file:

  1. Parses YAML frontmatter; unknown type values map to :data:ConceptType.OTHER.
  2. Creates a PageIndex node with the frontmatter data.
  3. Parses markdown links from the body and maps them to relates_to edges using a stem → concept_id map built in a first pass.

The resulting tree is saved via store and bodies via content_store.

.. note:: If a tree named tree_name already exists in store it will be overwritten atomically. To avoid data loss, choose a unique tree_name or delete the existing tree first.

import_okf_bundle(input_dir: Path, tree_name: str, store: JSONTreeStore, content_store: NodeContentStore) -> ImportReport

Parameter Type Default Description
input_dir Path Source OKF bundle directory.
tree_name str Name to assign to the new (or replacement) PageIndex tree.
store JSONTreeStore :class:~parrot.knowledge.pageindex.store.JSONTreeStore for persisting the new tree.
content_store NodeContentStore :class:~parrot.knowledge.pageindex.content_store.NodeContentStore for storing sidecar bodies.

Returns: ImportReport — class:ImportReport with counts of nodes and edges created.

Attribute logger

Alias parse_markdown_links

Re-exported from parrot.knowledge.pageindex.okf.graph.parse_markdown_links.

Alias structure_to_list

Re-exported from parrot.knowledge.pageindex.utils.structure_to_list.

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally