Skip to content

Getting Started

Welcome to the Canonical Knowledge Structure (CKS) project.

This guide introduces the core ideas behind CKS and walks through the first steps of using the Python reference implementation.


Canonical Knowledge Structure (CKS) is an implementation-independent framework for representing knowledge.

Unlike traditional data formats, CKS separates knowledge from its representation.

Instead of treating JSON, XML, databases, or programming languages as the primary representation, CKS defines a canonical semantic model that every representation can share.

Knowledge
Canonical Knowledge Structure
┌────┼─────────────┐
▼ ▼ ▼
JSON Python Database

The same knowledge can therefore be represented in multiple ways while preserving identical meaning.


From PyPI (recommended):

Terminal window
pip install canonical-ks

Or from source:

Terminal window
git clone https://github.com/Deus-corp/CKS.git
cd CKS
pip install -e .

Verify the installation:

import cks
print(cks.__version__)

A Knowledge Object consists of:

  • a canonical identity;
  • a semantic structure.
from cks.core import ObjectIdentity
from cks.core import KnowledgeObject
identity = ObjectIdentity(
id="definition-1",
type="Definition",
name="Knowledge"
)
obj = KnowledgeObject(
identity=identity
)

Knowledge Objects are collected into a Knowledge Structure.

from cks.interface import construct
structure = construct([obj])

The resulting structure is immutable and can be safely inspected, validated, and serialized.


Validate the structure using the canonical validator.

from cks.interface import validate
result = validate(structure)
print(result.is_valid)

Diagnostics are available even for valid structures.

for diagnostic in result.diagnostics:
print(diagnostic)

Or use the command line:

Terminal window
cks validate examples/corpus/valid_theory_example.json

Knowledge Structures can be evolved through canonical structural operators.

from cks.interface import evolve
from cks.evolution import AddObject
new_obj = KnowledgeObject(
identity=ObjectIdentity(
id="definition-2",
type="Definition",
name="New Knowledge"
)
)
# Add a new object
evolved = evolve(structure, operators=[AddObject(new_obj)])

The original structure remains unchanged — evolution always returns a new structure.


Serialize the structure into canonical JSON.

from cks.interface import serialize
json_text = serialize(structure)
print(json_text)

Deserialize it back.

from cks.interface import parse
restored = parse(json_text)

The following property holds:

parse(serialize(S))

is structurally equivalent to

S

The reference engine provides several implementation-independent inspection operations.

from cks.interface import inspect
summary = inspect(structure)
print(summary)

Additional operations include:

  • compare()
  • extract()
  • project()
  • diagnose()

Execute the complete reference test suite.

Terminal window
python -m pytest -v

Current status: 110 tests, all passing.

All tests should pass before contributing changes.


src/
cks/
core.py
interface.py
engine.py
validator.py
validation.py
serialization.py
diagnostics.py
result.py
evolution.py
schema.py
plugin.py
schemas/
adapters/
jsonld_to_cks.py
cks_to_jsonld.py
rdf_to_cks.py
cks_to_rdf.py
cli/
__init__.py
formatters.py
commands/
validate.py
parse.py
inspect.py
evolve.py
convert.py
export.py
migrate.py
plugin.py
schema.py
constraints/
__init__.py
base.py
builtin.py
registry.py
structural.py
semantic.py
contradiction.py
reasoning.py
temporal.py
layering.py
ontology.py
projection.py
verification.py
docs/
examples/
corpus/
valid_theory_example.json
invalid_duplicate_id.json
invalid_dangling_reference.json
invalid_derivation_cycle.json
json/
cks-schema.json
tests/

After completing this guide, the recommended reading order is:

  1. Concepts
  2. Architecture
  3. API Reference
  4. Examples
  5. Core Specifications

These documents explain both the theory behind CKS and the design of the reference implementation.


The Python reference implementation follows the principles defined by the CKS specifications.

Every public operation is designed to be:

  • deterministic;
  • observationally pure;
  • implementation-independent;
  • representation-independent.

These guarantees allow different implementations to produce identical observable behaviour while remaining free to choose their internal architecture.


Continue with:

  • Concepts — the semantic foundations of CKS.
  • Architecture — the design of the reference implementation.
  • API Reference — the complete public interface.
  • Examples — practical usage patterns.
  • CLI Reference — use cks --help for command-line usage.