Zero-dependency primitives for Logseq-style markdown knowledge graphs.
Extracted from markdown-graph-mcp and expanded to support graph bootstrapping.
- Title/filename encoding: Convert between Logseq's
___(triple-lowbar) namespace encoding and human-readable/paths - Directory management: Helpers for pages/, journals/, assets/, and .trash/ directories
- Config management: Ensure
logseq/config.edndeclares the required settings for correct namespace handling - Page I/O: Read/write page properties, soft-delete with trash recovery
- Graph bootstrap: Initialize a fresh, correctly-formed graph from scratch
Clone the repo and install:
git clone https://github.com/pburney/markdown-graph-kit.git
cd markdown-graph-kit
pip install -e .Or install from GitHub:
pip install git+https://github.com/pburney/markdown-graph-kit.gitfrom markdown_graph_kit import bootstrap_graph, page_path, set_page_property
# Create a new graph
graph_root = bootstrap_graph("path/to/my_graph")
# Write a page property
page = page_path(graph_root, "MyPage")
old_val, action = set_page_property(page, "type", "#MyType")
print(f"Property {action}: {old_val} → #MyType")See src/markdown_graph_kit/__init__.py for the full API and docstrings.
bootstrap_graph(graph_root)— create directories and config for a new graphtitle_to_filename(title)/filename_to_title(stem)— encode/decode namespace pathspages_dir(graph_root)/journals_dir(graph_root)/assets_dir(graph_root)— directory pathspage_path(graph_root, title)— canonical path for a pageparse_page_properties(filepath)— extract front-matter from a pageset_page_property(page_path, key, value)— add or update a propertybackup_page_file(page_file, graph_root)/delete_page_file(page_file, graph_root)— soft-delete with recoveryensure_graph_config(graph_root)— ensure config.edn has required settings
- Python: ≥3.11
- Dependencies: None (pure stdlib)
- Platforms: Linux, macOS, Windows (anywhere Python 3.11+ runs)
MIT
- markdown-graph-mcp — MCP server for markdown graph access