system-parse-lib 0.0.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,27 @@
1
+ # Byte-compiled / cache
2
+ __pycache__/
3
+ *.py[cod]
4
+
5
+ # Virtual environments
6
+ .venv/
7
+ venv/
8
+ env/
9
+
10
+ # Packaging / build
11
+ build/
12
+ dist/
13
+ *.egg-info/
14
+ .eggs/
15
+
16
+ # Testing / tooling
17
+ .pytest_cache/
18
+ .coverage
19
+ htmlcov/
20
+ .mypy_cache/
21
+ .ruff_cache/
22
+
23
+ # Editors / OS
24
+ .vscode/
25
+ .idea/
26
+ *.swp
27
+ .DS_Store
@@ -0,0 +1,28 @@
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2026, Black Mesa Studios
4
+
5
+ Redistribution and use in source and binary forms, with or without
6
+ modification, are permitted provided that the following conditions are met:
7
+
8
+ 1. Redistributions of source code must retain the above copyright notice, this
9
+ list of conditions and the following disclaimer.
10
+
11
+ 2. Redistributions in binary form must reproduce the above copyright notice,
12
+ this list of conditions and the following disclaimer in the documentation
13
+ and/or other materials provided with the distribution.
14
+
15
+ 3. Neither the name of the copyright holder nor the names of its
16
+ contributors may be used to endorse or promote products derived from
17
+ this software without specific prior written permission.
18
+
19
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,97 @@
1
+ Metadata-Version: 2.5
2
+ Name: system-parse-lib
3
+ Version: 0.0.1
4
+ Summary: A for now small python library used for getting information about the system and hardware on linux. Dependency free! (well, not really)
5
+ Project-URL: Homepage, https://github.com/black-mesa-studios/system-parse-lib
6
+ Project-URL: Issues, https://github.com/black-mesa-studios/system-parse-lib/issues/
7
+ Author-email: Artem Ivashyn <artem4ik15082013@gmail.com>
8
+ License-Expression: BSD-3-Clause
9
+ License-File: LICENSE
10
+ Classifier: Operating System :: OS Independent
11
+ Classifier: Programming Language :: Python :: 3
12
+ Requires-Python: >=3.9
13
+ Description-Content-Type: text/markdown
14
+
15
+ # system-parse-lib
16
+
17
+ A small Python library for reading system information on Linux: OS name, kernel version, uptime, desktop environment, session type, CPU and GPU models and vendors, and basic user details. One module, no third-party dependencies, and no external commands: everything is read from `/etc`, `/proc` and `/sys`.
18
+
19
+ ![License](https://img.shields.io/badge/license-BSD--3--Clause-blue)
20
+ ![Python](https://img.shields.io/badge/python-3-yellow)
21
+ ![Platform](https://img.shields.io/badge/platform-Linux-lightgrey)
22
+
23
+ **Documentation:** https://black-mesa-studios.github.io/system-parse-lib/
24
+
25
+ ## Features
26
+
27
+ - Distro ID and pretty name, read from `/etc/os-release`
28
+ - Current username and hostname
29
+ - Kernel version and uptime (as seconds or readable text)
30
+ - Desktop environment, from `XDG_CURRENT_DESKTOP` or `DESKTOP_SESSION`
31
+ - Session type (Wayland, X11, tty), from `XDG_SESSION_TYPE`
32
+ - CPU model, from `/proc/cpuinfo`
33
+ - GPUs with vendor, model and kernel driver, from `/sys/bus/pci/devices`
34
+
35
+ ## Requirements
36
+
37
+ - Linux
38
+ - Python 3.10 or newer
39
+ - Optional: a `pci.ids` file (from the `hwdata` or `pciids` package) so `get_gpu()` can show real model names
40
+
41
+ ## Installation
42
+
43
+ There's no package yet. Clone the repo and copy `systemparselib.py` next to your script:
44
+
45
+ ```
46
+ git clone https://github.com/black-mesa-studios/system-parse-lib.git
47
+ cp system-parse-lib/systemparselib.py ./
48
+ ```
49
+
50
+ ## Usage
51
+
52
+ ```python
53
+ import systemparselib
54
+
55
+ sysinfo = systemparselib.Main()
56
+
57
+ print(sysinfo.get_pretty_name()) # e.g. Arch Linux
58
+ print(sysinfo.get_de()) # e.g. KDE
59
+ print(sysinfo.get_session_type()) # e.g. wayland
60
+ print(sysinfo.get_kernel_version()) # e.g. 6.11.2-arch1-1
61
+ print(sysinfo.get_pretty_uptime()) # e.g. up 3 hours, 12 minutes
62
+ print(sysinfo.get_cpu()) # e.g. AMD Ryzen 5 5600X 6-Core Processor
63
+ print(sysinfo.get_gpu()) # e.g. [GPU(vendor='AMD', model='...', driver='amdgpu')]
64
+ print(f"{sysinfo.get_username()}@{sysinfo.get_hostname()}")
65
+ ```
66
+
67
+ ## Functions
68
+
69
+ All functions live on the `Main` class.
70
+
71
+ | Function | Returns | Description |
72
+ | --- | --- | --- |
73
+ | `get_distro_id()` | `str \| None` | Short distro ID, like `arch` or `ubuntu` |
74
+ | `get_pretty_name()` | `str \| None` | Human-readable OS name |
75
+ | `get_username()` | `str` | Current user's name |
76
+ | `get_hostname()` | `str` | Machine hostname |
77
+ | `get_de()` | `str \| None` | Desktop environment, or `None` if none is set |
78
+ | `get_session_type()` | `str` | Session type from `XDG_SESSION_TYPE`, like `wayland` or `x11` |
79
+ | `get_kernel_version()` | `str` | Kernel release, like `6.11.2-arch1-1` |
80
+ | `get_uptime_seconds()` | `int \| None` | Seconds since boot |
81
+ | `get_pretty_uptime()` | `str \| None` | Readable uptime, like `up 3 hours, 12 minutes` |
82
+ | `get_cpu()` | `str \| None` | CPU model name |
83
+ | `get_gpu()` | `list[GPU]` | One `GPU(vendor, model, driver)` per display device |
84
+
85
+ Full details are in the [documentation](https://black-mesa-studios.github.io/system-parse-lib/).
86
+
87
+ ## Testing
88
+
89
+ `test.py` prints the output of every function so you can check it on your machine:
90
+
91
+ ```
92
+ python3 test.py
93
+ ```
94
+
95
+ ## License
96
+
97
+ Released under the [BSD 3-Clause License](LICENSE). Copyright 2026 Black Mesa Studios.
@@ -0,0 +1,83 @@
1
+ # system-parse-lib
2
+
3
+ A small Python library for reading system information on Linux: OS name, kernel version, uptime, desktop environment, session type, CPU and GPU models and vendors, and basic user details. One module, no third-party dependencies, and no external commands: everything is read from `/etc`, `/proc` and `/sys`.
4
+
5
+ ![License](https://img.shields.io/badge/license-BSD--3--Clause-blue)
6
+ ![Python](https://img.shields.io/badge/python-3-yellow)
7
+ ![Platform](https://img.shields.io/badge/platform-Linux-lightgrey)
8
+
9
+ **Documentation:** https://black-mesa-studios.github.io/system-parse-lib/
10
+
11
+ ## Features
12
+
13
+ - Distro ID and pretty name, read from `/etc/os-release`
14
+ - Current username and hostname
15
+ - Kernel version and uptime (as seconds or readable text)
16
+ - Desktop environment, from `XDG_CURRENT_DESKTOP` or `DESKTOP_SESSION`
17
+ - Session type (Wayland, X11, tty), from `XDG_SESSION_TYPE`
18
+ - CPU model, from `/proc/cpuinfo`
19
+ - GPUs with vendor, model and kernel driver, from `/sys/bus/pci/devices`
20
+
21
+ ## Requirements
22
+
23
+ - Linux
24
+ - Python 3.10 or newer
25
+ - Optional: a `pci.ids` file (from the `hwdata` or `pciids` package) so `get_gpu()` can show real model names
26
+
27
+ ## Installation
28
+
29
+ There's no package yet. Clone the repo and copy `systemparselib.py` next to your script:
30
+
31
+ ```
32
+ git clone https://github.com/black-mesa-studios/system-parse-lib.git
33
+ cp system-parse-lib/systemparselib.py ./
34
+ ```
35
+
36
+ ## Usage
37
+
38
+ ```python
39
+ import systemparselib
40
+
41
+ sysinfo = systemparselib.Main()
42
+
43
+ print(sysinfo.get_pretty_name()) # e.g. Arch Linux
44
+ print(sysinfo.get_de()) # e.g. KDE
45
+ print(sysinfo.get_session_type()) # e.g. wayland
46
+ print(sysinfo.get_kernel_version()) # e.g. 6.11.2-arch1-1
47
+ print(sysinfo.get_pretty_uptime()) # e.g. up 3 hours, 12 minutes
48
+ print(sysinfo.get_cpu()) # e.g. AMD Ryzen 5 5600X 6-Core Processor
49
+ print(sysinfo.get_gpu()) # e.g. [GPU(vendor='AMD', model='...', driver='amdgpu')]
50
+ print(f"{sysinfo.get_username()}@{sysinfo.get_hostname()}")
51
+ ```
52
+
53
+ ## Functions
54
+
55
+ All functions live on the `Main` class.
56
+
57
+ | Function | Returns | Description |
58
+ | --- | --- | --- |
59
+ | `get_distro_id()` | `str \| None` | Short distro ID, like `arch` or `ubuntu` |
60
+ | `get_pretty_name()` | `str \| None` | Human-readable OS name |
61
+ | `get_username()` | `str` | Current user's name |
62
+ | `get_hostname()` | `str` | Machine hostname |
63
+ | `get_de()` | `str \| None` | Desktop environment, or `None` if none is set |
64
+ | `get_session_type()` | `str` | Session type from `XDG_SESSION_TYPE`, like `wayland` or `x11` |
65
+ | `get_kernel_version()` | `str` | Kernel release, like `6.11.2-arch1-1` |
66
+ | `get_uptime_seconds()` | `int \| None` | Seconds since boot |
67
+ | `get_pretty_uptime()` | `str \| None` | Readable uptime, like `up 3 hours, 12 minutes` |
68
+ | `get_cpu()` | `str \| None` | CPU model name |
69
+ | `get_gpu()` | `list[GPU]` | One `GPU(vendor, model, driver)` per display device |
70
+
71
+ Full details are in the [documentation](https://black-mesa-studios.github.io/system-parse-lib/).
72
+
73
+ ## Testing
74
+
75
+ `test.py` prints the output of every function so you can check it on your machine:
76
+
77
+ ```
78
+ python3 test.py
79
+ ```
80
+
81
+ ## License
82
+
83
+ Released under the [BSD 3-Clause License](LICENSE). Copyright 2026 Black Mesa Studios.
@@ -0,0 +1,146 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
6
+ <title>system-parse-lib: Documentation</title>
7
+ <style>
8
+ :root{--bg:#f6f6f4;--fg:#1b1b1f;--mut:#62626b;--line:#d8d8d4;--acc:#7a3fd1;--code:#ebebe7;--side:#efefec;
9
+ box-sizing:border-box;padding-top:env(safe-area-inset-top,0px);padding-bottom:env(safe-area-inset-bottom,0px)}
10
+ @media(prefers-color-scheme:dark){:root:not([data-theme="light"]){--bg:#15151a;--fg:#e6e6ea;--mut:#9a9aa5;--line:#2c2c35;--acc:#b48cff;--code:#1f1f27;--side:#1a1a20}}
11
+ :root[data-theme="dark"]{--bg:#15151a;--fg:#e6e6ea;--mut:#9a9aa5;--line:#2c2c35;--acc:#b48cff;--code:#1f1f27;--side:#1a1a20}
12
+ html{scroll-padding-top:env(safe-area-inset-top,0px);scroll-behavior:smooth}
13
+ *{box-sizing:border-box}
14
+ body{margin:0;background:var(--bg);color:var(--fg);font:16px/1.65 system-ui,-apple-system,"Segoe UI",sans-serif;display:flex;min-height:100vh}
15
+ a{color:var(--acc)}
16
+ nav{width:250px;flex:none;background:var(--side);border-right:1px solid var(--line);padding:24px 20px;position:sticky;top:0;height:100vh;overflow-y:auto}
17
+ nav h4{margin:22px 0 6px;font-size:.95rem}
18
+ nav h4:first-child{margin-top:0}
19
+ nav ul{list-style:none;margin:0;padding:0 0 0 4px}
20
+ nav li{margin:3px 0}
21
+ nav a{text-decoration:none;color:var(--mut)}
22
+ nav a:hover{color:var(--acc);text-decoration:underline}
23
+ main{flex:1;min-width:0;max-width:860px;padding:40px 48px 80px}
24
+ h1{font-size:2.1rem;margin:0 0 4px}
25
+ h1 span{color:var(--acc)}
26
+ h2{font-size:1.4rem;margin:44px 0 12px;padding-top:8px}
27
+ h3{font-size:1.1rem;margin:30px 0 6px}
28
+ hr{border:0;border-top:1px solid var(--line);margin:22px 0}
29
+ code,pre{font-family:ui-monospace,"JetBrains Mono",Menlo,Consolas,monospace;font-size:.88em}
30
+ code{background:var(--code);padding:1px 6px;border-radius:4px}
31
+ pre{background:var(--code);border:1px solid var(--line);border-radius:6px;padding:14px 16px;overflow-x:auto;line-height:1.5}
32
+ pre code{background:none;padding:0}
33
+ .t{overflow-x:auto}
34
+ table{border-collapse:collapse;width:100%;font-size:.95rem}
35
+ th,td{text-align:left;padding:8px 12px;border:1px solid var(--line);vertical-align:top}
36
+ th{background:var(--side)}
37
+ .tag{color:var(--mut);font-size:.9rem}
38
+ footer{margin-top:60px;color:var(--mut);font-size:.9rem}
39
+ @media(max-width:760px){body{display:block}nav{position:static;width:auto;height:auto;border-right:0;border-bottom:1px solid var(--line)}main{padding:24px 18px 60px}}
40
+ </style>
41
+ </head>
42
+ <body>
43
+ <nav>
44
+ <h4>About system-parse-lib</h4>
45
+ <ul><li><a href="#home">Home</a></li><li><a href="#requirements">Requirements</a></li></ul>
46
+ <h4>Getting started</h4>
47
+ <ul><li><a href="#install">Installation</a></li><li><a href="#quickstart">Quick start</a></li></ul>
48
+ <h4>Reference</h4>
49
+ <ul><li><a href="#overview">Functions</a></li><li><a href="#distro">Distro</a></li><li><a href="#user">User &amp; host</a></li><li><a href="#desktop">Desktop &amp; session</a></li><li><a href="#system">System</a></li><li><a href="#hardware">Hardware</a></li></ul>
50
+ <h4>Source</h4>
51
+ <ul><li><a href="https://github.com/black-mesa-studios/system-parse-lib">GitHub repository</a></li><li><a href="https://github.com/black-mesa-studios/system-parse-lib/blob/main/LICENSE">License (BSD-3-Clause)</a></li></ul>
52
+ </nav>
53
+ <main>
54
+ <h1 id="home"><span>[</span>system-parse-lib<span>]</span></h1>
55
+ <p class="tag">A small Python library for reading system information on Linux.</p>
56
+ <hr>
57
+ <p>system-parse-lib reads your OS name, kernel version, uptime, desktop environment, session type, CPU and GPU models and vendors, and basic user details, and hands them back as plain Python values. It's one module, <code>systemparselib.py</code>. It has no third-party dependencies and doesn't call any external commands: everything is read straight from <code>/etc</code>, <code>/proc</code> and <code>/sys</code>.</p>
58
+
59
+ <h2 id="requirements">Requirements</h2>
60
+ <ul>
61
+ <li>Linux</li>
62
+ <li>Python 3.10 or newer</li>
63
+ <li>Optional: a <code>pci.ids</code> file (from the <code>hwdata</code> or <code>pciids</code> package) so <code>get_gpu()</code> can show real model names</li>
64
+ </ul>
65
+
66
+ <h2 id="install">Installation</h2>
67
+ <p>There's no package yet. Clone the repository and copy <code>systemparselib.py</code> next to your script:</p>
68
+ <pre><code>git clone https://github.com/black-mesa-studios/system-parse-lib.git
69
+ cp system-parse-lib/systemparselib.py ./</code></pre>
70
+
71
+ <h2 id="quickstart">Quick start</h2>
72
+ <pre><code>import systemparselib
73
+
74
+ sysinfo = systemparselib.Main()
75
+
76
+ print(sysinfo.get_pretty_name()) # e.g. Arch Linux
77
+ print(sysinfo.get_de()) # e.g. KDE
78
+ print(sysinfo.get_session_type()) # e.g. wayland
79
+ print(sysinfo.get_kernel_version()) # e.g. 6.11.2-arch1-1
80
+ print(sysinfo.get_pretty_uptime()) # e.g. up 3 hours, 12 minutes
81
+ print(sysinfo.get_gpu()) # [GPU(vendor='AMD', model='...', driver='amdgpu')]
82
+ print(f"{sysinfo.get_username()}@{sysinfo.get_hostname()}")</code></pre>
83
+
84
+ <h2 id="overview">Functions</h2>
85
+ <p>Everything lives on the <code>Main</code> class. Creating an instance reads <code>/etc/os-release</code> once; each method then reads its own data when called.</p>
86
+ <div class="t"><table>
87
+ <tr><th>Method</th><th>Returns</th><th>Source</th></tr>
88
+ <tr><td><code>get_distro_id()</code></td><td><code>str | None</code></td><td><code>ID</code> in /etc/os-release</td></tr>
89
+ <tr><td><code>get_pretty_name()</code></td><td><code>str | None</code></td><td><code>PRETTY_NAME</code> in /etc/os-release</td></tr>
90
+ <tr><td><code>get_username()</code></td><td><code>str</code></td><td><code>getpass.getuser()</code></td></tr>
91
+ <tr><td><code>get_hostname()</code></td><td><code>str</code></td><td><code>socket.gethostname()</code></td></tr>
92
+ <tr><td><code>get_de()</code></td><td><code>str | None</code></td><td>Environment variables</td></tr>
93
+ <tr><td><code>get_session_type()</code></td><td><code>str</code></td><td><code>XDG_SESSION_TYPE</code></td></tr>
94
+ <tr><td><code>get_kernel_version()</code></td><td><code>str</code></td><td><code>os.uname().release</code></td></tr>
95
+ <tr><td><code>get_uptime_seconds()</code></td><td><code>int | None</code></td><td><code>/proc/uptime</code></td></tr>
96
+ <tr><td><code>get_pretty_uptime()</code></td><td><code>str | None</code></td><td><code>/proc/uptime</code></td></tr>
97
+ <tr><td><code>get_cpu()</code></td><td><code>str | None</code></td><td><code>/proc/cpuinfo</code></td></tr>
98
+ <tr><td><code>get_gpu()</code></td><td><code>list[GPU]</code></td><td><code>/sys/bus/pci/devices</code></td></tr>
99
+ </table></div>
100
+
101
+ <h2 id="distro">Distro</h2>
102
+ <h3><code>get_distro_id()</code></h3>
103
+ <p>Returns the distro's short ID with quotes removed, such as <code>arch</code>, <code>ubuntu</code> or <code>fedora</code>. Useful for picking a package manager.</p>
104
+ <h3><code>get_pretty_name()</code></h3>
105
+ <p>Returns the human-readable OS name, such as <code>Arch Linux</code> or <code>Ubuntu 24.04 LTS</code>.</p>
106
+ <p class="tag">Both return <code>None</code> if <code>/etc/os-release</code> doesn't exist.</p>
107
+
108
+ <h2 id="user">User &amp; host</h2>
109
+ <h3><code>get_username()</code></h3>
110
+ <p>Returns the name of the current user.</p>
111
+ <h3><code>get_hostname()</code></h3>
112
+ <p>Returns the machine's hostname.</p>
113
+
114
+ <h2 id="desktop">Desktop &amp; session</h2>
115
+ <h3><code>get_de()</code></h3>
116
+ <p>Returns the desktop environment from <code>XDG_CURRENT_DESKTOP</code>, falling back to <code>DESKTOP_SESSION</code>. Returns <code>None</code> when neither is set, for example over SSH or in a TTY.</p>
117
+ <h3><code>get_session_type()</code></h3>
118
+ <p>Returns the session type from <code>XDG_SESSION_TYPE</code>, such as <code>wayland</code>, <code>x11</code> or <code>tty</code>. If the variable isn't set, it returns the string <code>"Could not retrieve session type."</code>.</p>
119
+
120
+ <h2 id="system">System</h2>
121
+ <h3><code>get_kernel_version()</code></h3>
122
+ <p>Returns the kernel release string, such as <code>6.11.2-arch1-1</code>.</p>
123
+ <h3><code>get_uptime_seconds()</code></h3>
124
+ <p>Returns the time since boot in whole seconds, read from <code>/proc/uptime</code>. Returns <code>None</code> if it can't be read.</p>
125
+ <h3><code>get_pretty_uptime()</code></h3>
126
+ <p>Returns the uptime as readable text, such as <code>up 3 hours, 12 minutes</code> or <code>up 2 days, 1 hour, 5 minutes</code>. Returns <code>None</code> if the uptime can't be read.</p>
127
+
128
+ <h2 id="hardware">Hardware</h2>
129
+ <h3><code>get_cpu()</code></h3>
130
+ <p>Returns the CPU model name from <code>/proc/cpuinfo</code>, such as <code>AMD Ryzen 5 5600X 6-Core Processor</code>. Returns <code>None</code> if the file doesn't exist, and an empty string if it has no <code>model name</code> line (some ARM systems).</p>
131
+ <h3><code>get_gpu()</code></h3>
132
+ <p>Returns a list with one <code>GPU</code> object per display device found in <code>/sys/bus/pci/devices</code>. It returns an empty list if there are none.</p>
133
+ <div class="t"><table>
134
+ <tr><th>Field</th><th>Type</th><th>Description</th></tr>
135
+ <tr><td><code>vendor</code></td><td><code>str</code></td><td><code>NVIDIA</code>, <code>AMD</code> or <code>Intel</code>. Any other vendor is shown as its raw PCI vendor ID, like <code>1234</code>.</td></tr>
136
+ <tr><td><code>model</code></td><td><code>str</code></td><td>Model name from <code>pci.ids</code>. Falls back to <code>Device &lt;id&gt;</code> if no <code>pci.ids</code> file is found.</td></tr>
137
+ <tr><td><code>driver</code></td><td><code>str | None</code></td><td>Kernel driver in use, such as <code>amdgpu</code> or <code>nvidia</code>, or <code>None</code> if none is bound.</td></tr>
138
+ </table></div>
139
+ <pre><code>[GPU(vendor='NVIDIA', model='GeForce GTX 1650', driver='nvidia')]</code></pre>
140
+ <p>For a plain dictionary, use <code>dataclasses.asdict(gpu)</code>.</p>
141
+
142
+ <hr>
143
+ <footer>system-parse-lib is released under the BSD 3-Clause License. Copyright 2026 Black Mesa Studios. <a href="https://github.com/black-mesa-studios/system-parse-lib">View on GitHub</a>.</footer>
144
+ </main>
145
+ </body>
146
+ </html>
@@ -0,0 +1,26 @@
1
+ [build-system]
2
+ requires = ["hatchling >= 1.26"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "system-parse-lib"
7
+ version = "0.0.1"
8
+ authors = [
9
+ { name="Artem Ivashyn", email="artem4ik15082013@gmail.com" },
10
+ ]
11
+ description = "A for now small python library used for getting information about the system and hardware on linux. Dependency free! (well, not really)"
12
+ readme = "README.md"
13
+ requires-python = ">=3.9"
14
+ classifiers = [
15
+ "Programming Language :: Python :: 3",
16
+ "Operating System :: OS Independent",
17
+ ]
18
+ license = "BSD-3-Clause"
19
+ license-files = ["LICEN[CS]E*"]
20
+
21
+ [project.urls]
22
+ Homepage = "https://github.com/black-mesa-studios/system-parse-lib"
23
+ Issues = "https://github.com/black-mesa-studios/system-parse-lib/issues/"
24
+
25
+ [tool.hatch.build.targets.wheel]
26
+ packages = ["src/system-parse-lib"]
@@ -0,0 +1,171 @@
1
+ import os, subprocess, getpass, socket
2
+ from dataclasses import dataclass, asdict
3
+ from functools import cache
4
+
5
+ PCI_DEVICES = "/sys/bus/pci/devices"
6
+ PCI_IDS_PATHS = (
7
+ "/usr/share/hwdata/pci.ids",
8
+ "/usr/share/misc/pci.ids",
9
+ "/usr/share/pci.ids",
10
+ )
11
+ VENDORS = {"10de": "NVIDIA", "1002": "AMD", "8086": "Intel"}
12
+
13
+ @dataclass
14
+ class GPU:
15
+ vendor: str
16
+ model: str
17
+ driver: str | None = None
18
+
19
+ def _read_sysfs(path):
20
+ try:
21
+ with open(path) as f:
22
+ return f.read().strip()
23
+ except OSError:
24
+ return None
25
+
26
+ @cache
27
+ def _load_pci_ids():
28
+ """Returns {(vendor_id, device_id): name}"""
29
+ names = {}
30
+ for path in PCI_IDS_PATHS:
31
+ try:
32
+ f = open(path, encoding="utf-8", errors="replace")
33
+ except OSError:
34
+ continue
35
+ with f:
36
+ vendor = None
37
+ for line in f:
38
+ if line.startswith("#") or not line.strip():
39
+ continue
40
+ if line.startswith("C "):
41
+ break
42
+ if line.startswith("\t\t"):
43
+ continue
44
+ if line.startswith("\t"):
45
+ dev_id, _, name = line.strip().partition(" ")
46
+ if vendor:
47
+ names[(vendor, dev_id)] = name
48
+ else:
49
+ vendor = line.split()[0]
50
+ break
51
+ return names
52
+
53
+ class Main():
54
+ def __init__(self):
55
+ def get_distro_info():
56
+ if not os.path.exists('/etc/os-release'):
57
+ return None
58
+
59
+ info = {}
60
+
61
+ with open('/etc/os-release') as f:
62
+ for line in f:
63
+ if '=' in line:
64
+ key, value = line.strip().split('=', 1)
65
+ info[key] = value
66
+ return info
67
+ self.distro_info = get_distro_info()
68
+
69
+ def get_distro_id(self):
70
+ if not self.distro_info:
71
+ return None
72
+ return self.distro_info.get('ID', '').strip('"')
73
+
74
+ def get_username(self):
75
+ username = getpass.getuser()
76
+ return username
77
+
78
+ def get_kernel_version(self):
79
+ kernel_version = os.uname().release
80
+ return kernel_version
81
+
82
+ def get_uptime_seconds(self):
83
+ try:
84
+ with open("/proc/uptime") as f:
85
+ return int(float(f.read().split()[0]))
86
+ except (OSError, ValueError, IndexError):
87
+ return None
88
+
89
+ def get_pretty_uptime(self):
90
+ seconds = self.get_uptime_seconds()
91
+ if seconds is None:
92
+ return None
93
+
94
+ days, rem = divmod(seconds, 86400)
95
+ hours, rem = divmod(rem, 3600)
96
+ minutes = rem // 60
97
+
98
+ parts = []
99
+ if days:
100
+ parts.append(f"{days} day{'s' if days != 1 else ''}")
101
+ if hours:
102
+ parts.append(f"{hours} hour{'s' if hours != 1 else ''}")
103
+ if minutes or not parts:
104
+ parts.append(f"{minutes} minute{'s' if minutes != 1 else ''}")
105
+ return "up " + ", ".join(parts)
106
+
107
+ def get_session_type(self):
108
+ session_type = os.getenv('XDG_SESSION_TYPE')
109
+ if session_type:
110
+ return session_type
111
+ else:
112
+ return "Could not retrieve session type."
113
+
114
+ def get_hostname(self):
115
+ hostname = socket.gethostname()
116
+ return hostname
117
+
118
+ def get_pretty_name(self):
119
+ if not self.distro_info:
120
+ return None
121
+ return self.distro_info.get('PRETTY_NAME', '').strip('"')
122
+
123
+ def get_de(self):
124
+ desktop = os.environ.get("XDG_CURRENT_DESKTOP") or os.environ.get("DESKTOP_SESSION")
125
+ if desktop:
126
+ return desktop
127
+ return None
128
+
129
+ def get_cpu(self):
130
+ cpu = ""
131
+ try:
132
+ with open("/proc/cpuinfo", "r", encoding="utf-8") as file:
133
+ for line in file:
134
+ if "model name" in line.lower():
135
+ cpu = line.split(":", 1)[-1].strip()
136
+ break
137
+ except FileNotFoundError:
138
+ return None
139
+ return cpu
140
+
141
+ def get_gpu(self):
142
+ gpus = []
143
+ try:
144
+ devices = sorted(os.listdir(PCI_DEVICES))
145
+ except OSError:
146
+ return gpus
147
+
148
+ ids = _load_pci_ids()
149
+
150
+ for dev in devices:
151
+ base = os.path.join(PCI_DEVICES, dev)
152
+
153
+ pci_class = _read_sysfs(base + "/class")
154
+ if not pci_class or not pci_class.startswith("0x03"):
155
+ continue
156
+
157
+ vendor_id = (_read_sysfs(base + "/vendor") or "")[2:]
158
+ device_id = (_read_sysfs(base + "/device") or "")[2:]
159
+
160
+ vendor = VENDORS.get(vendor_id, vendor_id)
161
+
162
+ name = ids.get((vendor_id, device_id), f"Device {device_id}")
163
+ model = name.split('[')[-1].split(']')[0] if '[' in name else name
164
+
165
+ driver = None
166
+ if os.path.exists(base + "/driver"):
167
+ driver = os.path.basename(os.path.realpath(base + "/driver"))
168
+
169
+ gpus.append(GPU(vendor=vendor, model=model, driver=driver))
170
+
171
+ return gpus
@@ -0,0 +1,13 @@
1
+ import systemparselib
2
+
3
+ test = systemparselib.Main()
4
+
5
+ print(test.get_distro_id())
6
+ print(test.get_pretty_name())
7
+ print(test.get_de())
8
+ print(test.get_cpu())
9
+ print(test.get_gpu())
10
+ print(f"{test.get_username()}@{test.get_hostname()}")
11
+ print(test.get_kernel_version())
12
+ print(test.get_pretty_uptime())
13
+ print(test.get_session_type())