A cross-platform command launcher for administrator privileges.
Project description
py-admin-launch
A cross-platform Python command/helper to launch a specified program with administrator privileges.
Strategy
- Linux desktop:
pkexecfor polkit GUI authentication, falling back tosudowhenpkexecis not available. GUI session variables such asDISPLAY,XAUTHORITY,WAYLAND_DISPLAY,XDG_RUNTIME_DIR, andDBUS_SESSION_BUS_ADDRESSare passed explicitly so desktop apps can still reach the current display after elevation. - Windows:
ShellExecuteW(..., "runas", ...). - macOS:
osascript+with administrator privileges, falling back tosudowhenosascriptis not available.
If the current process is already administrator/root, the command is launched directly as the current user.
CLI
Run from source:
python -m py_admin_launch -- your-command arg1 arg2
After installing the package:
py-admin-launch -- your-command arg1 arg2
Useful options:
py-admin-launch --cwd /path/to/workdir -- your-command arg1 arg2
py-admin-launch --no-wait -- your-command arg1 arg2
The CLI waits by default. On Linux and macOS, that means py-admin-launch
returns the elevated command's exit code, including failures such as cancelled
authentication or a failed pkexec/sudo invocation. This matches the behavior
users usually expect from commands like sudo your-command.
Use --no-wait only when you intentionally want to start the command in the
background and return after the elevation request is handed off. In that mode,
the launcher cannot report the elevated command's later exit code.
On Windows, elevated launches use ShellExecuteW(..., "runas", ...), which does
not provide a child process handle to this helper. That means the CLI cannot
observe the elevated program's exit code on Windows.
Python API
from py_admin_launch import launch
launch(["python", "-m", "http.server", "80"])
launch() accepts a command list plus optional cwd and wait arguments:
result = launch(["your-command", "arg1"], cwd="/tmp", wait=True)
print(result.elevated, result.returncode)
When wait=True, returncode is the launched command's exit code where the
platform exposes one. When wait=False, returncode is None.
Project details
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 py_admin_launch-0.1.3.tar.gz.
File metadata
- Download URL: py_admin_launch-0.1.3.tar.gz
- Upload date:
- Size: 7.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.4.1 CPython/3.11.15 Windows/10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c45a6a35576c9f3f405ae4f789c116115e86f0a4ce497e96692aada99f949704
|
|
| MD5 |
93d50ce44e775fa8c1ba6c5b7e43fd1f
|
|
| BLAKE2b-256 |
1d19f2cfe1a1debcc60d93f9860c9d0a34600fd7a0d399cf87cacb189f242a6e
|
File details
Details for the file py_admin_launch-0.1.3-py3-none-any.whl.
File metadata
- Download URL: py_admin_launch-0.1.3-py3-none-any.whl
- Upload date:
- Size: 7.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.4.1 CPython/3.11.15 Windows/10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c8a34fc20f25de5f4f4caf552fe4cc032d95b86bbc366f4b19bbf55ed74e9035
|
|
| MD5 |
85728216db9e7155e3cb07ee85704b64
|
|
| BLAKE2b-256 |
0b36593e16a73be3f47a72c39c9b6b13b32d41f083574cfbbca6f8e87748cdf7
|