Skip to content

py-moodle

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

Usage:

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

Options:

  • -e, --env TEXT: Environment to use: local | staging | prod (also respects MOODLE_ENV) [default: local]
  • --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.

py-moodle courses

Manage courses: list, show, create, delete.

Usage:

$ py-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.
  • delete: Deletes a course by its ID.

py-moodle courses list

Lists all available courses.

Usage:

$ py-moodle courses list [OPTIONS]

Options:

  • --json: Display output in JSON format.
  • --help: Show this message and exit.

py-moodle courses show

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

Usage:

$ py-moodle courses show [OPTIONS] COURSE_ID

Arguments:

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

Options:

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

py-moodle courses create

Creates a new course.

Usage:

$ py-moodle courses create [OPTIONS]

Options:

  • --fullname TEXT: Full name for the new course. [required]
  • --shortname TEXT: Short name for the new course. [required]
  • --categoryid INTEGER: Category ID for the new course. [default: 1]
  • --visible INTEGER: 1 for visible, 0 for hidden. [default: 1]
  • --summary TEXT: Course summary.
  • --help: Show this message and exit.

py-moodle courses delete

Deletes a course by its ID.

Usage:

$ py-moodle courses delete [OPTIONS] COURSE_ID

Arguments:

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

Options:

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

py-moodle categories

Manage course categories: list, create, delete.

Usage:

$ py-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.

py-moodle categories list

Lists all available course categories.

Usage:

$ py-moodle categories list [OPTIONS]

Options:

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

py-moodle categories create

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

Usage:

$ py-moodle categories create [OPTIONS]

Options:

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

py-moodle categories delete

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

Usage:

$ py-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.

py-moodle sections

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

Usage:

$ py-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.

py-moodle sections list

Lists a summary of all sections in a specific course.

Usage:

$ py-moodle sections list [OPTIONS]

Options:

  • --course-id INTEGER: ID of the course to list sections from. [required]
  • --json: Display output in JSON format.
  • --help: Show this message and exit.

py-moodle sections show

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

Usage:

$ py-moodle sections show [OPTIONS] SECTION_ID

Arguments:

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

Options:

  • --course-id INTEGER: ID of the course the section belongs to. [required]
  • --json: Output in JSON format.
  • --help: Show this message and exit.

py-moodle sections create

Creates a new section at the end of a course.

Usage:

$ py-moodle sections create [OPTIONS]

Options:

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

py-moodle sections delete

Deletes a specific section by its ID.

Usage:

$ py-moodle sections delete [OPTIONS] SECTION_ID

Arguments:

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

Options:

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

py-moodle modules

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

Usage:

$ py-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,...

py-moodle modules delete

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

Usage:

$ py-moodle modules delete [OPTIONS] CMID

Arguments:

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

Options:

  • --help: Show this message and exit.

py-moodle modules show

Shows detailed information for a specific module.

Usage:

$ py-moodle modules show [OPTIONS] CMID

Arguments:

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

Options:

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

py-moodle modules list-types

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

Usage:

$ py-moodle modules list-types [OPTIONS]

Options:

  • --course-id INTEGER: Course ID to check available modules for. Defaults to 1. [default: 1]
  • --json: Output in JSON format.
  • --help: Show this message and exit.

py-moodle modules add

Add a new module to a course.

Usage:

$ py-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.

py-moodle modules add label

Adds a new label to a course section.

Usage:

$ py-moodle modules add label [OPTIONS]

Options:

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

py-moodle modules add scorm

Adds a new SCORM package to a course section.

Usage:

$ py-moodle modules add scorm [OPTIONS]

Options:

  • --course-id INTEGER: ID of the course to add the SCORM to. [required]
  • --section-id INTEGER: ID of the section to add the SCORM to. [required]
  • --name TEXT: Name of the SCORM package. [required]
  • --file FILENAME: Path to the SCORM package .zip file. [required]
  • --intro TEXT: Introduction or description for the SCORM.
  • --help: Show this message and exit.

py-moodle modules add assign

Adds a new assignment to a course section.

Usage:

$ py-moodle modules add assign [OPTIONS]

Options:

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

py-moodle modules edit

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

Usage:

$ py-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,...

py-moodle modules edit label

Edits an existing label module.

Usage:

$ py-moodle modules edit label [OPTIONS] CMID

Arguments:

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

Options:

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

py-moodle modules edit name

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

Usage:

$ py-moodle modules edit name [OPTIONS] CMID

Arguments:

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

Options:

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

py-moodle users

Manage Moodle users: list, create, delete.

Usage:

$ py-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.

py-moodle users list

Lists users enrolled in a specific course.

Usage:

$ py-moodle users list [OPTIONS]

Options:

  • --course-id INTEGER: ID of the course to list users from. [required]
  • --json: Display output in JSON format.
  • --help: Show this message and exit.

py-moodle users create

Creates a new user in Moodle.

Usage:

$ py-moodle users create [OPTIONS]

Options:

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

py-moodle users delete

Deletes a user from Moodle by their ID.

Usage:

$ py-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.

py-moodle admin

Moodle site administration tasks.

Usage:

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

Options:

  • --help: Show this message and exit.

Commands:

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

py-moodle admin enable-webservice

Activates a web service in Moodle. Requires administrator permissions.

Usage:

$ py-moodle admin enable-webservice [OPTIONS]

Options:

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

py-moodle folders

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

Usage:

$ py-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.

py-moodle folders add

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

Usage:

$ py-moodle folders add [OPTIONS]

Options:

  • --course-id INTEGER: ID of the course to add the folder to. [required]
  • --section-id INTEGER: ID of the section to add the folder to. [required]
  • --name TEXT: Name of the new folder. [required]
  • --intro TEXT: 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.

py-moodle folders delete

Deletes a folder module from a course.

Usage:

$ py-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.

py-moodle folders list-content

Lists the files and subdirectories inside a folder.

Usage:

$ py-moodle folders list-content [OPTIONS] CMID

Arguments:

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

Options:

  • --help: Show this message and exit.

py-moodle folders add-file

Adds a file to an existing folder.

Usage:

$ py-moodle folders add-file [OPTIONS]

Options:

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

py-moodle folders delete-file

Deletes a file from an existing folder.

Usage:

$ py-moodle folders delete-file [OPTIONS]

Options:

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

py-moodle folders rename-file

Renames a file inside an existing folder.

Usage:

$ py-moodle folders rename-file [OPTIONS]

Options:

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

py-moodle pages

Manage page modules: create and delete HTML pages.

Usage:

$ py-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.

py-moodle pages add

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

Usage:

$ py-moodle pages add [OPTIONS]

Options:

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

py-moodle pages delete

Delete a page module from a course.

Usage:

$ py-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.

py-moodle resources

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

Usage:

$ py-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.

py-moodle resources add

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

Usage:

$ py-moodle resources add [OPTIONS]

Options:

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

py-moodle resources delete

Delete a resource module from a course.

Usage:

$ py-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.

py-moodle urls

Manage URL modules: create and delete external links.

Usage:

$ py-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.

py-moodle urls add

Add a new URL module to a course section.

Usage:

$ py-moodle urls add [OPTIONS]

Options:

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

py-moodle urls delete

Delete a URL module from a course.

Usage:

$ py-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.

py-moodle site

Get site information.

Usage:

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

Options:

  • --help: Show this message and exit.

Commands:

  • info: Get site info.

py-moodle site info

Get site info.

Usage:

$ py-moodle site info [OPTIONS]

Options:

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