API
You can use runchain from your Python code
from runchain import Chain, list_chains
# List all chains
chains = list_chains()
print("Available chains:", chains)
# Work with a specific chain
backup_chain = Chain("backup")
if backup_chain.exists():
print("Scripts in backup chain:", backup_chain.list())
# Add a script file
backup_chain.add_file("~/scripts/database.sh", "10")
backup_chain.add_file("~/scripts/files.py", "20-backup-files")
# Add a script from string content
backup_chain.add_string(
"#!/bin/bash",
"echo 'Hello from string script'",
target="30-hello"
)
# Schedule the chain
backup_chain.cron("0 2 * * *")
# Run the chain
success = backup_chain.run()
if success:
print("Backup completed successfully")
# Remove a script
backup_chain.remove("10-database.sh")
# Remove entire chain
backup_chain.destroy()
API reference
- class runchain.chain.Chain(name: str, base_dir: pathlib.Path | str | None = None)
Bases:
objectRepresents a single runchain chain.
- add_file(script_path: str, target: str | None = None) str
Add a script to this chain.
- Parameters
script_path – Path to the script file to add
target – Optional naming specification
- Returns
The final filename in the chain
- add_string(*contents: str, target: str) str
Add a script string to this chain.
- Parameters
contents – Script content lines
target – Required naming specification (number or NN-name format)
- Returns
The final filename in the chain
- cron(schedule: str) None
Schedule this chain to run with crondir.
- destroy() None
Remove this entire chain.
- exists() bool
Check if this chain exists.
- list() list[str]
List all scripts in this chain in alphabetical order.
- log(message: str) None
Log a message.
- remove(script: str, target: str | None = None) None
Remove a script from this chain.
- run() bool
Execute all scripts in this chain in alphabetical order.
- Returns
True if all scripts succeeded, False if any failed
- runchain.chain.list_chains(base_dir: pathlib.Path | str | None = None) list[str]
List all available chains.