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 |
| 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
quizblocks (Level 2) - Question types: MCQ, multi-select, true/false, open answer, match, order
- Per-choice and global feedback (
[!correct],[!incorrect]) !importdirectives- 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.) !importdirectives (.learn.mdand.quiz.md)- Validation (lenient and strict modes)
LearnSpec suite (v0.2)
Every format follows the same shape:
- YAML frontmatter with the universal fields (
langrequired,license,spec_version,created,updated) - Cross-format directives
!import,!ref,!checkpoint(when applicable) — seepylearnspec.common.directives parse_<format>(content)returns a typed dataclass with a.to_dict()methodvalidate_<format>(content, strict=False)returns a list ofDiagnostic(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.11.1.tar.gz
(49.2 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pylearnspec-0.11.1.tar.gz.
File metadata
- Download URL: pylearnspec-0.11.1.tar.gz
- Upload date:
- Size: 49.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
uv/0.9.25 {"installer":{"name":"uv","version":"0.9.25","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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fee39b0da95f36cb6da4391f2f16f14822794928df2b01f26fb1cf76596e553c
|
|
| MD5 |
1cfc095acaffb9fe686396796be7a139
|
|
| BLAKE2b-256 |
173da917d1387d7d3929e9784d918cd87f04d245fa92e4b879b7b8bcc57dd40f
|
File details
Details for the file pylearnspec-0.11.1-py3-none-any.whl.
File metadata
- Download URL: pylearnspec-0.11.1-py3-none-any.whl
- Upload date:
- Size: 53.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
uv/0.9.25 {"installer":{"name":"uv","version":"0.9.25","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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7cca1bbc138298c0df08afe9b487b89733c4dc8473f632c496e86c5dc61b4fcd
|
|
| MD5 |
af179adc323c9496f792837b1678fa80
|
|
| BLAKE2b-256 |
20a5b9fadc8eeed808980ff0deb6ff9a9e5635913043f059a54affc8452cdf59
|