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
ListenMD — speech-only rendition scripts parse_listen, validate_listen

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

Metadata

Release files for pylearnspec 0.15.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pylearnspec 0.15.0
File Size Uploaded Provenance Actions
pylearnspec-0.15.0.tar.gz 81.2 kB Without provenance Details for pylearnspec-0.15.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pylearnspec 0.15.0
File Interpreter ABI Platform Actions
pylearnspec-0.15.0-py3-none-any.whl Python 3 none any Details for pylearnspec-0.15.0-py3-none-any.whl

Total release size: 163.5 kB

Release files / pylearnspec-0.15.0.tar.gz

Download URL pylearnspec-0.15.0.tar.gz
Size 81.2 kB
Tags Source
SHA-256 checksum
How to use checksums
d028892108b55015570366885ccd7a1e8b071f766915d43bcf9cd07ef38a8435
BLAKE2b-256 checksum
How to use checksums
76dcf9362f71acda50064319a2ef79a38618faa09de98582843f8c3a55860b10
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.8

Release files / pylearnspec-0.15.0-py3-none-any.whl

Download URL pylearnspec-0.15.0-py3-none-any.whl
Size 82.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c0278f5fcb752f969d3bdbdc50a7ae7f0d6e310ab12d87e6042a0f33df402a41
BLAKE2b-256 checksum
How to use checksums
229aad048028b16c1495fce138b95842acdedae428362fb847be397112746820
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.8

Security for pylearnspec 0.15.0

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.

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