Skip to main content

osn_system_utils: A comprehensive cross-platform library for system process and network management.

This library provides a high-level API for managing system processes, discovering network ports, and executing OS-specific commands like shutdown or socket statistics on both Linux and Windows.

Technologies

Name Badge Description
Python Python The core language used for implementing the wrappers and logic.
Psutil Psutil Used for retrieving network connection details and mapping PIDs to ports.
Subprocess Subprocess Used to execute the underlying system shell commands.
Socket Socket Used for binding checks to identify free ports on localhost.

Key Features

  • Network Management
    • Find free ports on localhost using various strategies (min, max, random).
    • Map PIDs to active ports or formatted addresses.
    • Check for busy and free ports within specific ranges.
  • Process Management
    • Kill processes by name or PID with support for process trees.
    • Query process tables with advanced filtering (regex, equality, numeric ranges).
    • Cross-platform check for process existence.
  • OS-Specific Wrappers
    • Linux: High-level wrappers for pkill, kill, shutdown, and ss (socket statistics).
    • Windows: High-level wrappers for taskkill, shutdown, and netstat.

Installation

  1. Install library:

    • With pip:

      pip install osn_system_utils
      

      With pip (beta versions):

      pip install -i https://test.pypi.org/simple/ osn_system_utils
      
    • With git:

      pip install git+https://github.com/oddshellnick/osn_system_utils.git
      

      (Ensure you have git installed)

  2. Install the required Python packages using pip:

    pip install -r requirements.txt
    

Usage

Here are some examples of how to use osn_system_utils:

Network Port Discovery

from osn_system_utils.api.network import get_localhost_free_port_of

# Find the first available free port in the default range
port = get_localhost_free_port_of(on_candidates="min")
print(f"Available port: {port}")

# Find a random free port from a specific list
specific_port = get_localhost_free_port_of(ports_to_check=[8080, 8081, 9000], on_candidates="random")

Advanced Process Filtering

from osn_system_utils.api.process import get_process_table
import re

# Get all python processes using more than 100MB of memory
filters = {
    "memory_info.rss": 100 * 1024 * 1024
}
for proc in get_process_table(above_filter=filters):
    print(proc)

Linux Socket Statistics (ss)

from osn_system_utils.linux.ss import run_ss

# Get a summary of all listening TCP sockets
output = run_ss(mode="list", scope="listening", protocols=["tcp"])
print(output)

Classes and Functions

General Utilities (osn_system_utils.utils)

  • validate_parameter(...): Validates that a value exists within a sequence of allowed values.
  • run_command(...): Executes a shell command and returns the stdout.
  • deduplicate_list(...): Removes duplicates from an iterable while maintaining order.
  • CommandExecutionError: Exception raised when a system command fails.

Network API (osn_system_utils.api.network)

  • get_random_localhost_free_port()
  • get_localhost_pids_with_ports()
  • get_localhost_pids_with_addresses()
  • get_localhost_busy_ports()
  • get_localhost_free_ports()
  • get_localhost_free_port_of(...)

Process API (osn_system_utils.api.process)

  • kill_processes_by_name(...)
  • kill_process_by_pid(...)
  • get_process_table(...)
  • check_process_exists_by_pid(...)
  • check_process_exists_by_name(...)

Linux System Wrappers (osn_system_utils.linux)

  • kill:
    • run_pkill(...): Execute Linux pkill.
    • run_kill(...): Execute Linux kill for specific PIDs.
  • shutdown:
    • run_shutdown(...): Manage system power (reboot, poweroff, etc.).
  • ss:
    • run_ss(...): Execute socket statistics command.

Windows System Wrappers (osn_system_utils.windows)

  • netstat:
    • run_netstat(...): Execute Windows netstat with various flags.
  • shutdown:
    • run_shutdown(...): Manage Windows system power and restart behavior.
  • taskkill:
    • run_taskkill(...): Terminate tasks by PID or Image Name.

Future Notes

  • Implementation of MacOS specific command wrappers.
  • Asynchronous versions of command execution functions.
  • Wrappers for many other commands.
  • Integration with remote command execution via SSH.

Release files for osn-system-utils 0.0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for osn-system-utils 0.0.4
File Size Uploaded
osn_system_utils-0.0.4.tar.gz 14.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for osn-system-utils 0.0.4
File Interpreter ABI Platform
osn_system_utils-0.0.4-py3-none-any.whl Python 3 none any Details

Total release size: 32.1 kB

Release files / osn_system_utils-0.0.4.tar.gz

Download URL osn_system_utils-0.0.4.tar.gz
Size 14.6 kB
Tags Source
SHA-256 checksum
How to use checksums
d05ba9fca88731aa9fdb68c91a8b95f85d0b945ee5e8e40dc439b89cc808ff31
BLAKE2b-256 checksum
How to use checksums
c6935bd63492fe52a023d9e28da447ec4fb14b74fc119caae24a0b686cbe41e3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jan 25, 2026.

Transparency log

Release files / osn_system_utils-0.0.4-py3-none-any.whl

Download URL osn_system_utils-0.0.4-py3-none-any.whl
Size 17.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7a0b725e1e7e59763b122823a95b4eb4faaf08547ed3192359879af2b8c45bfa
BLAKE2b-256 checksum
How to use checksums
df41eb2284154c69b269f3c743f2c84d85ac31da4c6c460c49f08c545266baba
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jan 25, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.0.4 This release

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

0.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page