environments-utils


Nameenvironments-utils JSON
Version 1.0.15 PyPI version JSON
download
home_pagehttps://github.com/LucaCappelletti94/environments_utils
SummaryUtilities to identify which environments is your python script running within.
upload_time2024-10-30 17:07:50
maintainerNone
docs_urlNone
authorLuca Cappelletti
requires_pythonNone
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Environment Utils

[![Pypi project](https://badge.fury.io/py/environments-utils.svg)](https://badge.fury.io/py/environments-utils)
[![python](https://img.shields.io/pypi/pyversions/environments-utils)](https://pypi.org/project/environments-utils/)
[![license](https://img.shields.io/pypi/l/environments-utils)](https://pypi.org/project/environments-utils/)
[![Pypi total project downloads](https://pepy.tech/badge/environments-utils)](https://pepy.tech/badge/environments-utils)
[![Github Actions](https://github.com/LucaCappelletti94/environments_utils/actions/workflows/python.yml/badge.svg)](https://github.com/LucaCappelletti94/environments_utils/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`:

```shell
pip install environments_utils
```

## Examples

### Detect Rosetta on macOS with Python

[Rosetta](https://developer.apple.com/documentation/apple_silicon/about_the_rosetta_translation_environment) 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:

```python
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.

```python
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.

```python
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.

```python
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.

```python
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.

```python
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.

```python
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.

```python
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](LICENSE) file for details.



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/LucaCappelletti94/environments_utils",
    "name": "environments-utils",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": null,
    "author": "Luca Cappelletti",
    "author_email": "cappelletti.luca94@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/0c/dc/6d54683a129c309447bfc3252f4d4cb24807f2ed539cfb28e898397541a8/environments_utils-1.0.15.tar.gz",
    "platform": null,
    "description": "# Environment Utils\n\n[![Pypi project](https://badge.fury.io/py/environments-utils.svg)](https://badge.fury.io/py/environments-utils)\n[![python](https://img.shields.io/pypi/pyversions/environments-utils)](https://pypi.org/project/environments-utils/)\n[![license](https://img.shields.io/pypi/l/environments-utils)](https://pypi.org/project/environments-utils/)\n[![Pypi total project downloads](https://pepy.tech/badge/environments-utils)](https://pepy.tech/badge/environments-utils)\n[![Github Actions](https://github.com/LucaCappelletti94/environments_utils/actions/workflows/python.yml/badge.svg)](https://github.com/LucaCappelletti94/environments_utils/actions/)\n\nUtilities to identify the environment in which your Python script is running.\n\nThis 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.\n\n## Installation\n\nInstall `environments_utils` from `PyPi`:\n\n```shell\npip install environments_utils\n```\n\n## Examples\n\n### Detect Rosetta on macOS with Python\n\n[Rosetta](https://developer.apple.com/documentation/apple_silicon/about_the_rosetta_translation_environment) 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.\n\nTo detect Rosetta, simply run:\n\n```python\nfrom environments_utils import is_macos_rosetta\n\nif is_macos_rosetta():\n    print(\"I am running inside Rosetta!\")\n```\n\n### is_tmux\n\nReturn a boolean representing if the script is running within a TMUX-like terminal.\n\n```python\nfrom environments_utils import is_tmux\n\nif not is_tmux():\n    print(\"This script is long-running; consider starting it within a TMUX-like terminal.\")\n```\n\n### is_notebook\n\nReturn a boolean representing if the script is running within a Jupyter notebook.\n\n```python\nfrom environments_utils import is_notebook\nfrom tqdm import tqdm_notebook, tqdm as tqdm_cli\n\ntqdm = tqdm_notebook if is_notebook() else tqdm_cli\n```\n\n### is_slurm_node\n\nReturns whether you are in a `SLURM` cluster node.\n\n```python\nfrom environments_utils import (\n    is_slurm_node,\n    get_slurm_node_id,\n    get_number_of_available_slurm_nodes\n)\n\nif is_slurm_node():\n    print(\"YAY! I'm in node {} of {}!\".format(get_slurm_node_id(), get_number_of_available_slurm_nodes()))\n```\n\n## Operating System Identifiers\n\nUtilities to identify the operating system running the app.\n\n```python\nfrom environments_utils import is_macos, is_windows, is_linux, is_macos_with_arm\n\nif is_macos():\n    print(\"The OS is macOS\")\n\nif is_windows():\n    print(\"The OS is Windows\")\n\nif is_linux():\n    print(\"The OS is Linux\")\n\nif is_macos_with_arm():\n    print(\"The machine is macOS with ARM processors like M1\")\n```\n\n## Architecture Identifiers\n\nUtilities to identify the architectures running the app.\n\n```python\nfrom environments_utils import is_x86, is_x86_64, is_arm\n\nif is_x86():\n    print(\"This is a 32-bit system with x86 architecture.\")\n\nif is_x86_64():\n    print(\"This is a 64-bit system with x86_64 architecture.\")\n\nif is_arm():\n    print(\"This is an ARM machine, such as Mac M1\")\n```\n\n## Internet Connection\n\nUtility to detect whether the user is connected to the internet.\n\n```python\nfrom environments_utils import is_online\n\nif is_online():\n    print(\"You are online.\")\nelse:\n    print(\"You are offline\")\n```\n\n## GPU Availability\n\nThe 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.\n\n```python\nfrom environments_utils import has_gpu, has_nvidia_gpu, has_amd_gpu, has_intel_gpu\n\nif has_gpu():\n    if has_nvidia_gpu():\n        print(\"NVIDIA GPU is available.\")\n    elif has_amd_gpu():\n        print(\"AMD GPU is available.\")\n    elif has_intel_gpu():\n        print(\"Intel GPU is available.\")\nelse:\n    print(\"GPU is not available.\")\n```\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Utilities to identify which environments is your python script running within.",
    "version": "1.0.15",
    "project_urls": {
        "Homepage": "https://github.com/LucaCappelletti94/environments_utils"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "0cdc6d54683a129c309447bfc3252f4d4cb24807f2ed539cfb28e898397541a8",
                "md5": "fc57dee9c819c3caf5c0f69ffcf0ada8",
                "sha256": "9807fbc323eefeb5766d091f40a3ca4ea652f69321d7e5976ff9edce40330d64"
            },
            "downloads": -1,
            "filename": "environments_utils-1.0.15.tar.gz",
            "has_sig": false,
            "md5_digest": "fc57dee9c819c3caf5c0f69ffcf0ada8",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 8867,
            "upload_time": "2024-10-30T17:07:50",
            "upload_time_iso_8601": "2024-10-30T17:07:50.580010Z",
            "url": "https://files.pythonhosted.org/packages/0c/dc/6d54683a129c309447bfc3252f4d4cb24807f2ed539cfb28e898397541a8/environments_utils-1.0.15.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-10-30 17:07:50",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "LucaCappelletti94",
    "github_project": "environments_utils",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "environments-utils"
}
        
Elapsed time: 0.46867s