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

  • Windows: UAC starts a hidden helper. The command uses the caller's console for interactive streams and the original file or pipe handles for redirected streams. Standard output and standard error remain separate; binary data is not decoded or copied through a TCP server. Only the UAC consent dialog is needed, not a second command window.
  • Linux: a controlling terminal uses sudo, which can prompt on /dev/tty even when command input is piped. A headless session uses sudo -n: arrange noninteractive authorization or the command fails on stderr. A graphical session without a controlling terminal prefers pkexec and a polkit agent. pkexec receives the display/session variables and keeps the working directory; sudo uses its configured environment policy and the requested working directory. Standard input, output and error are inherited in all three cases.
  • 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 and returns the command's exit code. On Windows and Linux, use ordinary shell pipes and redirection. For example, in cmd.exe or a POSIX shell:

py-admin-launch -- your-command < input.bin > output.bin 2> errors.log

Press Ctrl+C to interrupt a foreground command. On Windows the console delivers Ctrl+C to an attached command. With all three streams redirected, the helper forwards Ctrl+C to the command's private hidden console instead. On cancellation the helper gives the command up to three seconds to exit, then terminates any remaining processes in its job. The CLI reports an interrupt as exit code 130.

Use --no-wait only when you intentionally want to start the command in the background. On Windows it returns after the helper confirms the command has started. The child retains its stream handles, but the launcher no longer waits for its exit or supervises Ctrl+C. Redirect streams before handing off if the child should not share the terminal.

Python API

from py_admin_launch import launch

launch(["python", "-m", "http.server", "80"], wait=True)

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)

Use wait=True for foreground execution and interruption. With the API default wait=False, returncode is None. On Windows, pid is the target command's PID, not the helper's.

Testing

Run python -m unittest discover -s tests -v. Windows integration tests use the real helper and Win32 IPC with the open verb so CI needs no consent UI. Set PAL_TEST_UAC=1 from a non-administrator terminal to exercise runas instead. Linux integration tests run as root or with noninteractive sudo authorization for the test interpreter.

Metadata

Release files for py-admin-launch 0.2.1

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.1
File Size Uploaded Provenance Actions
py_admin_launch-0.2.1.tar.gz 15.6 kB Without provenance Details for py_admin_launch-0.2.1.tar.gz

Built distribution (wheel)

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

Total release size: 26.7 kB

Release files / py_admin_launch-0.2.1.tar.gz

Download URL py_admin_launch-0.2.1.tar.gz
Size 15.6 kB
Tags Source
SHA-256 checksum
How to use checksums
9a63d54bc567b864bf17358fce41885bcf9a7263cd864f7f3065a4da2b9a67e1
BLAKE2b-256 checksum
How to use checksums
82db5d1cb6b683c48a60030ee2ce47180e51b7c32b7ecc2b28677275f3e29176
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.4.1 CPython/3.14.6 Windows/11

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

Download URL py_admin_launch-0.2.1-py3-none-any.whl
Size 11.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
388b803b34b057f888efb51519341667e241aa7689359aa9e2005ba88412f100
BLAKE2b-256 checksum
How to use checksums
d20367bb25a0e2d0fe91fe4dfa6adaef79dc25364cdcedae0a01662e255522b5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.4.1 CPython/3.14.6 Windows/11

Security for py-admin-launch 0.2.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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