Skip to main content

Python Moodle SDK

Project description

Poodle - Python Moodle

Poodle is an SDK intended for providing typed api interfacing with any Moodle instance.

It is part of a Bachelor Thesis and therefore only meant for educational purposes.

It is still work in progress.

Installation

Poodle can be installed by running:

pip install bchmnn.poodle

Basic Usage

async def main(moodle: Poodle):
  course = await moodle.get_user_course("<some_course_name>")
  groups = await moodle.core_group_get_course_groups(course.id)
  assignment = await moodle.get_assignment(course.id, index=-1)
  participants = await moodle.mod_assign_list_participants(assignment.id)

async def setup():
  url = "https://your.moodle.instance"
  poodle = Poodle(url)
  async with poodle as moodle:
    await moodle.auth()
    await main(moodle)

if __name__ == "__main__":
  asyncio.run(setup())

Advanced Usage

Credential Provider

The default credential provider is CLICredentialProvider that retrieves credentials through the command line.

If you want to define your own credential provider:

class CustomCredentialProvider(GenericCredentialProviderInterface):
  def __init__(self, id_provider_url="*", priority=3):
    super().__init__(id_provider_url, priority)

  def retrieve(self) -> Tuple[str, str]:
    # get credentials
    return (username, password)

  @property
  def name(self) -> str:
    return "PassCredentialProvider"

Authentication Provider

The default authentication provider is BrowserSSOHandler that opens the public_config.launchurl in a browser and retrieves the token by registering a custom url schema. The OS will handle the callback and propagate the token.

If you want to define your own authentication provider:

class CustomAuthHandler(AbstractSSOHandler):
  _login_providers: List[GenericCredentialProviderInterface]

  def __init__(
    self,
    id_provider_urls: List[str],
    priority: int = 0,
    login_providers: List[GenericCredentialProviderInterface] = [],
  ):
    super().__init__(priority, id_provider_urls)
    self.init_logger(LOGGER_NAME, level=LOGGING_LEVEL)
    self._login_providers = login_providers

  async def authenticate(
    self,
    public_config: CoreSitePublicConfig,
    session: aiohttp.ClientSession,
  ) -> Tokens:
    # fetch tokens
    return tokens

Use Custom Providers

If you have defined your custom credential and authentication provider you can apply them:

async def setup():
  url = "https://your.moodle.instance"

  login_provider = CustomCredentialProvider()
  auth_handler = CustomAuthHandler([url], priority=1, login_providers=[login_provider])

  poodle = Poodle(url, auth_handlers=[auth_handler])
  async with poodle as moodle:
    await moodle.auth()
    # do some stuff

Features

  • authentication using os browser
  • caching
  • types
    • core_webservice_get_site_info
    • core_enrol_get_users_courses
    • core_course_get_contents
    • core_group_get_course_groups
    • mod_assign_get_assignments
    • mod_assign_get_submissions
    • mod_assign_list_participants
    • more to come

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bchmnn.poodle-0.2.6.tar.gz (57.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

bchmnn.poodle-0.2.6-py3-none-any.whl (50.5 kB view details)

Uploaded Python 3

File details

Details for the file bchmnn.poodle-0.2.6.tar.gz.

File metadata

  • Download URL: bchmnn.poodle-0.2.6.tar.gz
  • Upload date:
  • Size: 57.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for bchmnn.poodle-0.2.6.tar.gz
Algorithm Hash digest
SHA256 4dfedad5e4375b44d0a0cd2d8caac4938b557908bea49a3dc3e9e24d28c47b90
MD5 c8a84703a22935392df28e031d67204c
BLAKE2b-256 08ba2d86a99e5189dade9b4fcef46ff7d82842dbd3d8d8d6da82d1b1944d9648

See more details on using hashes here.

File details

Details for the file bchmnn.poodle-0.2.6-py3-none-any.whl.

File metadata

  • Download URL: bchmnn.poodle-0.2.6-py3-none-any.whl
  • Upload date:
  • Size: 50.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for bchmnn.poodle-0.2.6-py3-none-any.whl
Algorithm Hash digest
SHA256 48cec8998c6ff3f6499aeb2e25d7594c5db30fe39a1944e2841a0793351fa24a
MD5 3700328d53d85a66a2b7fcec6daba30a
BLAKE2b-256 e0af8843322456c56a86434e080ea9599a6ad5b0d8ce1f2ced51a5634fe6433d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page