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
Metadata
Release files for bchmnn.poodle 0.2.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| bchmnn.poodle-0.2.6.tar.gz | 57.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| bchmnn.poodle-0.2.6-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 107.7 kB
Release files / bchmnn.poodle-0.2.6.tar.gz
| Download URL | bchmnn.poodle-0.2.6.tar.gz |
|---|---|
| Size | 57.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4dfedad5e4375b44d0a0cd2d8caac4938b557908bea49a3dc3e9e24d28c47b90
|
|
BLAKE2b-256 checksum How to use checksums |
08ba2d86a99e5189dade9b4fcef46ff7d82842dbd3d8d8d6da82d1b1944d9648
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.4
|
Release files / bchmnn.poodle-0.2.6-py3-none-any.whl
| Download URL | bchmnn.poodle-0.2.6-py3-none-any.whl |
|---|---|
| Size | 50.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
48cec8998c6ff3f6499aeb2e25d7594c5db30fe39a1944e2841a0793351fa24a
|
|
BLAKE2b-256 checksum How to use checksums |
e0af8843322456c56a86434e080ea9599a6ad5b0d8ce1f2ced51a5634fe6433d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.4
|