Skip to content

Quick Start

Get up and running with py-moodle in minutes!

Prerequisites

  • Python 3.8+ installed
  • Access to a Moodle instance
  • Valid Moodle credentials

1. Install py-moodle

pip install py-moodle

2. Configure Credentials

Create a .env file with your Moodle credentials:

cp .env.example .env

Edit the .env file (replace PROD with your target environment name):

MOODLE_PROD_URL=https://your-moodle-site.com
MOODLE_PROD_USERNAME=your-username
MOODLE_PROD_PASSWORD=your-password
# Optional: CAS URL and token
# MOODLE_PROD_CAS_URL=https://cas.your-institution.org/cas
# MOODLE_PROD_WS_TOKEN=your_webservice_token

Select this environment by running commands with --env prod or by setting MOODLE_ENV=prod.

3. Test Your Setup

List all available courses:

py-moodle courses list

You should see output like:

┏━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ ID ┃ Shortname                    ┃ Fullname                          ┃
┡━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ 2  │ my-first-course              │ My first course                   │
│ 4  │ my-second-course             │ My second course                  │
└────┴──────────────────────────────┴───────────────────────────────────┘

4. Try Some Commands

Show course details:

py-moodle courses show 2

Create a new course:

py-moodle courses create --fullname "Test Course" --shortname "test-001"

Add content to a course:

py-moodle modules add label --course-id 2 --section-id 1 --name "Welcome" --intro "Welcome to the course!"

Next Steps

Need Help?

Use py-moodle --help or py-moodle COMMAND --help for detailed command information.