Persistent bash sessions for Python
Project description
bashautom
Persistent bash sessions for Python.
Unlike subprocess.run() which spawns a new process every time, bashautom keeps a /bin/bash process alive so state (env vars, cwd, etc.) persists across commands.
from bashautom import Session
with Session() as s:
s.execute("cd /opt/myproject")
s.execute("source .env")
s.execute("export BUILD_ID=42")
result = s.execute("make build")
Install
pip install bashautom
Python 3.10+, Linux/macOS only.
Usage
from bashautom import Session
with Session() as s:
result = s.execute("echo hello")
print(result.stdout)
print(result.exit_code)
print(result.success)
Timeouts
Commands can be killed without destroying the session:
with Session() as s:
result = s.execute("sleep 60", timeout=3)
print(result.timed_out)
# session still works
s.execute("echo ok")
Streaming
from bashautom.session import StreamEvent
def on_output(event: StreamEvent):
print(f"[{event.stream}] {event.data.strip()}")
with Session() as s:
s.execute("for i in 1 2 3; do echo $i; sleep 0.5; done", stream_callback=on_output)
Multiple sessions
from bashautom import SessionManager
with SessionManager() as mgr:
build = mgr.create("build", cwd="/opt/project")
deploy = mgr.create("deploy", cwd="/opt/infra")
build.execute("make release")
deploy.execute("./deploy.sh")
Env helpers
with Session() as s:
s.set_env("PROJECT", "bashautom")
print(s.get_env("PROJECT"))
print(s.get_cwd())
print(s.pid)
print(s.alive)
API
Session
execute(command, timeout=None, stream_callback=None)- run a command, returnsCommandResultsend_signal(sig=SIGINT)- send a signal to the running processget_cwd()/get_env(var)/set_env(var, value)- shell state accessclose()- kill the sessionpid,alive- process info
CommandResult
command,stdout,stderr- what ran and what came backexit_code,success,timed_out- statusduration- wall time in seconds
SessionManager
create(name, ...)/get(name)/get_or_create(name, ...)- session lifecycleclose(name)/close_all()- cleanupnames,active- introspection
License
MIT
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file bashautom-0.1.1.tar.gz.
File metadata
- Download URL: bashautom-0.1.1.tar.gz
- Upload date:
- Size: 8.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
785e9aa4b29106963865f03dea0d274bd9c99dac4d457dc9aa7f68d0ab39ccd3
|
|
| MD5 |
4b929bcfb62c092e2471340316556e01
|
|
| BLAKE2b-256 |
28125819192ef9a2bf6814e0c93cc18f47c04083aea10046079ea390aafaf0a3
|
Provenance
The following attestation bundles were made for bashautom-0.1.1.tar.gz:
Publisher:
publish.yml on huskago/bashautom
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
bashautom-0.1.1.tar.gz -
Subject digest:
785e9aa4b29106963865f03dea0d274bd9c99dac4d457dc9aa7f68d0ab39ccd3 - Sigstore transparency entry: 975263067
- Sigstore integration time:
-
Permalink:
huskago/bashautom@1aeb0b1393529e5b30ee659079d3f4462bfc8c30 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/huskago
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@1aeb0b1393529e5b30ee659079d3f4462bfc8c30 -
Trigger Event:
release
-
Statement type:
File details
Details for the file bashautom-0.1.1-py3-none-any.whl.
File metadata
- Download URL: bashautom-0.1.1-py3-none-any.whl
- Upload date:
- Size: 7.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3078f43a1ee896b15d92fc734d491c8035ebb5eb09a1098000c029d6bcbddaa2
|
|
| MD5 |
4af1878ac136f79cdbe4ea87ff65503b
|
|
| BLAKE2b-256 |
e1bfb1a756802c9641663a3fa43d01ed0d6f607c88477709272a747c0448f59a
|
Provenance
The following attestation bundles were made for bashautom-0.1.1-py3-none-any.whl:
Publisher:
publish.yml on huskago/bashautom
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
bashautom-0.1.1-py3-none-any.whl -
Subject digest:
3078f43a1ee896b15d92fc734d491c8035ebb5eb09a1098000c029d6bcbddaa2 - Sigstore transparency entry: 975263069
- Sigstore integration time:
-
Permalink:
huskago/bashautom@1aeb0b1393529e5b30ee659079d3f4462bfc8c30 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/huskago
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@1aeb0b1393529e5b30ee659079d3f4462bfc8c30 -
Trigger Event:
release
-
Statement type: