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)

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

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_updated-0.1.5.tar.gz (3.4 kB view details)

Uploaded Source

Built Distribution

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

elevate_updated-0.1.5-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

File details

Details for the file elevate_updated-0.1.5.tar.gz.

File metadata

  • Download URL: elevate_updated-0.1.5.tar.gz
  • Upload date:
  • Size: 3.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for elevate_updated-0.1.5.tar.gz
Algorithm Hash digest
SHA256 a218c47fcaf667bbfbd7e7e09c72e15875d50016d21e3fe48d5a0adbc4a22caa
MD5 2b9001ecd8392f4525a858da64610f2e
BLAKE2b-256 ad7892789b1e61d5dfe200c17acdb1f505aa6d991010347ba3f1ccc478650c4b

See more details on using hashes here.

File details

Details for the file elevate_updated-0.1.5-py3-none-any.whl.

File metadata

File hashes

Hashes for elevate_updated-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 9f15667eaca628c96ea7b6fb2caf3a3673ae99349f263053aa286c5bd43d3127
MD5 cb4458587540a44b3473b23762f91be1
BLAKE2b-256 149154809c7051f9f58cbcfb89324e5635ea690488b22b1707c5572137663a69

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