Skip to content

python-moodle

A CLI to manage Moodle via AJAX sessions and web services.

Usage:

$ python-moodle [OPTIONS] COMMAND [ARGS]...

Options:

  • -e, --env <str>: Environment to use: local | staging | prod (also respects MOODLE_ENV) [default: local]
  • -q, --quiet: Suppress incidental status output (banners, progress/confirmation messages). The command's primary result and any errors are still shown.
  • --no-color: Disable ANSI colors in table output. The NO_COLOR environment variable is also respected.
  • -v, --verbose: Enable verbose (INFO-level) diagnostics on stderr.
  • --debug: Enable debug-level diagnostics on stderr, including HTTP tracing from the authentication layer. Secret values are redacted.
  • --install-completion: Install completion for the current shell.
  • --show-completion: Show completion for the current shell, to copy it or customize the installation.
  • --help: Show this message and exit.

Commands:

  • courses: Manage courses: list, show, create, delete.
  • categories: Manage course categories: list, create,...
  • sections: Manage course sections: list, show,...
  • modules: Manage course modules...
  • users: Manage Moodle users: list, create, delete.
  • admin: Moodle site administration tasks.
  • folders: Manage folder modules: create, delete, and...
  • pages: Manage page modules: create and delete...
  • resources: Manage resource modules: create and delete...
  • urls: Manage URL modules: create and delete...
  • site: Get site information.
  • doctor: Diagnose connectivity, credentials, and...

python-moodle courses

Manage courses: list, show, create, delete.

Usage:

$ python-moodle courses [OPTIONS] COMMAND [ARGS]...

Options:

  • --help: Show this message and exit.

Commands:

  • list: Lists all available courses.
  • show: Shows a detailed summary of a specific...
  • create: Creates a new course.
  • ensure: Ensures a course with the given shortname...
  • delete: Deletes a course by its ID.

python-moodle courses list

Lists all available courses.

Usage:

$ python-moodle courses list [OPTIONS]

Options:

  • --output <table|json|yaml|csv>: Output format: table, json, yaml, or csv. [default: table]
  • --fields <str>: Comma-separated top-level fields to keep in machine-readable output (json/yaml/csv), in the given order. Ignored for table output; an unknown field is an error.
  • --help: Show this message and exit.

python-moodle courses show

Shows a detailed summary of a specific course, including its sections and modules.

Usage:

$ python-moodle courses show [OPTIONS] {course_id}

Arguments:

  • course_id: ID of the course to show. [required]

Options:

  • --output <table|json|yaml|csv>: Output format: table, json, yaml, or csv. [default: table]
  • --help: Show this message and exit.

python-moodle courses create

Creates a new course.

Usage:

$ python-moodle courses create [OPTIONS]

Options:

  • --fullname <str>: Full name for the new course. [required]
  • --shortname <str>: Short name for the new course. [required]
  • --categoryid <int>: Category ID for the new course. [default: 1]
  • --visible <int>: 1 for visible, 0 for hidden. [default: 1]
  • --summary <str>: Course summary.
  • --output <table|json|yaml|csv>: Output format: table, json, or yaml. [default: table]
  • --dry-run: Preview the course that would be created without calling Moodle.
  • --help: Show this message and exit.

python-moodle courses ensure

Ensures a course with the given shortname exists (create if missing).

Usage:

$ python-moodle courses ensure [OPTIONS]

Options:

  • --shortname <str>: Unique shortname to look up or create. [required]
  • --fullname <str>: Desired full name of the course. [required]
  • --category-id <int>: Desired category ID. [required]
  • --update / --no-update: Update fullname/category if the course already exists. [default: no-update]
  • --output <table|json|yaml|csv>: Output format: table, json, or yaml. [default: table]
  • --help: Show this message and exit.

python-moodle courses delete

Deletes a course by its ID.

Usage:

$ python-moodle courses delete [OPTIONS] {course_id}

Arguments:

  • course_id: ID of the course to delete. [required]

Options:

  • --force: Delete without asking for confirmation.
  • --output <table|json|yaml|csv>: Output format: table, json, or yaml. [default: table]
  • --dry-run: Preview the deletion without calling Moodle or prompting for confirmation.
  • --help: Show this message and exit.

