Skip to main content

Elevate: Request root privileges

Elevate is a small Python library that re-launches the current process with root/admin privileges using one of the following mechanisms:

  • UAC (Windows)

  • AppleScript (macOS)

  • pkexec, gksudo or kdesudo (Linux)

  • sudo (Linux, macOS)

Usage

To use, call elevate.elevate() early in your script. When run as root this function does nothing. When not run as root, this function replaces the current process (Linux, macOS) or creates a new process, waits, and exits (Windows). Consider the following example:

import os
from elevate import elevate

def is_root():
    return os.getuid() == 0

print("before ", is_root())
elevate()
print("after ", is_root())

This prints:

before False
before True
after True

On Windows, the new process’s standard streams are not attached to the parent, which is an inherent limitation of UAC. By default the new process runs in a new console window. To suppress this window, use elevate(show_console=False).

On Linux and macOS, graphical prompts are tried before sudo by default. To prevent graphical prompts, use elevate(graphical=False).

Metadata

Release files for elevate-updated 0.1.5

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

Source distribution (sdist)

Source distribution for elevate-updated 0.1.5
File Size Uploaded
elevate_updated-0.1.5.tar.gz 3.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for elevate-updated 0.1.5
File Interpreter ABI Platform
elevate_updated-0.1.5-py3-none-any.whl Python 3 none any Details

Total release size: 7.5 kB

Release files / elevate_updated-0.1.5.tar.gz

Download URL elevate_updated-0.1.5.tar.gz
Size 3.4 kB
Tags Source
SHA-256 checksum
How to use checksums
a218c47fcaf667bbfbd7e7e09c72e15875d50016d21e3fe48d5a0adbc4a22caa
BLAKE2b-256 checksum
How to use checksums
ad7892789b1e61d5dfe200c17acdb1f505aa6d991010347ba3f1ccc478650c4b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.5

Release files / elevate_updated-0.1.5-py3-none-any.whl

Download URL elevate_updated-0.1.5-py3-none-any.whl
Size 4.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9f15667eaca628c96ea7b6fb2caf3a3673ae99349f263053aa286c5bd43d3127
BLAKE2b-256 checksum
How to use checksums
149154809c7051f9f58cbcfb89324e5635ea690488b22b1707c5572137663a69
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.5

Release history Release notifications | RSS feed

This release

0.1.5 This release

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