Utilities to identify which environments is your python script running within.
Project description
Environment Utils
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
To install this package, use pip:
pip install environments_utils
Examples
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")
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Hashes for environments_utils-1.0.11.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5ed275c346d0b0d76ac48f37f31d53fd228fbb58063cefb5c6613588aa925e40 |
|
MD5 | bed0657c8aec0472cf000bb2b471a803 |
|
BLAKE2b-256 | aafbe7e8d19772d2d10ec4e73b761fe33c368e21d9d94d7cbcb3f492e9e587e7 |