python-moodle categories

Manage course categories: list, create, delete.

Usage:

$ python-moodle categories [OPTIONS] COMMAND [ARGS]...

Options:

  • --help: Show this message and exit.

Commands:

  • list: Lists all available course categories.
  • create: Creates a new course category.
  • delete: Deletes a course category by its ID.

python-moodle categories list

Lists all available course categories.

Usage:

$ python-moodle categories list [OPTIONS]

Options:

  • --output <table|json|yaml|csv>: Output format: table, json, yaml, or csv. [default: table]
  • --fields <str>: Comma-separated top-level fields to keep in machine-readable output (json/yaml/csv), in the given order. Ignored for table output; an unknown field is an error.
  • --help: Show this message and exit.

python-moodle categories create

Creates a new course category. This operation uses a session key (sesskey) and does not require a webservice token.

Usage:

$ python-moodle categories create [OPTIONS]

Options:

  • --name <str>: Name for the new category. [required]
  • --parent-id <int>: Parent category ID (default: 0 for top level). [default: 0]
  • --help: Show this message and exit.

python-moodle categories delete

Deletes a course category by its ID. The category must be empty. This operation uses a session key (sesskey).

Usage:

$ python-moodle categories delete [OPTIONS] {category_id}

Arguments:

  • category_id: ID of the category to delete. [required]

Options:

  • --force: Delete without a confirmation prompt.
  • --help: Show this message and exit.

python-moodle sections

Manage course sections: list, show, create, delete.

Usage:

$ python-moodle sections [OPTIONS] COMMAND [ARGS]...

Options:

  • --help: Show this message and exit.

Commands:

  • list: Lists a summary of all sections in a...
  • show: Shows detailed information of a specific...
  • create: Creates a new section at the end of a course.
  • delete: Deletes a specific section by its ID.

python-moodle sections list

Lists a summary of all sections in a specific course.

Usage:

$ python-moodle sections list [OPTIONS]

Options:

  • --course-id <int>: ID of the course to list sections from. [required]
  • --output <table|json|yaml|csv>: Output format: table, json, yaml, or csv. [default: table]
  • --fields <str>: Comma-separated top-level fields to keep in machine-readable output (json/yaml/csv), in the given order. Ignored for table output; an unknown field is an error.
  • --help: Show this message and exit.

python-moodle sections show

Shows detailed information of a specific section, including its modules.

Usage:

$ python-moodle sections show [OPTIONS] {section_id}

Arguments:

  • section_id: ID of the section to show. [required]

Options:

  • --course-id <int>: ID of the course the section belongs to. [required]
  • --output <table|json|yaml|csv>: Output format: table, json, yaml, or csv. [default: table]
  • --help: Show this message and exit.

python-moodle sections create

Creates a new section at the end of a course.

Usage:

$ python-moodle sections create [OPTIONS]

Options:

  • --course-id <int>: ID of the course where to create the section. [required]
  • --help: Show this message and exit.

python-moodle sections delete

Deletes a specific section by its ID.

Usage:

$ python-moodle sections delete [OPTIONS] {section_id}

Arguments:

  • section_id: ID of the section to delete. [required]

Options:

  • --course-id <int>: ID of the course the section belongs to. [required]
  • --help: Show this message and exit.

python-moodle modules

Manage course modules (resources/activities) like labels, SCORMs, etc.

Usage:

$ python-moodle modules [OPTIONS] COMMAND [ARGS]...

Options:

  • --help: Show this message and exit.

