Skip to main content

Python library for requesting root privileges

Project description

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)

  • gksudo (Linux)

  • 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).

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

elevate-0.1.2.tar.gz (2.9 kB view details)

Uploaded Source

File details

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

File metadata

  • Download URL: elevate-0.1.2.tar.gz
  • Upload date:
  • Size: 2.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for elevate-0.1.2.tar.gz
Algorithm Hash digest
SHA256 e40aa31cf208e97bfdf448d72a63a93d82d46e757bebaea165806b0cdd5cebb4
MD5 914f5a9bc3479870d75aeefd41e4daa3
BLAKE2b-256 f5273c6040dc5ef75a85e1833bca5186ecfaad537e28111bd02a839136487b6c

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