Skip to main content

Python library for Open Knowledge Format (OKF) file generation and refresh

Project description

py-okf

A Python library for generating and managing Open Knowledge Format (OKF) files from Python projects.

OKF is a vendor-neutral markdown specification that lets AI agents and humans access curated knowledge without vendor lock-in — a directory of .md files with YAML frontmatter, one file per concept (module, class, API, dataset, etc.).

py-okf analyzes your Python codebase using the ast module and generates an .okf/ bundle of markdown files describing your project's concepts.

Installation

pip install py-okf

CLI Usage

# Generate OKF files for a Python project
okf generate /path/to/your/project

# Refresh stale OKF files (only regenerates files where source changed)
okf refresh /path/to/your/project

# Validate OKF files against the spec
okf validate /path/to/your/project

# Custom output directory
okf generate /path/to/your/project -o docs/okf

# Include private (underscore-prefixed) symbols
okf generate /path/to/your/project --include-private

Python API

from pyokf import analyze_project, generate_module_concepts, OKFBundle
from pathlib import Path

# Analyze a project
modules = analyze_project(Path("./myproject"))

# Generate OKF concepts
bundle = OKFBundle(Path("./.okf"))
bundle.ensure_directory()
for module in modules:
    concepts = generate_module_concepts(module)
    bundle.write_all(concepts)

# Load and validate an existing bundle
bundle = OKFBundle(Path("./.okf")).load()
errors = bundle.validate_directory()

Generated Output

Running okf generate . produces an .okf/ directory with flat, dotted-name files:

.okf/
├── mypackage.md                    # module concept
├── mypackage.Connection.md         # class concept
└── mypackage.query.md              # api concept (exported function)

Each file contains YAML frontmatter followed by a markdown description:

---
type: api
title: mypackage.query
description: Execute a SQL query against the active connection.
resource: ./mypackage/__init__.py
tags:
- python
- api
timestamp: '2026-06-22T10:00:00Z'
---

# query

Execute a SQL query against the active connection.

## Signature

    def query(sql: str, params: Optional[list[str]] = None) -> list[dict]

## Parameters

- **`sql`**: `str`
- **`params`**: `Optional[list[str]]` *(default: `None`)*

## Returns

`list[dict]`

Concept Types

Type Description
module A Python module file
class A class definition
function A top-level function
api A function listed in __all__ (publicly exported)

Requirements

  • Python 3.10+
  • PyYAML >= 6.0

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

py_okf-0.1.0.tar.gz (15.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

py_okf-0.1.0-py3-none-any.whl (13.1 kB view details)

Uploaded Python 3

File details

Details for the file py_okf-0.1.0.tar.gz.

File metadata

  • Download URL: py_okf-0.1.0.tar.gz
  • Upload date:
  • Size: 15.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for py_okf-0.1.0.tar.gz
Algorithm Hash digest
SHA256 05fcef2066cf7ddf980ccb31e87badffa3392f8334411abd88db0d894a889be2
MD5 363a77582562ca351add3a4c0f9422c7
BLAKE2b-256 0aaf4e450454b053bd26c67eb9dd61d135415b14f7358f48e60990df03584d79

See more details on using hashes here.

File details

Details for the file py_okf-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: py_okf-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 13.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for py_okf-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c63269777cdd2d609f140bb47e2caa27d395520a7643bd01222f9523d756d65f
MD5 90ce3e0a97954c6a5676dbda0a27eab7
BLAKE2b-256 17877f1bc50bb912f8bd7a767c84c5a59b5e949bb2853f6ff24477ce0bab06a6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page