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.2.0.tar.gz (20.8 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.2.0-py3-none-any.whl (17.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: py_okf-0.2.0.tar.gz
  • Upload date:
  • Size: 20.8 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.2.0.tar.gz
Algorithm Hash digest
SHA256 c932108cd933a9f5918867b3e37d0d154ff2385c615dacfbac3b627e86b91e62
MD5 b696f1e6e135b6d0dbbd5e3adfc2bad5
BLAKE2b-256 725ce0bb85540bbd2f8171b1d7cdb35867088704d13e1c0527df05078cc7ced4

See more details on using hashes here.

File details

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

File metadata

  • Download URL: py_okf-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 17.8 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.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c16e3866b8c5a364f4d45a80b1ec4ec0c4566d843619c197b7d39619af0398f1
MD5 ba4d01835797de44c2355c91d112cce5
BLAKE2b-256 3392d425606784b96104054044839063d6baa5f4807b04266772eedd7979c4be

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