Skip to main content

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.

Python 3.8+ License: MIT

pyOS Screenshot

โœจ 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


Download files

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

Source Distribution

pyos_kernel-0.1.0.tar.gz (30.1 kB view details)

Uploaded Source

Built Distribution

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

pyos_kernel-0.1.0-py3-none-any.whl (34.1 kB view details)

Uploaded Python 3

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

Hashes for pyos_kernel-0.1.0.tar.gz
Algorithm Hash digest
SHA256 c40373104d3608b62307f0da3606ccbc62aaabe85687e450ba7ed936ec53cbb1
MD5 2d29a1e71e312b9b40ee28b376fd67ee
BLAKE2b-256 95ea142d727e0f597262d2059ec999e1d7a2fc7d072ff974c1de793f52ecc831

See more details on using hashes here.

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

Hashes for pyos_kernel-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a2815d29f331d4ee8fe4a3175c4b2c3f710bb6daccf60c74af3cb8a333865600
MD5 7b98a0821028da4d272b530c0ba34f1d
BLAKE2b-256 c49f90a4241d9f2272d1b3f0cb618b7c5ac2d297f6e6ecd71b6559156d7985cf

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