Build complete operating systems using Python - compiles to Assembly and Machine Code
Project description
๐ฅ๏ธ pyOS
Build complete operating systems using Python. Write your OS kernel in Python, and pyOS compiles it to Assembly and Machine Code that runs on real hardware.
โจ Features
- ๐ Write OS in Pure Python - No Assembly knowledge required
- โก Compiles to Native Code - Python โ Assembly โ Machine Code
- ๐จ VGA Text Mode - Full color support (16 colors)
- โจ๏ธ Keyboard Support - PS/2 keyboard driver included
- ๐ง Memory Management - GDT, heap allocation, stack management
- ๐ง QEMU Integration - Test your OS instantly
- ๐ฆ Easy Installation -
pip install pyOS
๐ Quick Start
Installation
pip install pyOS
Requirements: NASM and QEMU
# Windows (with chocolatey)
choco install nasm qemu
# Linux
sudo apt install nasm qemu-system-x86
# macOS
brew install nasm qemu
Hello World OS
from pyos import Kernel, Screen
kernel = Kernel(arch="x86")
@kernel.on_boot
def main():
Screen.clear()
Screen.set_color("green", "black")
Screen.print("Hello World!")
Screen.print("Welcome to my OS!", row=1)
kernel.build("myos.iso")
Run Your OS
qemu-system-i386 -fda myos.iso
๐ Documentation
Kernel
from pyos import Kernel
# Create a kernel targeting x86 architecture
kernel = Kernel(
arch="x86", # or "x86_64"
stack_size=16384, # 16KB stack
heap_size=1048576, # 1MB heap
)
# Register boot functions with priority (lower = runs first)
@kernel.on_boot(priority=0)
def early_boot():
pass
@kernel.on_boot(priority=1)
def late_boot():
pass
Screen (VGA Text Mode)
from pyos import Screen
# Clear screen
Screen.clear()
# Set default colors
Screen.set_color("white", "blue")
# Print text
Screen.print("Hello!")
Screen.print("At position", row=5, col=10)
Screen.print("Colored text", color="red", background="black")
# Available colors:
# black, blue, green, cyan, red, magenta, brown, light_gray,
# dark_gray, light_blue, light_green, light_cyan, light_red,
# light_magenta, yellow, white
Building & Running
# Build ISO image
kernel.build("myos.iso")
# Or build raw binary
kernel.build("myos.bin", format="bin")
# Generate Assembly only (for inspection)
asm_code = kernel.compile()
๐ฏ Examples
Multi-Stage Boot
from pyos import Kernel, Screen
kernel = Kernel(arch="x86")
@kernel.on_boot(priority=0)
def init():
Screen.clear()
Screen.print("Initializing...", color="cyan")
@kernel.on_boot(priority=1)
def load_drivers():
Screen.print("[OK] Drivers loaded", row=1, color="green")
@kernel.on_boot(priority=2)
def ready():
Screen.print("System Ready!", row=3, color="yellow")
kernel.build("myos.iso")
Colorful UI
from pyos import Kernel, Screen
kernel = Kernel(arch="x86")
@kernel.on_boot
def main():
Screen.clear()
# Draw a header
Screen.set_color("white", "blue")
Screen.print("=" * 40, row=0)
Screen.print(" My Operating System v1.0", row=1)
Screen.print("=" * 40, row=2)
# System info
Screen.set_color("green", "black")
Screen.print("[OK] CPU initialized", row=4)
Screen.print("[OK] Memory ready", row=5)
# Footer
Screen.set_color("yellow", "black")
Screen.print("Press any key to continue...", row=10)
kernel.build("myos.iso")
๐๏ธ Architecture
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Your Python Code โ
โ @kernel.on_boot โ
โ def main(): โ
โ Screen.print("Hello!") โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ pyOS Compiler โ
โ โข Parses Python code โ
โ โข Captures screen/keyboard operations โ
โ โข Generates x86 Assembly โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ NASM Assembler โ
โ โข Converts Assembly to Machine Code โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Bootable Image โ
โ โข Bootloader (512 bytes) โ
โ โข Kernel binary โ
โ โข Runs on QEMU or real hardware โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐ Project Structure
pyOS/
โโโ pyos/
โ โโโ __init__.py
โ โโโ kernel.py # Kernel class and decorators
โ โโโ builder.py # ISO/binary builder
โ โโโ emulator.py # QEMU integration
โ โโโ cli.py # Command-line interface
โ โโโ compiler/
โ โ โโโ codegen.py # Python โ Assembly
โ โ โโโ assembler.py # Assembly โ Machine Code
โ โโโ drivers/
โ โ โโโ screen.py # VGA text mode driver
โ โ โโโ keyboard.py # PS/2 keyboard driver
โ โโโ memory/
โ โ โโโ manager.py # Memory allocation
โ โ โโโ gdt.py # Global Descriptor Table
โ โโโ boot/
โ โโโ bootloader.asm # x86 bootloader
โโโ examples/
โโโ hello_world.py
โโโ keyboard_input.py
โโโ advanced_os.py
๐ ๏ธ CLI Commands
# Create new project
pyos new myos
# Build OS
pyos build main.py -o myos.iso
# Run in QEMU
pyos run myos.iso
# Debug mode
pyos debug myos.iso
# Generate Assembly only
pyos asm main.py -o kernel.asm
# Check dependencies
pyos check
๐ค Contributing
Contributions are welcome! Feel free to:
- ๐ Report bugs
- ๐ก Suggest features
- ๐ง Submit pull requests
๐ License
MIT License - feel free to use in your own projects!
๐ Acknowledgments
- NASM - The Netwide Assembler
- QEMU - Open source machine emulator
- OSDev Wiki - Invaluable OS development resources
Made with โค๏ธ for OS enthusiasts
Build your dream OS with Python!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pyos_kernel-0.1.0.tar.gz.
File metadata
- Download URL: pyos_kernel-0.1.0.tar.gz
- Upload date:
- Size: 30.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c40373104d3608b62307f0da3606ccbc62aaabe85687e450ba7ed936ec53cbb1
|
|
| MD5 |
2d29a1e71e312b9b40ee28b376fd67ee
|
|
| BLAKE2b-256 |
95ea142d727e0f597262d2059ec999e1d7a2fc7d072ff974c1de793f52ecc831
|
File details
Details for the file pyos_kernel-0.1.0-py3-none-any.whl.
File metadata
- Download URL: pyos_kernel-0.1.0-py3-none-any.whl
- Upload date:
- Size: 34.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a2815d29f331d4ee8fe4a3175c4b2c3f710bb6daccf60c74af3cb8a333865600
|
|
| MD5 |
7b98a0821028da4d272b530c0ba34f1d
|
|
| BLAKE2b-256 |
c49f90a4241d9f2272d1b3f0cb618b7c5ac2d297f6e6ecd71b6559156d7985cf
|