Registry / devops / uptime

uptime

JSON →
library3.0.1pypypi✓ verified 86d ago

The `uptime` library provides a cross-platform way to retrieve system uptime and boot time, aiming to do so without relying on external processes like parsing `uptime(1)` command output. It works on various major platforms, including Linux, Windows, macOS, and BSD systems. Despite its current version 3.0.1 being released in 2013, it remains a stable and widely used utility for basic system information.

pip install uptime
INSTALL
IMPORT
SIG · UPTIME
U
uptime
devopspythonv3.0.1
Install
2.4s avg
Import
14ms
Disk
17MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v3.0.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.010s · 19.2MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 2.4s · import 0.018s · 20MB
17MB installed
● package 17MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

uptime
from uptime import uptime
boottime
from uptime import boottime

This quickstart demonstrates how to fetch the system's uptime in seconds and its boot time as a `datetime` object. It includes error handling for cases where uptime or boot time cannot be determined.

from uptime import uptime, boottime import datetime def run_quickstart(): try: system_uptime_seconds = uptime() if system_uptime_seconds is not None: print(f"System Uptime: {system_uptime_seconds:.2f} seconds") uptime_timedelta = datetime.timedelta(seconds=system_uptime_seconds) print(f"System Uptime (formatted): {uptime_timedelta}") else: print("Could not determine system uptime.") system_boot_time = boottime() if system_boot_time is not None: print(f"System Boot Time: {system_boot_time}") else: print("Could not determine system boot time.") except RuntimeError as e: print(f"An error occurred: {e}") except Exception as e: print(f"An unexpected error occurred: {e}") if __name__ == '__main__': run_quickstart()
Debug
Known issues
gotchaThe `uptime` library heavily relies on Python's standard `ctypes` module for platform-specific system calls. On less common or custom Python installations, a broken or misconfigured `ctypes` can result in incorrect uptime values or `None` being returned.
fix
Ensure your Python installation's `ctypes` module is functioning correctly. It is advisable to test `uptime` on your specific deployment environment before critical reliance. If `None` is returned, implement checks in your code.
affects: All
gotcha`uptime.uptime()` returns the system's uptime as a `float` representing seconds, while `uptime.boottime()` returns the boot time as a `datetime.datetime` object. These different return types should be handled appropriately in arithmetic or display operations.
fix
Always check the return type of each function. For calculations involving both, convert `float` uptime to a `datetime.timedelta` object, or the `datetime.datetime` to a timestamp, to prevent `TypeError`.
affects: All (since 2.0 for `boottime` return type)
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'uptime'
The `uptime` package is not installed in the current Python environment.
fix
Install the package using pip: `pip install uptime`.
RuntimeError: The datetime module isn't available
The standard `datetime` module, which is a dependency for `uptime.boottime()`, is missing or inaccessible in the Python environment. This is highly unusual for a standard library module.
fix
This indicates a potentially corrupted or non-standard Python installation. Verify the integrity of your Python installation and ensure the `datetime` module is present and importable. Reinstalling Python might be necessary.
Upgrade
Version history
3.0.1latest on PyPI · released Oct 7, 2013
Audit
Dependencies

No dependency data recorded yet.

Agent activity
18 hits · last 30 days
node
18
Resources