Skip to main content

py-admin-launch

A cross-platform Python command/helper to launch a specified program with administrator privileges.

Python 3.6 and every later Python 3 release are supported. Python 3.6 installs the small dataclasses backport automatically; newer interpreters use the standard-library implementation.

Strategy

  • Linux desktop: pkexec for polkit GUI authentication, falling back to sudo when pkexec is not available. GUI session variables such as DISPLAY, XAUTHORITY, WAYLAND_DISPLAY, XDG_RUNTIME_DIR, and DBUS_SESSION_BUS_ADDRESS are passed explicitly so desktop apps can still reach the current display after elevation.
  • Windows: ShellExecuteW(..., "runas", ...).
  • macOS: osascript + with administrator privileges, falling back to sudo when osascript is 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.

Metadata

Release files for py-admin-launch 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for py-admin-launch 0.2.0
File Size Uploaded
py_admin_launch-0.2.0.tar.gz 7.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for py-admin-launch 0.2.0
File Interpreter ABI Platform
py_admin_launch-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 15.2 kB

Release files / py_admin_launch-0.2.0.tar.gz

Download URL py_admin_launch-0.2.0.tar.gz
Size 7.9 kB
Tags Source
SHA-256 checksum
How to use checksums
77ea0d6d9501aa2780150bb968a5d1e82a8a27104e13ca1f529aab8820a202bd
BLAKE2b-256 checksum
How to use checksums
3ec486a9008dad696095384d8c4d87e4d4c83a5b4425dace0849b258b6746463
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.2.1 CPython/3.13.5 Windows/11

Release files / py_admin_launch-0.2.0-py3-none-any.whl

Download URL py_admin_launch-0.2.0-py3-none-any.whl
Size 7.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4c5fa4ba3e36b132a55eb44bdf5e57fdd1e441c4549f672e557947a93e5c5357
BLAKE2b-256 checksum
How to use checksums
4f2866b1bc71d3cd8d1fec28ed0b263fdbbf7488273b40d6d081c2a4e9ba648e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.2.1 CPython/3.13.5 Windows/11

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page