โ†
EDERSON DUARTE ITABAIANA

Building a System Info CLI Tool with Python

I recently built sysinfo, a command-line tool that displays Linux system information and integrates with the YouTube RSS feed to suggest a random DJ mix. Hereโ€™s a breakdown of the architecture and the libraries that made it possible.

Why Python?

For a system info tool, Python offers two things: fast iteration and excellent library support. The entire tool is about 200 lines of code and took a fraction of the time it would have taken in Java for the same result.

Architecture

The tool is structured around three concerns:

1. System Information Gathering

Linux exposes system information through /proc and specific commands. Hereโ€™s how each piece is collected:

import platform
import psutil

# OS and kernel
os_name = platform.system()
kernel = platform.release()

# Uptime
with open("/proc/uptime") as f:
    uptime_seconds = float(f.read().split()[0])

# CPU
cpu_model = ""
with open("/proc/cpuinfo") as f:
    for line in f:
        if "model name" in line:
            cpu_model = line.split(":")[1].strip()
            break
cpu_cores = psutil.cpu_count(logical=True)

# RAM
mem = psutil.virtual_memory()

For package count, I detect the distribution and call the appropriate command:

2. Display with Rich

Rich is what gives the terminal output its polished look. The Panel and Columns classes make it trivial to create boxed layouts:

from rich.console import Console
from rich.panel import Panel
from rich.table import Table

console = Console()

info_table = Table(show_header=False, box=None)
info_table.add_column(style="bold cyan")
info_table.add_column()

info_table.add_row("OS", os_name)
info_table.add_row("Kernel", kernel)
info_table.add_row("Uptime", formatted_uptime)

panel = Panel(info_table, title="System Info")
console.print(panel)

3. YouTube RSS Integration

YouTube channels expose a public RSS feed that requires no API key:

https://www.youtube.com/feeds/videos.xml?channel_id=UCegoQiMHYHprN_wLzAC0Vvw

Using the feedparser library, parsing it is straightforward:

import feedparser

feed = feedparser.parse(RSS_URL)

mixes = [
    entry for entry in feed.entries
    if is_mix(entry.title)
]

if mixes:
    pick = random.choice(mixes)
    print(f"๐ŸŽง {pick.title}")
    print(f"   โ†’ {pick.link}")
    print(f"   ๐Ÿ‘  {pick.media_community.media_statistics.get('views', 'N/A')} views")

CLI Interface

I used Typer for the CLI interface. It builds on Click but uses type hints for a cleaner API:

import typer

app = typer.Typer()

@app.command()
def main(
    system_only: bool = typer.Option(False, "--system-only", help="Show system info only"),
    set_only: bool = typer.Option(False, "--set-only", help="Show DJ set only"),
):
    if not set_only:
        show_system_info()
    if not system_only:
        show_dj_suggestion()

Packaging

The project uses pyproject.toml with a simple script entry point:

[project.scripts]
sysinfo = "sysinfo.cli:app"

This makes pip install . enough to have the sysinfo command available anywhere.

Conclusion

Building a CLI tool in Python is surprisingly satisfying. The combination of rich for display, psutil for system data, and feedparser for external integration makes for a clean, modular codebase. The full source is available on GitLab.