Skip to main content

pylearnspec

Python parser and validator for the LearnSpec suite of open standards:

Format API
LearnMD — instructional content parse_learn, validate_learn
QuizMD — assessments parse_quiz, validate_quiz
FlashMD — flashcards parse_flash, validate_flash
NuggetMD — micro-learning nuggets parse_nugget, validate_nugget
TrackMD — learning paths parse_track, validate_track
DiagramMD — diagrams parse_diagram, validate_diagram, serialize_diagram
AnimMD — step-reveal animations parse_anim, validate_anim, serialize_anim
MediaMD — media catalogues parse_media, validate_media
GlossaryMD — glossaries parse_glossary, validate_glossary
BadgeMD — micro-credentials parse_badge, validate_badge
CertMD — macro-credentials parse_cert, validate_cert

Install

pip install pylearnspec

Quick start

Parse a QuizMD file

from pylearnspec import parse_quiz

with open("my-quiz.quiz.md") as f:
    quiz = parse_quiz(f.read())

print(quiz.title)
print(f"{len(quiz.questions)} questions")

for q in quiz.questions:
    print(f"  Q{q.number} ({q.q_type}): {q.title}")

Parse a LearnMD file

from pylearnspec import parse_learn

with open("my-lesson.learn.md") as f:
    lesson = parse_learn(f.read())

print(lesson.title)
for section in lesson.sections:
    print(f"  {'#' * section.depth} {section.title}")

Validate

from pylearnspec import validate_quiz, validate_learn

# Lenient mode (default)
diagnostics = validate_quiz(content)

# Strict mode (for CI)
diagnostics = validate_quiz(content, strict=True)

for d in diagnostics:
    print(f"[{d.level}] {d.message}")

JSON output

Both Quiz and Lesson objects have a .to_dict() method for JSON serialization:

import json
from pylearnspec import parse_quiz

quiz = parse_quiz(content)
print(json.dumps(quiz.to_dict(), indent=2))

Supported features

QuizMD

  • Frontmatter (Level 1) and per-question quiz blocks (Level 2)
  • Question types: MCQ, multi-select, true/false, open answer, match, order
  • Per-choice and global feedback ([!correct], [!incorrect])
  • !import directives
  • Validation (lenient and strict modes)

LearnMD

  • Frontmatter metadata (lang, estimated_time, tags)
  • Section hierarchy (## modules, ### lessons)
  • Special fenced blocks: summary, example, note, tip, warning, quiz, etc.
  • GFM callout detection (> [!tip], > [!warning], etc.)
  • !import directives (.learn.md and .quiz.md)
  • Validation (lenient and strict modes)

AnimMD

  • Frontmatter (pace, captions, badges) and the bind intent layer ({node: A}, {edge: [A, B]}, {label: "text"})
  • One ## heading per step; the five verbs show, hide, draw, focus, pulse
  • Companion blocks in DiagramMD catalogues (```anim for:slug), preserved through parse_diagram/serialize_diagram round-trips (orphans included)
  • Validation (lenient and strict modes) and deterministic serialization

LearnSpec suite (v0.2)

Every format follows the same shape:

  • YAML frontmatter with the universal fields (lang required, license, spec_version, created, updated)
  • Cross-format directives !import, !ref, !checkpoint (when applicable) — see pylearnspec.common.directives
  • parse_<format>(content) returns a typed dataclass with a .to_dict() method
  • validate_<format>(content, strict=False) returns a list of Diagnostic(level, message)

Development

pip install -e ".[dev]"
pytest

License

MIT

Download files

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

Source Distribution

pylearnspec-0.14.0.tar.gz (73.0 kB view details)

Uploaded Source

Built Distribution

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

pylearnspec-0.14.0-py3-none-any.whl (74.7 kB view details)

Uploaded Python 3

File details

Details for the file pylearnspec-0.14.0.tar.gz.

File metadata

  • Download URL: pylearnspec-0.14.0.tar.gz
  • Upload date:
  • Size: 73.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for pylearnspec-0.14.0.tar.gz
Algorithm Hash digest
SHA256 3a5d5399b09facf15feb1316329620dbfd54f664d24ea9e82ea696e7b8c0c191
MD5 795b5abe6c608478cd8c8e9a706aed78
BLAKE2b-256 f9ffce7f9b7e6f27e8dea955e69487f32bba896b64ec22d884ec63165715c934

See more details on using hashes here.

File details

Details for the file pylearnspec-0.14.0-py3-none-any.whl.

File metadata

  • Download URL: pylearnspec-0.14.0-py3-none-any.whl
  • Upload date:
  • Size: 74.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for pylearnspec-0.14.0-py3-none-any.whl
Algorithm Hash digest
SHA256 71843271f9141701f9e430be20e2431948017a86b2e4ae2cf0f6251e8f71e779
MD5 b4e709e075ccfbf3001dd172879bd412
BLAKE2b-256 4eafc5523fc12f6290589f984cb6943cc4ada63349981f816309ec1915552e7d

See more details on using hashes here.

Release history Release notifications | RSS feed

0.15.0

2 files

This release

0.14.0 This release

2 files

0.13.0

2 files

0.11.1

2 files

0.11.0

2 files

0.10.0

2 files

0.9.0

2 files

0.8.0

2 files

0.7.1

2 files

0.7.0

2 files

0.6.0

2 files

0.5.0

2 files

0.4.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page