Skip to main content

Environment Utils

Pypi project python license Pypi total project downloads Github Actions

Utilities to identify the environment in which your Python script is running.

This includes determining whether you are in a Jupyter Notebook, within a node of a SLURM cluster, the architecture of the system you are using, and the operating system.

Installation

Install environments_utils from PyPi:

pip install environments_utils

Examples

Detect Rosetta on macOS with Python

Rosetta is a translation environment that enables you to run apps that contain x86_64 instructions on Apple silicon. In some cases, Rosetta may fail to translate an app successfully, and lead to crashes or other unexpected behavior. It is sometimes therefore useful to know whether the script is running within a macOS with Rosetta so to better understand whether the odd behaviour you may be experiencing is due to Rosetta or not.

To detect Rosetta, simply run:

from environments_utils import is_macos_rosetta

if is_macos_rosetta():
    print("I am running inside Rosetta!")

is_tmux

Return a boolean representing if the script is running within a TMUX-like terminal.

from environments_utils import is_tmux

if not is_tmux():
    print("This script is long-running; consider starting it within a TMUX-like terminal.")

is_notebook

Return a boolean representing if the script is running within a Jupyter notebook.

from environments_utils import is_notebook
from tqdm import tqdm_notebook, tqdm as tqdm_cli

tqdm = tqdm_notebook if is_notebook() else tqdm_cli

is_slurm_node

Returns whether you are in a SLURM cluster node.

from environments_utils import (
    is_slurm_node,
    get_slurm_node_id,
    get_number_of_available_slurm_nodes
)

if is_slurm_node():
    print("YAY! I'm in node {} of {}!".format(get_slurm_node_id(), get_number_of_available_slurm_nodes()))

Operating System Identifiers

Utilities to identify the operating system running the app.

from environments_utils import is_macos, is_windows, is_linux, is_macos_with_arm

if is_macos():
    print("The OS is macOS")

if is_windows():
    print("The OS is Windows")

if is_linux():
    print("The OS is Linux")

if is_macos_with_arm():
    print("The machine is macOS with ARM processors like M1")

Architecture Identifiers

Utilities to identify the architectures running the app.

from environments_utils import is_x86, is_x86_64, is_arm

if is_x86():
    print("This is a 32-bit system with x86 architecture.")

if is_x86_64():
    print("This is a 64-bit system with x86_64 architecture.")

if is_arm():
    print("This is an ARM machine, such as Mac M1")

Internet Connection

Utility to detect whether the user is connected to the internet.

from environments_utils import is_online

if is_online():
    print("You are online.")
else:
    print("You are offline")

GPU Availability

The packaged also provides heuristics to determine whether a GPU is available, which do not require the installation of torch or tensorflow. It does have the same limitations of those methods, as it still requires the drivers to be installed.

from environments_utils import has_gpu, has_nvidia_gpu, has_amd_gpu, has_intel_gpu

if has_gpu():
    if has_nvidia_gpu():
        print("NVIDIA GPU is available.")
    elif has_amd_gpu():
        print("AMD GPU is available.")
    elif has_intel_gpu():
        print("Intel GPU is available.")
else:
    print("GPU is not available.")

License

This project is licensed under the MIT License - see the LICENSE file for details.

Metadata

Release files for environments-utils 1.0.15

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

Source distribution (sdist)

Source distribution for environments-utils 1.0.15
File Size Uploaded Provenance Actions
environments_utils-1.0.15.tar.gz 8.9 kB Without provenance Details for environments_utils-1.0.15.tar.gz

Release files / environments_utils-1.0.15.tar.gz

Download URL environments_utils-1.0.15.tar.gz
Size 8.9 kB
Tags Source
SHA-256 checksum
How to use checksums
9807fbc323eefeb5766d091f40a3ca4ea652f69321d7e5976ff9edce40330d64
BLAKE2b-256 checksum
How to use checksums
0cdc6d54683a129c309447bfc3252f4d4cb24807f2ed539cfb28e898397541a8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.1 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.7.9

Security for environments-utils 1.0.15

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