Is it possible to make a minimalistic operating system using Python?
I really don't want to get into low-level code like assembly, so I want to use a simple
language like Perl, Python. But how?
-
2What are you hoping to achieve? – NPE Jun 05 '12 at 20:51
-
4Not without assembly or C being used _somewhere_ -- even pycorn has assembly for the bootstrap code. Interrupt handlers, likewise. – Charles Duffy Jun 05 '12 at 20:57
-
1I think [Ununium](http://sourceforge.net/projects/uuu/) was written entirely in python. Not quite sure if the project is still alive, though – inspectorG4dget Jun 05 '12 at 20:58
-
6IMO Perl and simple are two words that do not go together very well :) – betabandido Jun 05 '12 at 20:58
-
@inspectorG4dget It says right on the first page, "Our mission is to explore and develop new operating system concepts; to redefine the architecture while **using assembly language for most of the underlying architecture**." – Paul Manta Jun 05 '12 at 21:00
-
@PaulManta: I didn't actually visit the page. I recalled it from memory. I found out about it a long time ago (~3 years ago) when it was very python oriented. Sorry for the bad post, and thanks for the update – inspectorG4dget Jun 05 '12 at 21:03
-
2possible duplicate of [How much of an operating system could be written in, say, Python?](http://stackoverflow.com/questions/190464/how-much-of-an-operating-system-could-be-written-in-say-python) – Ignacio Vazquez-Abrams Jun 05 '12 at 21:04
-
An Idea: You could make a custom library in c and import it into python for things python can't do with operating systems. Also you could directly compile your python code to assembly/c/c++ – user3117152 Nov 18 '14 at 21:35
-
Yes certainly you could make an os in Python but you would need to modify to Python to make it work. You low level calls available and make it compiled (Python already compiled but it would need to be compacted to a few bytes), no modules and there is more. I think in the end it would be easier and quicker to learn Assembly and maybe C. With the currant Python there is no or little chance of this being possible without adding a huge amount of functionality to it but if you are still determined and have the knowledge, will and dedication. Good luck you'll get there eventually : ) – Xantium Sep 26 '17 at 21:11
4 Answers
Unfortunately Python is classified as a very high level programming language. It cannot be used, for example, to directly access hardware and perform low-level data structure manipulation. It is completely dependent on something to abstract the hardware from it, and that is the Kernel. It is, however, technically possible to create an operating system centered on Python, that is; have only the very low level stuff in written in C and assembly and have most of the rest of the operating system written in Python.
This article discusses with more detail what languages are suitable for writing operating system kernels.

- 6,409
- 2
- 23
- 18
-
11Nice article. The best quote of it is: _In many languages other than C a fair amount of Assembly and C development is required in order to provide the appropriate runtime environment supporting the language's abstractions._ – C2H5OH Jun 05 '12 at 21:14
-
"It is completely dependent on something to abstract the hardware from it, and that is the Kernel.". This statement is vague. In any programming language, for some functions you have to rely on system calls, for example, read() and write(). – losnihciL Dec 05 '21 at 09:48
-
@IosnihciL For many programming languages, using `read()` and `write()` are optional. If you prefer, you can simply implement them yourself if the language supports systems programming. In fact, that sort of thing is common in embedded development where there may not be any supporting software at all. Just you and the hardware. You cannot do that with standard Python. – Dougvj Dec 05 '21 at 18:10
-
Don't forget that Python can run shared libraries written in C (and Cython can create C code). You can do a lot more low-level-type stuff with Cython. – Brōtsyorfuzthrāx Sep 27 '22 at 10:10
You can certainly run Python without an OS, as shown by the The Intel BIOS Implementation Test Suite (BITS) Project. The scripting guide explains:
"... includes Python APIs to access various low-level functionality of the hardware platform, including ACPI, CPU and chipset registers, PCI, and PCI Express. You can write scripts to explore and test platform functionality, using the full power of Python in 32-bit ring 0, without an OS in the way.. "
Now, BITS is a BIOS testing platform specific to Intel hardware, and not meant to run a custom Python based OS, but that doesn't mean you couldn't try it...

- 972
- 11
- 22
I have ported Python interpreter to run in my operating system as a userspace program, it was the first program - and so far the only - that I ported; from this experience, I'd say it would certainly possible to write lots of the operating system functionality in Python; you can certainly even embed Python in the kernel with rather minimal feature support.
However you need to write assembly and C for the interrupts, low level memory management and so. In my case, I built a specially modified Python 2.5.2 against the Newlib C library; in minimal case you just need to provide heap memory management for the Newlib library, and you can have Python running on top of it.
As such, Python interpreter does not contain its own heap implementation, and it does depend on the C library, so you cannot run it on bare metal right away, but much more of the operating system kernel as is conventionally written, could also could be written in Python.
The special case of course are the microkernels, where much of the functionality is in userspace as services; these can be more naturally implemented in any preferred programming language, Python included.

- 129,958
- 22
- 279
- 321
I suggest you find a good textbook on operating system design, and study that. I'm pretty sure you won't find such a book with Python source code; C is more likely. (You might find an older textbook that uses Pascal instead of C, but it's really not that different.)
Once you have studied operating systems design enough to actually be able to write an operating system, you will know enough to have your own opinions on what languages would be suitable.

- 74,789
- 21
- 92
- 117