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.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

py_admin_launch-0.2.0.tar.gz (7.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

py_admin_launch-0.2.0-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

Details for the file py_admin_launch-0.2.0.tar.gz.

File metadata

  • Download URL: py_admin_launch-0.2.0.tar.gz
  • Upload date:
  • Size: 7.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.1 CPython/3.13.5 Windows/11

File hashes

Hashes for py_admin_launch-0.2.0.tar.gz
Algorithm Hash digest
SHA256 77ea0d6d9501aa2780150bb968a5d1e82a8a27104e13ca1f529aab8820a202bd
MD5 c0f92e627ca0d1c50d37720a6be1c9b6
BLAKE2b-256 3ec486a9008dad696095384d8c4d87e4d4c83a5b4425dace0849b258b6746463

See more details on using hashes here.

File details

Details for the file py_admin_launch-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: py_admin_launch-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 7.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.1 CPython/3.13.5 Windows/11

File hashes

Hashes for py_admin_launch-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4c5fa4ba3e36b132a55eb44bdf5e57fdd1e441c4549f672e557947a93e5c5357
MD5 5e54ffad7df129dd7842f08ad986a531
BLAKE2b-256 4f2866b1bc71d3cd8d1fec28ed0b263fdbbf7488273b40d6d081c2a4e9ba648e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page