Python content type



I might create a new content type that would help people teaching python.

Be warned, there is a high probability that I will never do it. It's just something that I need, that I started to think about it, but I am not sure I will find time to do it and if I will success.

The idea is to allow the teacher to create an activity, the student must then write some python code that will be evaluated automatically and give him points if it's the good solution.

The author UI will contain :

- A textarea (with syntax highlighting) that would allow to set the default code.

- A textarea to add instruction ? Not sure about it as you can put instruction outside of the h5p activity.

- a textarea with the solution

- a number input field that would allow to set the max score

When the student submit it code, it is executed with the skulpt library. If the output match the solution output, then the max score is awarded.

If there is error in code, the error message is displayed.

There would also be an advanced checkbox. Checking that will display more option :

- a textarea containing code to execute before the student code

- a textarea where we can create code to execute after the student code. The purpose of this code is to check if the user solution is good and to give point. Multiple function (it's possible to add custom python function to skupt that will trigger javascript) will be avaible to the author :

→ a function to get the ouput (as a unique string or as an array of string)

→ a function to display a feedback message

→ a function to set score to the user

If you have any though to share, feel free to do it. 

otacke's picture

Perfect! That might allow me to cross one item from my list :-)



otacke's picture

serettig's picture

Awesome idea!

It would be great to make this so generic, so that it's easy to also use other languages, like Java, which is often used in educational settings.

it would be even better if you could add unit tests as a teacher that must be passed, so that you can also check for edge cases or check if the answer is truly generic.

unit tests will be sort of possible as the author will be able to create a python script to choose the grade given.

For other language, it need something able to execute this language in javascript. For python I use skulpt. I don't know if there is such things for other language.

It progress well but there is still a lots to do :

It progress well, it can now handle input python function !


This is going well but taking more time than I though. Didn't got time to play and half of my vacation are over.

It can now automatically grade by comparing if the output is the same.

It's almost possible to grade by using custom logic.


Lets say it's 75% done.

otacke's picture

Those things "always" take longer than you expect ;-) 

serettig's picture

The last 20% take 80% of the effort... ;) Good luck!

Sad news. I just discovered that codemirror doesn't work well on mobile :/

It look like it work but if you actively try to use it it will have critical glitchs :/

And as H5P is mobile friendly, this mobably means my content-type can't be added officially :/

I could see to use code mirror 6 instead of codemirror 5 but that will require lots of works :(

Luckily I found a workaround to make it work on mobile :)

I stopped a few day and it allowd me to see more clearly how my content-type options should be organised.

I was able to progress and it is now possible to choose values that will be return by the python input function. It is also possible to create multiple execution of the code for different set of input value.

I had a lots of trouble understanding Promise because I never needed them.

In this project there is a lots of use of Promise and I now understand why Promise where created. Everything make sense ! So I am happy about that :D

otacke's picture


Regarding Promises: Keep in mind that the H5P core team still tries to supports IE11 (not sure for how long) and that it does not support Promises. You may want to add a Polyfill or fall back to callback functions if you're not using some library that requires it. If you're using Promises, then async/await may become your friends :-)



Unfortunatly the Skulpt library that allow me to compile python code to javascript need promise (at least I need them to get input from user and to allow the user to stop infinite loop).

However, as I started from the question boiler plate, I do have the babel transpiler that serettig was talking (i just disabled part of it to debug easily but can enable it easily), so maybe it will allow polyfill to promise ? I don't know if I need somehow to also make the transpiller transpille the skulpt library code, i don't really know how babel etc. work it's the first time I used them. Or maybe I just find a polyfill library specifically for the promise and load them. Or maybe I should just detect IE 11 and display a message saying that this content type doesn't support it.

otacke's picture

Why do you need to disable the transpiler for debugging? I think core-js is a good module to use for adding polyfills.

If I am not wrong, this prevent me from debugging my code as it's minimized ?

otacke's picture

Nope. It's a) not minimized when you're using `npm run watch` which will conveniently build the distribution in the background and all you'll have to do is press F5 in your browser and it's b) providing a source map which will give you the proper faulty line of code in the error console.

Oh thanks ! At the start I used the build command and though it was me changing a parameter in a file that disabled minification but it was in fact me switching to the watch command.

Here a demo : !

There is annoying bug that I need to check and everything is not finished. It's an alpha :p

I'd be really interested by this plugin for teaching Python at university. What is the status please ? On the demo page, only the theird example works for me. I have a blank page for the first two. 
Thanks a lot for creating this anyway ! 


I stopped / paused the developpment of this plugin.

However it should be functionnal. The only thing missing if I remember is the part to restore previous state.

You can download source here : but you might need to do some search on how to add it to your LMS (and as it's been a while I didn't touched the code, I no longer remember it myself :D).

Also the third exemple require some javascript on the moodle page itself. But unless you want to do advanced things like that, you don't need to do javascript for just running and matching input / output or other things you would like.

ok thanks!

serettig's picture

It's probably best to use a transpiler like Babel at the moment until you can savely use modern JS in all browsers.

serettig's picture

Honestly, I would worry about IE11 support in 2021. IE11 is not even supported by its manufacturer anymore, so I think third party sites don't need to as well.

otacke's picture

I fully agree about IE11 support personally and would have loved to ignore it years ago, but I still try to follow a project's policy if I contribute (cmp. Microsoft still supports IE11 for M365 until August 19, 2021 if I am not mistaken. Let's hope we hear some words from the H5P core team soon.

But either way: Yes, it's your content type, Degrange, and you don't need to support IE11 if you don't want to. The web world has Safari on iOS to worry about now anyway :-D



Hi Degrange

I would like to use this in Lumi to create some content. I am not familiar with codes to install libraries. (I thought it is just about downloading the zip file from your Github portal and uploading it to Lumi Install Libraries page. But that failed.)

Can you please share any sample h5p file you might have created for this content type? It will be of great help.




Thanks Otacke. Will check. 

And ever so grateful for your contributions to H5P, including the ones that are in Review stage.