Skip to main content

Check whether the current Python process is running as an administrator or root user.

Project description

is-admin-user

Check whether the current Python process is running as an administrator.

is-admin-user is a tiny, dependency-free Python package that works across Windows, Linux, and macOS. It exposes a programmable function interface for checking whether the current process has administrative privileges.

Installation

pip install is-admin-user

For local development:

pip install -e .

Usage

Python

from is_admin_user import is_admin_user

if is_admin_user():
    print("Running as administrator/root")
else:
    print("Running as a standard user")

You can also use the shorter alias:

from is_admin_user import is_admin

if is_admin():
    print("Administrative privileges are available")

Command line

is-admin-user

The command prints true and exits with status code 0 when the current process has administrator/root privileges. It prints false and exits with status code 1 otherwise.

For scripts that only need the exit code:

is-admin-user --quiet

Platform behavior

  • Windows: returns True when the current process token is running with administrator privileges.
  • Linux: returns True when the effective user ID is 0 (root).
  • macOS: returns True when the effective user ID is 0 (root).

On Windows, an account that belongs to the Administrators group may still return False if the Python process was not started with elevated privileges.

API

is_admin_user() -> bool

Returns True when the current Python process has administrator/root privileges, otherwise returns False.

is_admin() -> bool

Alias for is_admin_user().

Development

Run the test suite with:

python -m pytest

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

is_admin_user-0.1.1.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

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

is_admin_user-0.1.1-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

Details for the file is_admin_user-0.1.1.tar.gz.

File metadata

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

File hashes

Hashes for is_admin_user-0.1.1.tar.gz
Algorithm Hash digest
SHA256 caf7b0288d8bff05aac164b621941968a095c47a3ccc1e032cdeb3d9fa4ef7b7
MD5 ff2236e4581fd4d74ce13bd194249c29
BLAKE2b-256 5bd28460fc3f667f7fa87c297cbadf6127935a50f93c62f6dad1ddce2f9c1365

See more details on using hashes here.

File details

Details for the file is_admin_user-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: is_admin_user-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 5.0 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 is_admin_user-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ad77912508ae750b68790afbf43cf92886cef0c66f3e20b54c67112679a41cde
MD5 c1e305f1e9c39e16bff10f9e2c6c336e
BLAKE2b-256 3a694a94e2b00db1c3d9cd0f3af4779015a260538544ce7875f336f1f52f29e0

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