Skip to main content

MoodleSolver

Async Moodle quiz automation client with a Telethon-style session API.

Features

  • Telethon-style session: start(), connect(), disconnect(), is_connected
  • Fully async on top of aiohttp and a Camofox browser API
  • Multi-client: run several accounts in parallel, each with its own browser profile; disconnect() only touches that client's tabs
  • All question types: single choice, multiple choice, text answers, matching, image questions
  • Question dumps: every question saved as JSON (+ optional JPG image) for offline analysis
  • Review parser: fetch attempt reviews after submission
  • Result tracking: read the final grade table

Requirements

  • Python 3.10+
  • A running Camofox browser API (default http://localhost:9377)

Install

pip install moodlesolver

Quick start

import asyncio
from moodlesolver import AsyncMoodle

async def main():
    async with AsyncMoodle(
        site="https://moodle.example.edu",
        username="user@example.edu",
        password="secret",
    ) as m:
        print("logged in as", await m.whoami())

        await m.resume_attempt(quiz_id=123)
        q = await m.current_page()
        print(q["number"], q["text"], [o["label"] for o in q["options"]])

        r, nxt = await m.answer_step(["correct answer label"])
        print("answered", r, "timer left", nxt["timer"])

        await m.finish_attempt()
        print(await m.quiz_result(quiz_id=123))

asyncio.run(main())

Session lifecycle

m = AsyncMoodle(site=..., username=..., password=...)
await m.connect()            # open HTTP session to the browser API
await m.start()              # login (or reuse an existing session)
...
await m.disconnect()         # close this client's tabs and session

AsyncMoodle also works as an async context manager (async with).

API overview

Method Description
start() / connect() / disconnect() Session lifecycle
login(u, p) / whoami() Authentication
new_tab(url) / pick(substr) / tabs() / close_stale() Tab management
current_page() Parse the current question (type, options, timer)
answer_step(labels) Answer by label text, then submit ("next") in one step
answer_text(text) Fill a text-answer input
answer_match(pairs) Fill matching selects
download_image(path) / download_all_images(prefix) Export question images
dump_question(q, quiz_id) / step_quiz(quiz_id, bank) Dump questions and drive a full quiz from an answer bank
resume_attempt(quiz_id) / finish_attempt() / quiz_result(quiz_id) / review(attempt, cmid) Quiz lifecycle

Question bank format

step_quiz accepts a dict mapping question text (case-insensitive substring) to the answer:

bank = {
    "Some question text": "single answer label",
    "Pick all that apply": ["first", "second"],
}

License

MIT

Metadata

Release files for moodlesolver 1.0.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 moodlesolver 1.0.0
File Size Uploaded
moodlesolver-1.0.0.tar.gz 7.7 kB Details

Built distribution (wheel)

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

Total release size: 15.9 kB

Release files / moodlesolver-1.0.0.tar.gz

Download URL moodlesolver-1.0.0.tar.gz
Size 7.7 kB
Tags Source
SHA-256 checksum
How to use checksums
eeb98bb9799ea243ff3f4803b49ef55d3cd05471b1328dd8a59ef5d41c5e0c40
BLAKE2b-256 checksum
How to use checksums
66c212038cb009807223028629aa9401fc15676e2ebe61daa0928a242faaa89c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Release files / moodlesolver-1.0.0-py3-none-any.whl

Download URL moodlesolver-1.0.0-py3-none-any.whl
Size 8.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f0e1c43cdae7015780ffcca59d520b2a6b65fee618d04cc967a9c6ee6f38b231
BLAKE2b-256 checksum
How to use checksums
3cad5d0626a8f7392803390091fb885ee37739680b0de3b8c9a0d441128ac05a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Release history Release notifications | RSS feed

2.4.8

2 release files

2.4.7

2 release files

2.4.6

2 release files

2.4.5

2 release files

2.4.4

2 release files

2.4.3

2 release files

2.4.2

2 release files

2.4.1

2 release files

2.4.0

2 release files

2.3.0

2 release files

2.2.0

2 release files

2.1.1

2 release files

2.1.0

2 release files

2.0.0

2 release files

This release

1.0.0 This release

2 release 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