is-admin-user 0.1.0__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.
- is_admin_user-0.1.0/LICENSE +21 -0
- is_admin_user-0.1.0/PKG-INFO +94 -0
- is_admin_user-0.1.0/README.md +68 -0
- is_admin_user-0.1.0/pyproject.toml +47 -0
- is_admin_user-0.1.0/setup.cfg +4 -0
- is_admin_user-0.1.0/src/is_admin_user/__init__.py +5 -0
- is_admin_user-0.1.0/src/is_admin_user/_core.py +44 -0
- is_admin_user-0.1.0/src/is_admin_user/py.typed +1 -0
- is_admin_user-0.1.0/src/is_admin_user.egg-info/PKG-INFO +94 -0
- is_admin_user-0.1.0/src/is_admin_user.egg-info/SOURCES.txt +11 -0
- is_admin_user-0.1.0/src/is_admin_user.egg-info/dependency_links.txt +1 -0
- is_admin_user-0.1.0/src/is_admin_user.egg-info/top_level.txt +1 -0
- is_admin_user-0.1.0/tests/test_is_admin_user.py +77 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 GGN_2015
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: is-admin-user
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Check whether the current Python process is running as an administrator or root user.
|
|
5
|
+
Author: GGN_2015
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Keywords: administrator,admin,root,privileges,windows,linux,macos
|
|
8
|
+
Classifier: Development Status :: 3 - Alpha
|
|
9
|
+
Classifier: Intended Audience :: Developers
|
|
10
|
+
Classifier: Operating System :: MacOS
|
|
11
|
+
Classifier: Operating System :: Microsoft :: Windows
|
|
12
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
21
|
+
Classifier: Typing :: Typed
|
|
22
|
+
Requires-Python: >=3.8
|
|
23
|
+
Description-Content-Type: text/markdown
|
|
24
|
+
License-File: LICENSE
|
|
25
|
+
Dynamic: license-file
|
|
26
|
+
|
|
27
|
+
# is-admin-user
|
|
28
|
+
|
|
29
|
+
Check whether the current Python process is running as an administrator.
|
|
30
|
+
|
|
31
|
+
`is-admin-user` is a tiny, dependency-free Python package that works across
|
|
32
|
+
Windows, Linux, and macOS. It exposes a programmable function interface for
|
|
33
|
+
checking whether the current process has administrative privileges.
|
|
34
|
+
|
|
35
|
+
## Installation
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
pip install is-admin-user
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
For local development:
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
pip install -e .
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Usage
|
|
48
|
+
|
|
49
|
+
```python
|
|
50
|
+
from is_admin_user import is_admin_user
|
|
51
|
+
|
|
52
|
+
if is_admin_user():
|
|
53
|
+
print("Running as administrator/root")
|
|
54
|
+
else:
|
|
55
|
+
print("Running as a standard user")
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
You can also use the shorter alias:
|
|
59
|
+
|
|
60
|
+
```python
|
|
61
|
+
from is_admin_user import is_admin
|
|
62
|
+
|
|
63
|
+
if is_admin():
|
|
64
|
+
print("Administrative privileges are available")
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## Platform behavior
|
|
68
|
+
|
|
69
|
+
- Windows: returns `True` when the current process token is running with
|
|
70
|
+
administrator privileges.
|
|
71
|
+
- Linux: returns `True` when the effective user ID is `0` (`root`).
|
|
72
|
+
- macOS: returns `True` when the effective user ID is `0` (`root`).
|
|
73
|
+
|
|
74
|
+
On Windows, an account that belongs to the Administrators group may still return
|
|
75
|
+
`False` if the Python process was not started with elevated privileges.
|
|
76
|
+
|
|
77
|
+
## API
|
|
78
|
+
|
|
79
|
+
### `is_admin_user() -> bool`
|
|
80
|
+
|
|
81
|
+
Returns `True` when the current Python process has administrator/root
|
|
82
|
+
privileges, otherwise returns `False`.
|
|
83
|
+
|
|
84
|
+
### `is_admin() -> bool`
|
|
85
|
+
|
|
86
|
+
Alias for `is_admin_user()`.
|
|
87
|
+
|
|
88
|
+
## Development
|
|
89
|
+
|
|
90
|
+
Run the test suite with:
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
python -m pytest
|
|
94
|
+
```
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# is-admin-user
|
|
2
|
+
|
|
3
|
+
Check whether the current Python process is running as an administrator.
|
|
4
|
+
|
|
5
|
+
`is-admin-user` is a tiny, dependency-free Python package that works across
|
|
6
|
+
Windows, Linux, and macOS. It exposes a programmable function interface for
|
|
7
|
+
checking whether the current process has administrative privileges.
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
pip install is-admin-user
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
For local development:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
pip install -e .
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
22
|
+
|
|
23
|
+
```python
|
|
24
|
+
from is_admin_user import is_admin_user
|
|
25
|
+
|
|
26
|
+
if is_admin_user():
|
|
27
|
+
print("Running as administrator/root")
|
|
28
|
+
else:
|
|
29
|
+
print("Running as a standard user")
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
You can also use the shorter alias:
|
|
33
|
+
|
|
34
|
+
```python
|
|
35
|
+
from is_admin_user import is_admin
|
|
36
|
+
|
|
37
|
+
if is_admin():
|
|
38
|
+
print("Administrative privileges are available")
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Platform behavior
|
|
42
|
+
|
|
43
|
+
- Windows: returns `True` when the current process token is running with
|
|
44
|
+
administrator privileges.
|
|
45
|
+
- Linux: returns `True` when the effective user ID is `0` (`root`).
|
|
46
|
+
- macOS: returns `True` when the effective user ID is `0` (`root`).
|
|
47
|
+
|
|
48
|
+
On Windows, an account that belongs to the Administrators group may still return
|
|
49
|
+
`False` if the Python process was not started with elevated privileges.
|
|
50
|
+
|
|
51
|
+
## API
|
|
52
|
+
|
|
53
|
+
### `is_admin_user() -> bool`
|
|
54
|
+
|
|
55
|
+
Returns `True` when the current Python process has administrator/root
|
|
56
|
+
privileges, otherwise returns `False`.
|
|
57
|
+
|
|
58
|
+
### `is_admin() -> bool`
|
|
59
|
+
|
|
60
|
+
Alias for `is_admin_user()`.
|
|
61
|
+
|
|
62
|
+
## Development
|
|
63
|
+
|
|
64
|
+
Run the test suite with:
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
python -m pytest
|
|
68
|
+
```
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=68"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "is-admin-user"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Check whether the current Python process is running as an administrator or root user."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.8"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
license-files = ["LICENSE"]
|
|
13
|
+
authors = [
|
|
14
|
+
{ name = "GGN_2015" }
|
|
15
|
+
]
|
|
16
|
+
keywords = [
|
|
17
|
+
"administrator",
|
|
18
|
+
"admin",
|
|
19
|
+
"root",
|
|
20
|
+
"privileges",
|
|
21
|
+
"windows",
|
|
22
|
+
"linux",
|
|
23
|
+
"macos"
|
|
24
|
+
]
|
|
25
|
+
classifiers = [
|
|
26
|
+
"Development Status :: 3 - Alpha",
|
|
27
|
+
"Intended Audience :: Developers",
|
|
28
|
+
"Operating System :: MacOS",
|
|
29
|
+
"Operating System :: Microsoft :: Windows",
|
|
30
|
+
"Operating System :: POSIX :: Linux",
|
|
31
|
+
"Programming Language :: Python :: 3",
|
|
32
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
33
|
+
"Programming Language :: Python :: 3.8",
|
|
34
|
+
"Programming Language :: Python :: 3.9",
|
|
35
|
+
"Programming Language :: Python :: 3.10",
|
|
36
|
+
"Programming Language :: Python :: 3.11",
|
|
37
|
+
"Programming Language :: Python :: 3.12",
|
|
38
|
+
"Programming Language :: Python :: 3.13",
|
|
39
|
+
"Typing :: Typed"
|
|
40
|
+
]
|
|
41
|
+
|
|
42
|
+
[tool.setuptools.packages.find]
|
|
43
|
+
where = ["src"]
|
|
44
|
+
|
|
45
|
+
[tool.pytest.ini_options]
|
|
46
|
+
testpaths = ["tests"]
|
|
47
|
+
pythonpath = ["src"]
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"""Cross-platform administrator/root privilege checks."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import ctypes
|
|
6
|
+
import os
|
|
7
|
+
import sys
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def is_admin_user() -> bool:
|
|
11
|
+
"""Return whether the current Python process has administrator privileges.
|
|
12
|
+
|
|
13
|
+
On Windows, this checks the current process token for administrator
|
|
14
|
+
privileges. On Linux and macOS, this checks whether the effective user ID is
|
|
15
|
+
0, which is the root user.
|
|
16
|
+
"""
|
|
17
|
+
if sys.platform == "win32":
|
|
18
|
+
return _is_windows_admin()
|
|
19
|
+
|
|
20
|
+
return _is_posix_root()
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def is_admin() -> bool:
|
|
24
|
+
"""Return whether the current Python process has administrator privileges."""
|
|
25
|
+
return is_admin_user()
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def _is_windows_admin() -> bool:
|
|
29
|
+
try:
|
|
30
|
+
return bool(ctypes.windll.shell32.IsUserAnAdmin())
|
|
31
|
+
except (AttributeError, OSError, ValueError):
|
|
32
|
+
return False
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def _is_posix_root() -> bool:
|
|
36
|
+
geteuid = getattr(os, "geteuid", None)
|
|
37
|
+
if callable(geteuid):
|
|
38
|
+
return geteuid() == 0
|
|
39
|
+
|
|
40
|
+
getuid = getattr(os, "getuid", None)
|
|
41
|
+
if callable(getuid):
|
|
42
|
+
return getuid() == 0
|
|
43
|
+
|
|
44
|
+
return False
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: is-admin-user
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Check whether the current Python process is running as an administrator or root user.
|
|
5
|
+
Author: GGN_2015
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Keywords: administrator,admin,root,privileges,windows,linux,macos
|
|
8
|
+
Classifier: Development Status :: 3 - Alpha
|
|
9
|
+
Classifier: Intended Audience :: Developers
|
|
10
|
+
Classifier: Operating System :: MacOS
|
|
11
|
+
Classifier: Operating System :: Microsoft :: Windows
|
|
12
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
21
|
+
Classifier: Typing :: Typed
|
|
22
|
+
Requires-Python: >=3.8
|
|
23
|
+
Description-Content-Type: text/markdown
|
|
24
|
+
License-File: LICENSE
|
|
25
|
+
Dynamic: license-file
|
|
26
|
+
|
|
27
|
+
# is-admin-user
|
|
28
|
+
|
|
29
|
+
Check whether the current Python process is running as an administrator.
|
|
30
|
+
|
|
31
|
+
`is-admin-user` is a tiny, dependency-free Python package that works across
|
|
32
|
+
Windows, Linux, and macOS. It exposes a programmable function interface for
|
|
33
|
+
checking whether the current process has administrative privileges.
|
|
34
|
+
|
|
35
|
+
## Installation
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
pip install is-admin-user
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
For local development:
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
pip install -e .
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Usage
|
|
48
|
+
|
|
49
|
+
```python
|
|
50
|
+
from is_admin_user import is_admin_user
|
|
51
|
+
|
|
52
|
+
if is_admin_user():
|
|
53
|
+
print("Running as administrator/root")
|
|
54
|
+
else:
|
|
55
|
+
print("Running as a standard user")
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
You can also use the shorter alias:
|
|
59
|
+
|
|
60
|
+
```python
|
|
61
|
+
from is_admin_user import is_admin
|
|
62
|
+
|
|
63
|
+
if is_admin():
|
|
64
|
+
print("Administrative privileges are available")
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## Platform behavior
|
|
68
|
+
|
|
69
|
+
- Windows: returns `True` when the current process token is running with
|
|
70
|
+
administrator privileges.
|
|
71
|
+
- Linux: returns `True` when the effective user ID is `0` (`root`).
|
|
72
|
+
- macOS: returns `True` when the effective user ID is `0` (`root`).
|
|
73
|
+
|
|
74
|
+
On Windows, an account that belongs to the Administrators group may still return
|
|
75
|
+
`False` if the Python process was not started with elevated privileges.
|
|
76
|
+
|
|
77
|
+
## API
|
|
78
|
+
|
|
79
|
+
### `is_admin_user() -> bool`
|
|
80
|
+
|
|
81
|
+
Returns `True` when the current Python process has administrator/root
|
|
82
|
+
privileges, otherwise returns `False`.
|
|
83
|
+
|
|
84
|
+
### `is_admin() -> bool`
|
|
85
|
+
|
|
86
|
+
Alias for `is_admin_user()`.
|
|
87
|
+
|
|
88
|
+
## Development
|
|
89
|
+
|
|
90
|
+
Run the test suite with:
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
python -m pytest
|
|
94
|
+
```
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
src/is_admin_user/__init__.py
|
|
5
|
+
src/is_admin_user/_core.py
|
|
6
|
+
src/is_admin_user/py.typed
|
|
7
|
+
src/is_admin_user.egg-info/PKG-INFO
|
|
8
|
+
src/is_admin_user.egg-info/SOURCES.txt
|
|
9
|
+
src/is_admin_user.egg-info/dependency_links.txt
|
|
10
|
+
src/is_admin_user.egg-info/top_level.txt
|
|
11
|
+
tests/test_is_admin_user.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
is_admin_user
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from is_admin_user import is_admin, is_admin_user
|
|
4
|
+
from is_admin_user import _core
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class _FakeShell32:
|
|
8
|
+
def __init__(self, result: int) -> None:
|
|
9
|
+
self._result = result
|
|
10
|
+
|
|
11
|
+
def IsUserAnAdmin(self) -> int:
|
|
12
|
+
return self._result
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class _FailingShell32:
|
|
16
|
+
def IsUserAnAdmin(self) -> int:
|
|
17
|
+
raise OSError("administrator check failed")
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class _FakeWindll:
|
|
21
|
+
def __init__(self, result: int) -> None:
|
|
22
|
+
self.shell32 = _FakeShell32(result)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def test_returns_true_for_windows_admin(monkeypatch):
|
|
26
|
+
monkeypatch.setattr(_core.sys, "platform", "win32")
|
|
27
|
+
monkeypatch.setattr(_core.ctypes, "windll", _FakeWindll(1), raising=False)
|
|
28
|
+
|
|
29
|
+
assert is_admin_user() is True
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def test_returns_false_for_windows_standard_user(monkeypatch):
|
|
33
|
+
monkeypatch.setattr(_core.sys, "platform", "win32")
|
|
34
|
+
monkeypatch.setattr(_core.ctypes, "windll", _FakeWindll(0), raising=False)
|
|
35
|
+
|
|
36
|
+
assert is_admin_user() is False
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def test_returns_false_when_windows_check_fails(monkeypatch):
|
|
40
|
+
monkeypatch.setattr(_core.sys, "platform", "win32")
|
|
41
|
+
monkeypatch.setattr(
|
|
42
|
+
_core.ctypes,
|
|
43
|
+
"windll",
|
|
44
|
+
type("_FailingWindll", (), {"shell32": _FailingShell32()})(),
|
|
45
|
+
raising=False,
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
assert is_admin_user() is False
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def test_returns_true_for_posix_root(monkeypatch):
|
|
52
|
+
monkeypatch.setattr(_core.sys, "platform", "linux")
|
|
53
|
+
monkeypatch.setattr(_core.os, "geteuid", lambda: 0, raising=False)
|
|
54
|
+
|
|
55
|
+
assert is_admin_user() is True
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def test_returns_false_for_posix_standard_user(monkeypatch):
|
|
59
|
+
monkeypatch.setattr(_core.sys, "platform", "darwin")
|
|
60
|
+
monkeypatch.setattr(_core.os, "geteuid", lambda: 501, raising=False)
|
|
61
|
+
|
|
62
|
+
assert is_admin_user() is False
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def test_posix_falls_back_to_real_user_id(monkeypatch):
|
|
66
|
+
monkeypatch.setattr(_core.sys, "platform", "linux")
|
|
67
|
+
monkeypatch.delattr(_core.os, "geteuid", raising=False)
|
|
68
|
+
monkeypatch.setattr(_core.os, "getuid", lambda: 0, raising=False)
|
|
69
|
+
|
|
70
|
+
assert is_admin_user() is True
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def test_is_admin_alias(monkeypatch):
|
|
74
|
+
monkeypatch.setattr(_core.sys, "platform", "linux")
|
|
75
|
+
monkeypatch.setattr(_core.os, "geteuid", lambda: 0, raising=False)
|
|
76
|
+
|
|
77
|
+
assert is_admin() is True
|