Skip to main content

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: pkexec for polkit GUI authentication, falling back to sudo when pkexec is not available.
  • 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.

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

py_admin_launch-0.1.2.tar.gz (6.6 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.1.2-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: py_admin_launch-0.1.2.tar.gz
  • Upload date:
  • Size: 6.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.4.1 CPython/3.11.15 Windows/10

File hashes

Hashes for py_admin_launch-0.1.2.tar.gz
Algorithm Hash digest
SHA256 08036ef76f925edc8c61b87643a2fceaa5c2d99007a370f77915e52ad5d1bc27
MD5 24b1aadf6b1170ba6f5c224dcde1fb46
BLAKE2b-256 c532733ee9cbaaab3c842817a67e720d444bab91bd117f184a110cb2f0801634

See more details on using hashes here.

File details

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

File metadata

  • Download URL: py_admin_launch-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 6.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.4.1 CPython/3.11.15 Windows/10

File hashes

Hashes for py_admin_launch-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 0a905eb0faca6a95193c7e6299569e0bb818dbc989bd4fd6689d771f53c46a26
MD5 e502b1b2ce35d90685dcfea464f3c121
BLAKE2b-256 a0f8c65ab9042ddd29900b94a933a5fd99d8281df681168a943b97266a258c09

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 Pingdom Monitoring Sentry Error logging StatusPage Status page