aiopsutil is an asynchronous version of the popular psutil library, designed to provide an efficient and non-blocking way to retrieve information on running processes and system utilization.
Project description
aiopsutil-python
aiopsutil: Asynchronous Utilities for Gathering System and Process Information
aiopsutil is an asynchronous version of the popular psutil library, designed to provide an efficient and non-blocking way to retrieve information on running processes and system utilization. This Python package is tailored for developers who need to monitor and manage system resources in an asynchronous programming environment.
Table of Contents
- Key Features
- Installation
- Initialization
- API Methods
- AsyncProcess Class
- Usage Examples
- Contributing
- License
Key Features
- Asynchronous Operations: Leverage Python's
asynciolibrary to perform system and process monitoring without blocking the event loop. - Comprehensive Functionality: Offers a rich set of functions to retrieve information about system CPU, memory, disks, network, sensors, and running processes.
- Ease of Integration: Designed with a familiar interface for users of
psutil, making it easy to adopt in existing projects. - Cross-Platform Support: Works on multiple operating systems, including Linux, Windows, and macOS.
Installation
To use aiopsutil, you must have psutil installed. You can install it using pip:
pip install psutil
Initialization
Create an instance of AsyncPSUtil within an asynchronous context:
async def main():
aps = AsyncPSUtil()
# Use aps to call methods...
API Methods
aiopsutil provides a variety of methods to asynchronously gather system and process information. Here's a brief overview:
CPU Related
cpu_percent(interval: float = 0.1, percpu: bool = False) -> float: Get CPU usage percentage.cpu_stats() -> Dict: Return CPU statistics.cpu_freq(percpu: bool = False) -> Dict: Get CPU frequency information.
Memory Related
virtual_memory() -> Dict: Return virtual memory information.swap_memory() -> Dict: Return swap memory information.
Disk Related
disk_usage(path: str = "/") -> Dict: Get disk usage information for the given path.disk_io_counters(perdisk: bool = False) -> Dict: Return disk I/O statistics.
Network Related
net_io_counters(pernic: bool = False) -> Dict: Return network I/O statistics.net_connections(kind: str = 'inet') -> List[Dict]: Return a list of network connections.
Sensors Related
sensors_temperatures() -> Dict: Return temperature data grouped by sensor.sensors_battery() -> Dict: Return battery status information.
System Information
boot_time() -> float: Return system boot timestamp.users() -> List[Dict]: Return a list of logged-in users.
Process Management
process_iter(attrs: List[str] = None): An asynchronous iterator for iterating over processes.process_by_pid(pid: int) -> AsyncProcess: Get a process object by PID.
AsyncProcess Class
The AsyncProcess class provides methods to interact with individual processes:
memory_info() -> Dict: Return memory information.terminate()/kill(): Terminate the process.children(recursive: bool = False) -> List[AsyncProcess]: Get a list of child processes.
Usage Examples
Here's an example of how to use aiopsutil to monitor system resources:
import asyncio
async def monitor_system():
aps = AsyncPSUtil()
# Get CPU usage
cpu_usage = await aps.cpu_percent(interval=1)
print(f"CPU Usage: {cpu_usage}%")
# Get memory information
mem_info = await aps.virtual_memory()
print(f"Memory Used: {mem_info['used'] / 1024**3:.2f} GB")
# Iterate over processes
async for proc in aps.process_iter(['pid', 'name']):
if proc.info['name'] == 'python':
p = await aps.process_by_pid(proc.info['pid'])
mem = await p.memory_info()
print(f"Python process using {mem['rss']} bytes")
# Run the monitor system function
asyncio.run(monitor_system())
Contributing
Contributions to aiopsutil are welcome! Please ensure that your code follows the existing coding standards and passes all tests before submitting a pull request.
License
aiopsutil is licensed under the BSD 3-Clause License. See the LICENSE file for more details.
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 aiopsutil-0.1.0.tar.gz.
File metadata
- Download URL: aiopsutil-0.1.0.tar.gz
- Upload date:
- Size: 8.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9dc6f82d8fbd7921b8c68631adb5c87b161033e2f9d9c86c0e16db1a9ed96ff1
|
|
| MD5 |
3f5cde300f0e61ad91f91938d00c05e4
|
|
| BLAKE2b-256 |
94995e1348bd5eff77582e0105d2553ce3fecc489e65b6987a27064371d67662
|
File details
Details for the file aiopsutil-0.1.0-py3-none-any.whl.
File metadata
- Download URL: aiopsutil-0.1.0-py3-none-any.whl
- Upload date:
- Size: 7.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
57625dcf90acb672df3ffd9c59cd8bccb7effba12697a973bf9d3cb9477f1324
|
|
| MD5 |
4906c5f26a60daa16fe83633cba4f463
|
|
| BLAKE2b-256 |
abe5d86e0814810aca160cd5f4daaf89866b629c5c9c24572f3c75072a898d0e
|