type: Project title: okf-parser description: Relational inspection and validation for Open Knowledge Format bundles
okf-parser
Relational inspection and validation for Open Knowledge Format (OKF) v0.2 bundles.
okf-parser reads an OKF bundle without imposing a domain taxonomy, preserves
unknown frontmatter fields, and exposes concepts and links as
Ibis tables. This makes bundle-wide rules—identity,
lineage, cardinality, provenance, and profile-specific constraints—expressible
as deterministic relational checks.
Why another OKF tool?
The ecosystem already has good static linters and generators, including
okflint, okf-cli, and google-okf. This project focuses on a different
layer:
- compile a bundle into queryable relational tables;
- project those same relations into a NetworkX graph;
- validate OKF v0.2 conformance without rejecting extensions;
- distinguish normative errors from advisory diagnostics;
- let projects add cross-concept rules as Ibis expressions;
- produce stable human-readable and JSON reports for CI and agents.
The architectural boundary between strict authored OKF and source adapters is documented in
docs/architecture.md.
The parser and validation model are inspired by
franklinbaldo/sisprev: parse
documents independently from semantic validation, aggregate violations instead
of failing at the first bad concept, preserve authored bodies, and test
filesystem identity explicitly. No Sisprev-specific legal types are copied into
the core.
mrorigo/rust-okf inspired the stable
logical key, conservative metadata preservation, BOM/CRLF handling, and clean
separation between bundle parsing and downstream query surfaces. Its BM25,
vector index, storage format, and HTTP server are intentionally outside this
project's scope.
Quick start
uv sync
uv run okf-parser check path/to/bundle
uv run okf-parser check path/to/bundle --relational-schema okf.schema.sql
uv run okf-parser inventory path/to/bundle
uv run okf-parser graph path/to/bundle
uv run okf-parser format path/to/bundle
uv run okf-parser format path/to/bundle --write
uv run okf-parser duckdb path/to/bundle knowledge.duckdb
uv run okf-parser duckdb path/to/bundle knowledge.duckdb --overwrite
uv run okf-parser serve
uv run okf-parser serve --allow-write
The command exits with status 1 only when normative errors exist. Broken
cross-links are warnings because OKF v0.2 explicitly says they do not make a
bundle non-conformant.
The MCP server is commit-disabled by default. serve --allow-write exposes explicit
commit tools for formatting, relational apply, spec scaffolding, import, and DuckDB
export; preview tools remain available without the flag. Effect annotations describe
maximum tool effects but are not authorization or sandboxing.
format is an opinionated canonicalizer, not a syntax-preserving rewriter. It
keeps mdformat as its base and replaces only
the numbering policy for ordered lists: markers are decided while rendering, so
they are consecutive (1. 2. 3.) and never zero-padded to an even width. A list
starting at 101 is written 101. 102. 103., appending an item does not rewrite
the lines above it, and a list whose markers would exceed CommonMark's nine-digit
limit keeps plain numbering.
Formatting will not write a file whose protected block structure the rewrite
would change; such a file is reported in skipped_paths and left on disk.
Protected means the sequence, nesting and tag of every block, block attributes
such as an ordered list's start, and the content of code blocks, raw HTML and
frontmatter. Inline content — link targets, emphasis, text inside a paragraph or
table cell — is deliberately outside this check, because canonical formatting
rewrites inline whitespace.
Excluding paths
A repository that keeps OKF knowledge next to code, a README and vendored
dependencies has no root that validates cleanly. Checking the repository root
reports OKF001 for every unrelated Markdown file; checking each bundle
separately makes every link between bundles unresolvable, because the target
sits outside the checked root. Excluding subpaths is what lets one root cover
the whole tree, which is the only arrangement under which cross-bundle link
validation runs at all.
Put the patterns in an .okfignore beside the bundle, so the exclusions are
versioned with the content and CI needs no extra flags:
# vendored dependencies
vendor
# the knowledge inside them is not noise
!vendor/knowledge
# project Markdown at the root, not knowledge
/*.md
Or pass them for a single run — the option repeats, and adds to the file rather than replacing it:
uv run okf-parser check . --exclude vendor --exclude '/*.md'
Every command that reads a bundle accepts --exclude: check, inventory,
graph, format and duckdb. Excluded files are never read and never
written, so format --write on a repository root leaves vendored documents
alone.
Pattern semantics
.okfignore uses .gitignore pattern semantics, matched against
POSIX-style paths relative to the bundle root:
| pattern | matches | does not match |
|---|---|---|
vendor |
vendor/a.md, libs/vendor/a.md |
equipe/a.md |
/vendor |
vendor/a.md |
libs/vendor/a.md |
vendor/ |
vendor/a.md (directory only) |
a file named vendor |
*.md |
README.md, items/tarefa.md |
items/tarefa.markdown |
/*.md |
README.md |
items/tarefa.md |
docs/**/x.md |
docs/x.md, docs/a/b/x.md |
other/x.md |
!vendor/kb |
re-includes what an earlier pattern excluded |
- a pattern without a separator matches its name at any depth; a separator anchors it at the bundle root;
*and?stay inside one segment,[abc]and[!abc]classes work, and**spans segments;- a trailing
/matches directories only; !re-includes, and the last pattern that matches a path decides;#starts a comment, blank lines declare nothing, unescaped trailing spaces are dropped, and\#or\!escape a literal first character.
One deviation from .gitignore is deliberate. Git cannot re-include a path
whose parent directory is excluded, because it prunes the walk and never looks
back, so vendor plus !vendor/knowledge does nothing there. Here it works:
discovery descends whenever a negation exists. A negation that silently does
nothing is exactly the surprise this feature exists to prevent. With no
negation in the rules the walk still prunes, so excluding a vendored dependency
of several hundred documents never walks it.
The same rules are shared with the TypeScript package through
conformance/exclusion.json.
Migrating from the pre-0.14 semantics
Before 0.14.0 every pattern was anchored at the bundle root and ! was a
literal character. Two rewrites cover it:
| before | after | why |
|---|---|---|
*.md |
/*.md |
unanchored patterns now match at any depth |
vendor |
/vendor |
keep it root-only; leave as-is to match any depth |
A pattern that begins with a literal ! now needs \!.
Requiring a specification per type
OKF v0.2 only requires type to be non-empty, so a producer can invent a type,
emit concepts of it and keep a green check while that type's frontmatter
schema changes underneath its consumers.
The optional rule below closes that gap without inventing taxonomy: it derives a document path from each type in use and reports the types whose document is absent.
uv run okf-parser check ./bundle --require-spec ".okf/specs/{slug}.md"
uv run okf-parser check ./bundle --require-spec ".okf/specs/{slug}.md" --normative-spec
The template must contain {slug}. The slug is lowercase, with accents and
cedillas removed, whitespace and / turned into hyphens, and every remaining
non-alphanumeric character dropped:
type |
derived path |
|---|---|
Spec |
.okf/specs/spec.md |
Revisão Ciência |
.okf/specs/revisao-ciencia.md |
Peça Forense |
.okf/specs/peca-forense.md |
The path is derived, not declared. A spec: frontmatter field would be a
second fact free to disagree with the first, and putting the path in type
itself would tie identity to layout, so renaming a directory would invalidate
every concept of that type.
Missing documents are reported as OKF010 warnings, because a bundle mid-
adoption legitimately has legacy types without a document and that is not an
OKF v0.2 defect. --normative-spec promotes them to errors for a bundle that
has completed the adoption. The rule is off unless --require-spec is given.
GitHub Actions
Add the repository as a CI check:
steps:
- uses: actions/checkout@v7
- uses: franklinbaldo/okf-parser@v0.45.5
with:
path: knowledge
Rust end-to-end engine
The default Python and TypeScript implementations remain portable and require no Rust binary. For large bundles, build the native engine and pass its path explicitly:
cargo build --release --manifest-path rust-core/Cargo.toml
Python accepts load_bundle(root, rust_core=Path(".../okf-parser")); TypeScript accepts
loadBundle(root, { rustCore: ".../okf-core" }). The native process owns discovery,
bounded parallel reads, YAML/frontmatter, Markdown facts, validation, link resolution,
and content digests. The packaged okf-parser executable is the single Python command;
its ordinary subcommands dispatch to the Python CLI while private engine operations stay
inside the same executable. Omitting the option keeps the portable language-native fallback.
The composite action installs a pinned uv version and executes the same
validate_path() function used by the Python API, CLI, and MCP server.
Pin an exact version. There is no moving @v1 ref: this repository's tags are
package versions, because publish.yml refuses to publish a release whose tag
does not equal the version in pyproject.toml. A v1 tag would either break
that check or drift away from the version it claims to be. A major-version ref
becomes worth introducing when the package itself reaches 1.0.0.
Releases are published to PyPI from GitHub Releases through OIDC Trusted Publishing. No long-lived PyPI token is stored in the repository.
Every pull request must increase the SemVer version in pyproject.toml and add
exactly one matching changelog/<version>.md entry. CI compares both against
the target branch before allowing merge.
MCP
uv run okf-parser serve
uv run fastmcp run
Read-only tools: check, inventory, graph, and format_check.
DuckDB
okf-parser is a regular uv-managed Python app; the DuckDB integration is part
of the same package, not a native C++ subproject:
import duckdb
from okf_parser.duckdb import attach_okf
connection = duckdb.connect("knowledge.duckdb")
attach_okf(connection, "knowledge/")
connection.sql("""
SELECT concept_type, count(*)
FROM okf.concepts
GROUP BY concept_type
""").show()
The call creates okf.concepts, okf.links, okf.reserved, and
okf.diagnostics as ordinary DuckDB tables. Materializing twice into the same
schema raises BundleExportError rather than clobbering an earlier export; pass
overwrite=True (or --overwrite on the command line) to replace the four
tables.
Python API
from pathlib import Path
from okf_parser import load_bundle, validate_path
bundle = load_bundle(Path("knowledge"))
print(bundle.concepts.execute())
print(bundle.links.execute())
print(bundle.to_networkx())
print(bundle.validate())
report = validate_path(Path("knowledge"))
assert report.markdown_count == report.concept_count + report.reserved_count
assert report.is_conformant
Declared RFC 0006 types can be queried directly as Ibis relations without a CLI or database-file round trip:
bundle = load_bundle(Path("knowledge"))
with bundle.compile_types("docs/types/{slug}.md") as typed:
routines = typed["Rotina"]
print(routines.filter(routines.custo.notnull()).execute())
TypedRelations owns an ephemeral DuckDB/Ibis backend; use it as a context manager or call close() explicitly. With no matching declarations, tables is empty rather than silently inventing an inferred physical schema.
load_bundle, validate_path and format_path read the bundle's .okfignore
on their own, and take an exclude sequence for patterns supplied per call:
report = validate_path(Path("."), exclude=["vendor", "*.md"])
validate_path also takes the optional type-specification rule:
report = validate_path(Path("knowledge"), require_spec=".okf/specs/{slug}.md")
Current scope
- UTF-8 Markdown discovery, matching
.mdcase-insensitively, with.gitignore-compatible exclusions from.okfignoreor--exclude; - reserved
index.mdandlog.mdhandling; - strict YAML-frontmatter parsing for concept documents, validated with Pydantic at the parse boundary so one malformed document cannot abort a run;
- required non-empty
type, optionally requiring a specification document per type in use; - stable concept IDs derived from paths;
- Markdown-link extraction and resolution;
- Ibis tables for concepts, reserved documents, and links;
- NetworkX graph projection for traversal, cycles, components, and impact;
- aggregated validation reports.
Profiles, lifecycle/provenance family validation, external resources, and pluggable Ibis rules are the next milestones.
Metadata
Release files for okf-parser 0.45.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| okf_parser-0.45.5.tar.gz | 607.2 kB | Without provenance | Details for okf_parser-0.45.5.tar.gz |
Built distributions (wheels)
| File | Actions Reset | |||
|---|---|---|---|---|
| okf_parser-0.45.5-py3-none-win_amd64.whl | Python 3 | none | Windows x86-64 | Details for okf_parser-0.45.5-py3-none-win_amd64.whl |
| okf_parser-0.45.5-py3-none-manylinux_2_28_x86_64.whl | Python 3 | none | Linux glibc 2.28+ x86-64 | Details for okf_parser-0.45.5-py3-none-manylinux_2_28_x86_64.whl |
| okf_parser-0.45.5-py3-none-manylinux_2_28_aarch64.whl | Python 3 | none | Linux glibc 2.28+ ARM64 | Details for okf_parser-0.45.5-py3-none-manylinux_2_28_aarch64.whl |
| okf_parser-0.45.5-py3-none-macosx_11_0_arm64.whl | Python 3 | none | macOS 11.0+ ARM64 | Details for okf_parser-0.45.5-py3-none-macosx_11_0_arm64.whl |
| okf_parser-0.45.5-py3-none-macosx_10_12_x86_64.whl | Python 3 | none | macOS 10.12+ x86-64 | Details for okf_parser-0.45.5-py3-none-macosx_10_12_x86_64.whl |
Total release size: 7.1 MB
Release files / okf_parser-0.45.5.tar.gz
| Download URL | okf_parser-0.45.5.tar.gz |
|---|---|
| Size | 607.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1c73a2bda4be3add0965c1fd7d93241e25060eed177c80c9d561c66ad84276be
|
|
BLAKE2b-256 checksum How to use checksums |
4b494312f810b6b0986f2588fa74b1593ec69be2111ecbacabe9a4a99300f5dc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.11.21 {"installer":{"name":"uv","version":"0.11.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / okf_parser-0.45.5-py3-none-win_amd64.whl
| Download URL | okf_parser-0.45.5-py3-none-win_amd64.whl |
|---|---|
| Size | 1.3 MB |
| Tags | Python 3 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
0a23331de371fcf94246a3840897c9fd41ad982f8eab6153e59468a7afc714dc
|
|
BLAKE2b-256 checksum How to use checksums |
c85ce837ffd1f86bcfdf0a7e26d7f572cb43831bcd7e4bbdfa6720e399b7c21b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.11.21 {"installer":{"name":"uv","version":"0.11.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / okf_parser-0.45.5-py3-none-manylinux_2_28_x86_64.whl
| Download URL | okf_parser-0.45.5-py3-none-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 1.4 MB |
| Tags | Linux glibc 2.28+ x86-64 Python 3 |
|
SHA-256 checksum How to use checksums |
e8dd2cc7e9ea0fc133231a25cda668998cc01b56cad2071f983153b90f837e82
|
|
BLAKE2b-256 checksum How to use checksums |
86e9aea7edaffba49c7ca7a7638eb2597cba30e2ca66207916084e1b1f05c438
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.11.21 {"installer":{"name":"uv","version":"0.11.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / okf_parser-0.45.5-py3-none-manylinux_2_28_aarch64.whl
| Download URL | okf_parser-0.45.5-py3-none-manylinux_2_28_aarch64.whl |
|---|---|
| Size | 1.3 MB |
| Tags | Linux glibc 2.28+ ARM64 Python 3 |
|
SHA-256 checksum How to use checksums |
23952a240a2869d636747184235256212ad1ca0904468e21bb4e9cbb08b9e5a3
|
|
BLAKE2b-256 checksum How to use checksums |
dea6f7861db84440113486abd9786a8384ac1d5e85e39cf33056a5f622f9d1ac
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.11.21 {"installer":{"name":"uv","version":"0.11.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / okf_parser-0.45.5-py3-none-macosx_11_0_arm64.whl
| Download URL | okf_parser-0.45.5-py3-none-macosx_11_0_arm64.whl |
|---|---|
| Size | 1.2 MB |
| Tags | Python 3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
a58a9bff797d231d85e10a69132133347e8e80ea33354e10372fe2297598a952
|
|
BLAKE2b-256 checksum How to use checksums |
458f7f025a202c2732d2474706e2213a9cd1af80742c49d680ac08681a63e699
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.11.21 {"installer":{"name":"uv","version":"0.11.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / okf_parser-0.45.5-py3-none-macosx_10_12_x86_64.whl
| Download URL | okf_parser-0.45.5-py3-none-macosx_10_12_x86_64.whl |
|---|---|
| Size | 1.3 MB |
| Tags | Python 3 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
de11f2419cec5624a31d3f7b835479d8df74b5468d160ff17bc9c3e6356e335a
|
|
BLAKE2b-256 checksum How to use checksums |
4ff6db74afef1eb06e4abc640481b76e76dc4c45f9f3ef2cb5c7283bd93eaf01
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.11.21 {"installer":{"name":"uv","version":"0.11.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for okf-parser 0.45.5
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.