Commands:

  • delete: Deletes any module (label, SCORM, folder,...
  • show: Shows detailed information for a specific...
  • list-types: Lists all available module types...
  • add: Add a new module to a course.
  • edit: Edit existing course modules (labels,...

python-moodle modules delete

Deletes any module (label, SCORM, folder, etc.) by its ID. This uses the centralized delete function from the library.

Usage:

$ python-moodle modules delete [OPTIONS] {cmid}

Arguments:

  • cmid: ID of the module (cmid) to delete. [required]

Options:

  • --help: Show this message and exit.

python-moodle modules show

Shows detailed information for a specific module.

Usage:

$ python-moodle modules show [OPTIONS] {cmid}

Arguments:

  • cmid: ID of the module (cmid) to show. [required]

Options:

  • --output <table|json|yaml|csv>: Output format: table, json, or yaml. [default: table]
  • --help: Show this message and exit.

python-moodle modules list-types

Lists all available module types (activities/resources) that can be added to a course.

Usage:

$ python-moodle modules list-types [OPTIONS]

Options:

  • --course-id <int>: Course ID to check available modules for. Defaults to 1. [default: 1]
  • --output <table|json|yaml|csv>: Output format: table, json, or yaml. [default: table]
  • --help: Show this message and exit.

python-moodle modules add

Add a new module to a course.

Usage:

$ python-moodle modules add [OPTIONS] COMMAND [ARGS]...

Options:

  • --help: Show this message and exit.

Commands:

  • label: Adds a new label to a course section.
  • scorm: Adds a new SCORM package to a course section.
  • assign: Adds a new assignment to a course section.

python-moodle modules add label

Adds a new label to a course section.

Usage:

$ python-moodle modules add label [OPTIONS]

Options:

  • --course-id <int>: ID of the course to add the label to. [required]
  • --section-id <int>: ID of the section to add the label to. [required]
  • --html <str>: HTML content of the label. [required]
  • --name <str>: Internal name for the label. [default: Label (from CLI)]
  • --help: Show this message and exit.

python-moodle modules add scorm

Adds a new SCORM package to a course section.

Usage:

$ python-moodle modules add scorm [OPTIONS]

Options:

  • --course-id <int>: ID of the course to add the SCORM to. [required]
  • --section-id <int>: ID of the section to add the SCORM to. [required]
  • --name <str>: Name of the SCORM package. [required]
  • --file <filename>: Path to the SCORM package .zip file. [required]
  • --intro <str>: Introduction or description for the SCORM.
  • --output <table|json|yaml|csv>: Output format: table, json, or yaml. [default: table]
  • --dry-run: Preview the SCORM package that would be added without uploading it.
  • --help: Show this message and exit.

python-moodle modules add assign

Adds a new assignment to a course section.

Usage:

$ python-moodle modules add assign [OPTIONS]

Options:

  • --course-id <int>: ID of the course to add the assignment to. [required]
  • --section-id <int>: ID of the section to add the assignment to. [required]
  • --name <str>: Name of the new assignment. [required]
  • --intro <str>: Introduction or description for the assignment (HTML supported).
  • --help: Show this message and exit.

python-moodle modules edit

Edit existing course modules (labels, SCORMs, etc.)

Usage:

$ python-moodle modules edit [OPTIONS] COMMAND [ARGS]...

Options:

  • --help: Show this message and exit.

Commands:

  • label: Edits an existing label module.
  • name: Edits the name of any module (label,...

python-moodle modules edit label

Edits an existing label module.

Usage:

$ python-moodle modules edit label [OPTIONS] {cmid}

Arguments:

  • cmid: ID of the label module to edit. [required]

Options:

  • --html <str>: New HTML content for the label.
  • --name <str>: New internal name for the label.
  • --visible <int>: Set visibility (1 for visible, 0 for hidden).
  • --help: Show this message and exit.

python-moodle modules edit name

Edits the name of any module (label, assign, SCORM, etc.).

Usage:

$ python-moodle modules edit name [OPTIONS] {cmid}

Arguments:

  • cmid: ID of the module (cmid) to rename. [required]

Options:

  • -n, --name <str>: The new name for the module. [required]
  • --help: Show this message and exit.

python-moodle users

Manage Moodle users: list, create, delete.

Usage:

$ python-moodle users [OPTIONS] COMMAND [ARGS]...

Options:

  • --help: Show this message and exit.

Commands:

  • list: Lists users enrolled in a specific course.
  • create: Creates a new user in Moodle.
  • delete: Deletes a user from Moodle by their ID.

python-moodle users list

Lists users enrolled in a specific course.

Usage:

$ python-moodle users list [OPTIONS]

Options:

  • --course-id <int>: ID of the course to list users from. [required]
  • --output <table|json|yaml|csv>: Output format: table, json, yaml, or csv. [default: table]
  • --fields <str>: Comma-separated top-level fields to keep in machine-readable output (json/yaml/csv), in the given order. Ignored for table output; an unknown field is an error.
  • --help: Show this message and exit.

python-moodle users create

Creates a new user in Moodle.

Usage:

$ python-moodle users create [OPTIONS]

Options:

  • --username <str>: Username (must be unique). [required]
  • --password <str>: Password (must meet site policy). [required]
  • --firstname <str>: First name. [required]
  • --lastname <str>: Last name. [required]
  • --email <str>: Email address (must be unique). [required]
  • --help: Show this message and exit.

python-moodle users delete

Deletes a user from Moodle by their ID.

Usage:

$ python-moodle users delete [OPTIONS] {user_id}

Arguments:

  • user_id: ID of the user to delete. [required]

Options:

  • --force: Delete without asking for confirmation.
  • --help: Show this message and exit.

python-moodle admin

Moodle site administration tasks.

Usage:

$ python-moodle admin [OPTIONS] COMMAND [ARGS]...

Options:

  • --help: Show this message and exit.

Commands:

  • enable-webservice: Activates a web service in Moodle.

python-moodle admin enable-webservice

Activates a web service in Moodle. Requires administrator permissions.

Usage:

$ python-moodle admin enable-webservice [OPTIONS]

Options:

  • --service-id <int>: Web service ID to activate (default: 1 for 'Moodle mobile app'). [default: 1]
  • --help: Show this message and exit.

python-moodle folders

Manage folder modules: create, delete, and manage their content.

Usage:

$ python-moodle folders [OPTIONS] COMMAND [ARGS]...

Options:

  • --help: Show this message and exit.

Commands:

  • add: Adds a new folder to a course section,...
  • delete: Deletes a folder module from a course.
  • list-content: Lists the files and subdirectories inside...
  • add-file: Adds a file to an existing folder.
  • delete-file: Deletes a file from an existing folder.
  • rename-file: Renames a file inside an existing folder.

python-moodle folders add

Adds a new folder to a course section, optionally with initial files.

Usage:

$ python-moodle folders add [OPTIONS]

Options:

  • --course-id <int>: ID of the course to add the folder to. [required]
  • --section-id <int>: ID of the section to add the folder to. [required]
  • --name <str>: Name of the new folder. [required]
  • --intro <str>: Introduction or description for the folder (HTML supported).
  • --file <filename>: Path to a file to include. Can be used multiple times.
  • --help: Show this message and exit.

python-moodle folders delete

Deletes a folder module from a course.

Usage:

$ python-moodle folders delete [OPTIONS] {cmid}

Arguments:

  • cmid: ID of the folder module (cmid) to delete. [required]

Options:

  • -f, --force: Delete without confirmation.
  • --help: Show this message and exit.

python-moodle folders list-content

Lists the files and subdirectories inside a folder.

Usage:

$ python-moodle folders list-content [OPTIONS] {cmid}

Arguments:

  • cmid: ID of the folder module (cmid) to inspect. [required]

Options:

  • --help: Show this message and exit.

python-moodle folders add-file

Adds a file to an existing folder.

Usage:

$ python-moodle folders add-file [OPTIONS]

Options:

  • --cmid <int>: ID of the folder to add the file to. [required]
  • --file <filename>: Path of the local file to upload. [required]
  • --subfolder <str>: Path to the subfolder inside the Moodle folder (e.g., '/scorms/'). Must start and end with '/'. [default: /]
  • --help: Show this message and exit.

python-moodle folders delete-file

Deletes a file from an existing folder.

Usage:

$ python-moodle folders delete-file [OPTIONS]

Options:

  • --cmid <int>: ID of the folder containing the file. [required]
  • --filename <str>: Name of the file to delete from the folder. [required]
  • -f, --force: Delete without confirmation.
  • --help: Show this message and exit.

python-moodle folders rename-file

Renames a file inside an existing folder.

Usage:

$ python-moodle folders rename-file [OPTIONS]

Options:

  • --cmid <int>: ID of the folder containing the file. [required]
  • --old-name <str>: The current name of the file. [required]
  • --new-name <str>: The new name for the file. [required]
  • --help: Show this message and exit.

python-moodle pages

Manage page modules: create and delete HTML pages.

Usage:

$ python-moodle pages [OPTIONS] COMMAND [ARGS]...

Options:

  • --help: Show this message and exit.

Commands:

  • add: Add a new page module with HTML content to...
  • delete: Delete a page module from a course.

python-moodle pages add

Add a new page module with HTML content to a course section.

Usage:

$ python-moodle pages add [OPTIONS]

Options:

  • --course-id <int>: ID of the course to add the page to. [required]
  • --section-id <int>: ID of the section to add the page to. [required]
  • --name <str>: Name/title of the page. [required]
  • --file <filename>: Path to a file containing the HTML content. [required]
  • --intro <str>: Introduction or description for the page.
  • --help: Show this message and exit.

python-moodle pages delete

Delete a page module from a course.

Usage:

$ python-moodle pages delete [OPTIONS] {cmid}

Arguments:

  • cmid: ID of the page module (cmid) to delete. [required]

Options:

  • -f, --force: Delete without confirmation.
  • --help: Show this message and exit.

python-moodle resources

Manage resource modules: create and delete single-file resources.

Usage:

$ python-moodle resources [OPTIONS] COMMAND [ARGS]...

Options:

  • --help: Show this message and exit.

Commands:

  • add: Add a new resource (single file) to a...
  • delete: Delete a resource module from a course.

python-moodle resources add

Add a new resource (single file) to a course section.

Usage:

$ python-moodle resources add [OPTIONS]

Options:

  • --course-id <int>: ID of the course to add the resource to. [required]
  • --section-id <int>: ID of the section to add the resource to. [required]
  • --name <str>: Name/title of the resource. [required]
  • --file <filename>: Path to the file to upload. [required]
  • --intro <str>: Introduction or description for the resource.
  • --help: Show this message and exit.

python-moodle resources delete

Delete a resource module from a course.

Usage:

$ python-moodle resources delete [OPTIONS] {cmid}

Arguments:

  • cmid: ID of the resource module (cmid) to delete. [required]

Options:

  • -f, --force: Delete without confirmation.
  • --help: Show this message and exit.

python-moodle urls

Manage URL modules: create and delete external links.

Usage:

$ python-moodle urls [OPTIONS] COMMAND [ARGS]...

Options:

  • --help: Show this message and exit.

Commands:

  • add: Add a new URL module to a course section.
  • delete: Delete a URL module from a course.

python-moodle urls add

Add a new URL module to a course section.

Usage:

$ python-moodle urls add [OPTIONS]

Options:

  • --course-id <int>: ID of the course to add the URL to. [required]
  • --section-id <int>: ID of the section to add the URL to. [required]
  • --name <str>: Name/title of the URL. [required]
  • --url <str>: The external URL to link. [required]
  • --intro <str>: Introduction or description.
  • --help: Show this message and exit.

python-moodle urls delete

Delete a URL module from a course.

Usage:

$ python-moodle urls delete [OPTIONS] {cmid}

Arguments:

  • cmid: ID of the URL module (cmid) to delete. [required]

Options:

  • -f, --force: Delete without confirmation.
  • --help: Show this message and exit.

python-moodle site

Get site information.

Usage:

$ python-moodle site [OPTIONS] COMMAND [ARGS]...

Options:

  • --help: Show this message and exit.

Commands:

  • info: Get site info.

python-moodle site info

Get site info.

Usage:

$ python-moodle site info [OPTIONS]

Options:

  • --json: Output as JSON.
  • --help: Show this message and exit.

python-moodle doctor

Diagnose connectivity, credentials, and session health.

Usage:

$ python-moodle doctor [OPTIONS] COMMAND [ARGS]...

Options:

  • --help: Show this message and exit.

Commands:

  • run: Run all diagnostic checks for the selected...

python-moodle doctor run

Run all diagnostic checks for the selected --env and report status.

Usage:

$ python-moodle doctor run [OPTIONS]

Options:

  • -o, --output <table|json|yaml|csv>: Output format. [default: table]
  • --help: Show this message and exit.