{"id":7841,"library":"uptime","title":"Uptime Library","description":"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.","status":"active","version":"3.0.1","language":"python","source_language":"en","source_url":"https://github.com/Cairnarvon/uptime","tags":["system","uptime","monitoring","cross-platform"],"install":[{"cmd":"pip install uptime","lang":"bash","label":"Install with pip"}],"dependencies":[],"imports":[{"symbol":"uptime","correct":"from uptime import uptime"},{"symbol":"boottime","correct":"from uptime import boottime"}],"quickstart":{"code":"from uptime import uptime, boottime\nimport datetime\n\ndef run_quickstart():\n    try:\n        system_uptime_seconds = uptime()\n        if system_uptime_seconds is not None:\n            print(f\"System Uptime: {system_uptime_seconds:.2f} seconds\")\n            uptime_timedelta = datetime.timedelta(seconds=system_uptime_seconds)\n            print(f\"System Uptime (formatted): {uptime_timedelta}\")\n        else:\n            print(\"Could not determine system uptime.\")\n\n        system_boot_time = boottime()\n        if system_boot_time is not None:\n            print(f\"System Boot Time: {system_boot_time}\")\n        else:\n            print(\"Could not determine system boot time.\")\n\n    except RuntimeError as e:\n        print(f\"An error occurred: {e}\")\n    except Exception as e:\n        print(f\"An unexpected error occurred: {e}\")\n\nif __name__ == '__main__':\n    run_quickstart()","lang":"python","description":"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."},"warnings":[{"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.","message":"The `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.","severity":"gotcha","affected_versions":"All"},{"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`.","message":"`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.","severity":"gotcha","affected_versions":"All (since 2.0 for `boottime` return type)"}],"env_vars":null,"search_vec":"'1':31 '2013':55 '3.0.1':51 'aim':19 'basic':65 'boot':17 'bsd':45 'command':32 'cross':9,72 'cross-platform':8,71 'current':49 'despit':47 'extern':26 'includ':40 'inform':67 'librari':2,5 'like':28 'linux':41 'maco':43 'major':38 'monitor':70 'output':33 'pars':29 'platform':10,39,73 'process':27 'provid':6 'releas':53 'reli':24 'remain':57 'retriev':13 'stabl':59 'system':14,46,66,68 'time':18 'uptim':1,4,15,30,69 'use':62 'util':63 'various':37 'version':50 'way':11 'wide':61 'window':42 'without':23 'work':35","created_at":"2026-04-16T14:15:41.891073+00:00","updated_at":"2026-04-16T14:15:41.891073+00:00","problems":[{"fix":"Install the package using pip: `pip install uptime`.","cause":"The `uptime` package is not installed in the current Python environment.","error":"ModuleNotFoundError: No module named 'uptime'"},{"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.","cause":"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.","error":"RuntimeError: The datetime module isn't available"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"3.0.1","cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/Cairnarvon/uptime","docs":null,"changelog":null,"pypi":"https://pypi.org/project/uptime/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["devops"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-28","last_verified":"2026-06-28","next_check":"2026-07-28","install_tag":null}}