Skip to main content

A simple wrapper around subprocess with persistent environment variables

Project description

persishell

Lightweight replacement for os.system() with a persistent environment.

persishell is a simple Python library that wraps a persistent Bash subprocess, allowing you to run shell commands sequentially — with shared environment state across runs. It's useful when you need to maintain exported variables, cd into directories, interact with module load, or configure shell settings once and use them across multiple commands.

I use it extensively on SLURM clusters to write all my experiment scripts (including the sbatch scripts) in Python.

Installation

pip install persishell

Or for development:

pip install -e .

Quick Start

from persishell import PersiShell

sh = PersiShell()

# Set environment variables
sh.export("FOO", "bar")

# Commands use the persistent environment
sh.run("echo $FOO")  # prints: bar

# Change directories
sh.run("cd /tmp")
sh.run("pwd")  # prints: /tmp

# Unset environment variables
sh.unset("FOO")
sh.run("echo $FOO")  # prints an empty line

API Summary

PersiShell.run(command: str | list, optinal arguments)

Run a command inside the persistent shell. Accepts a string or a list of arguments.

PersiShell.export(key: str, value: str)

Export a persistent environment variable.

PersiShell.unset(key: str)

Unset a previously defined environment variable.

Limitations

Currently designed for Unix-like systems (uses bash, fcntl). It has not been tested on Windows.

License

MIT License

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

persishell-0.1.0.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.

persishell-0.1.0-py3-none-any.whl (3.4 kB view details)

Uploaded Python 3

File details

Details for the file persishell-0.1.0.tar.gz.

File metadata

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

File hashes

Hashes for persishell-0.1.0.tar.gz
Algorithm Hash digest
SHA256 6b0dd7acd541aedf3df929de4b1f6eeaf0f3372fbf19575f3b347ab7a8777ab8
MD5 6e79e4c0b3d1d288715278b60d085e77
BLAKE2b-256 98fb56418226bae443fdaff71f1e28360fefc5de2048b282d3cab75019d236f3

See more details on using hashes here.

File details

Details for the file persishell-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: persishell-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 3.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.10

File hashes

Hashes for persishell-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fcaaa4c9005a9b0b2da0e6a903e365ce64e4002a3d073f134e2d344b3fdcc589
MD5 b1231fe3f8e83b8a9a46c6a924f00145
BLAKE2b-256 d12cf4cbb2b11f74b8d8a86c8e1298a77c6de9d72aea9f76af3818faec23d40b

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