This library provides a set of Python abstractions for common system administration tasks on Linux and Windows, as well as utilities for network port management.
Project description
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
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, andss(socket statistics). - Windows: High-level wrappers for
taskkill,shutdown, andnetstat.
- Linux: High-level wrappers for
Installation
-
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)
-
-
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 Linuxpkill.run_kill(...): Execute Linuxkillfor 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 Windowsnetstatwith 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.
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
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 osn_system_utils-0.0.4.tar.gz.
File metadata
- Download URL: osn_system_utils-0.0.4.tar.gz
- Upload date:
- Size: 14.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d05ba9fca88731aa9fdb68c91a8b95f85d0b945ee5e8e40dc439b89cc808ff31
|
|
| MD5 |
80c55b7d803c334131c9a07d9c7a0dfc
|
|
| BLAKE2b-256 |
c6935bd63492fe52a023d9e28da447ec4fb14b74fc119caae24a0b686cbe41e3
|
Provenance
The following attestation bundles were made for osn_system_utils-0.0.4.tar.gz:
Publisher:
python-publish.yml on oddshellnick/osn-system-utils
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
osn_system_utils-0.0.4.tar.gz -
Subject digest:
d05ba9fca88731aa9fdb68c91a8b95f85d0b945ee5e8e40dc439b89cc808ff31 - Sigstore transparency entry: 851150641
- Sigstore integration time:
-
Permalink:
oddshellnick/osn-system-utils@eef9e17bb4f79c8ed282cc8f2d290d54f107d33f -
Branch / Tag:
refs/tags/v0.0.4 - Owner: https://github.com/oddshellnick
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@eef9e17bb4f79c8ed282cc8f2d290d54f107d33f -
Trigger Event:
release
-
Statement type:
File details
Details for the file osn_system_utils-0.0.4-py3-none-any.whl.
File metadata
- Download URL: osn_system_utils-0.0.4-py3-none-any.whl
- Upload date:
- Size: 17.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7a0b725e1e7e59763b122823a95b4eb4faaf08547ed3192359879af2b8c45bfa
|
|
| MD5 |
dfcf904d0dc9ae26e1bbe8437e221937
|
|
| BLAKE2b-256 |
df41eb2284154c69b269f3c743f2c84d85ac31da4c6c460c49f08c545266baba
|
Provenance
The following attestation bundles were made for osn_system_utils-0.0.4-py3-none-any.whl:
Publisher:
python-publish.yml on oddshellnick/osn-system-utils
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
osn_system_utils-0.0.4-py3-none-any.whl -
Subject digest:
7a0b725e1e7e59763b122823a95b4eb4faaf08547ed3192359879af2b8c45bfa - Sigstore transparency entry: 851150658
- Sigstore integration time:
-
Permalink:
oddshellnick/osn-system-utils@eef9e17bb4f79c8ed282cc8f2d290d54f107d33f -
Branch / Tag:
refs/tags/v0.0.4 - Owner: https://github.com/oddshellnick
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@eef9e17bb4f79c8ed282cc8f2d290d54f107d33f -
Trigger Event:
release
-
Statement type: