Index
๐ค AI-Generated Content
This documentation was generated with AI assistance and is still being audited. Some, or potentially a lot, of this information may be inaccurate. Learn more.
provide.foundation.process.aio
¶
Functions¶
async_run
async
¶
async_run(
cmd: list[str] | str,
cwd: str | Path | None = None,
env: Mapping[str, str] | None = None,
capture_output: bool = True,
check: bool = True,
timeout: float | None = None,
input: bytes | None = None,
shell: bool = False,
**kwargs: Any,
) -> CompletedProcess
Run a subprocess command asynchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cmd
|
list[str] | str
|
Command and arguments as a list |
required |
cwd
|
str | Path | None
|
Working directory for the command |
None
|
env
|
Mapping[str, str] | None
|
Environment variables (if None, uses current environment) |
None
|
capture_output
|
bool
|
Whether to capture stdout/stderr |
True
|
check
|
bool
|
Whether to raise exception on non-zero exit |
True
|
timeout
|
float | None
|
Command timeout in seconds |
None
|
input
|
bytes | None
|
Input to send to the process |
None
|
shell
|
bool
|
Whether to execute via shell |
False
|
**kwargs
|
Any
|
Additional subprocess arguments |
{}
|
Returns:
| Type | Description |
|---|---|
CompletedProcess
|
CompletedProcess with results |
Raises:
| Type | Description |
|---|---|
ValidationError
|
If command type and shell parameter mismatch |
ProcessError
|
If command fails and check=True |
ProcessTimeoutError
|
If timeout is exceeded |
Source code in provide/foundation/process/aio/execution.py
287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 | |
async_shell
async
¶
async_shell(
cmd: str,
cwd: str | Path | None = None,
env: Mapping[str, str] | None = None,
capture_output: bool = True,
check: bool = True,
timeout: float | None = None,
allow_shell_features: bool = DEFAULT_SHELL_ALLOW_FEATURES,
**kwargs: Any,
) -> CompletedProcess
Run a shell command asynchronously with safety validation.
WARNING: This function uses shell=True. By default, shell metacharacters are DENIED to prevent command injection. Use allow_shell_features=True only with trusted input.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cmd
|
str
|
Shell command string |
required |
cwd
|
str | Path | None
|
Working directory |
None
|
env
|
Mapping[str, str] | None
|
Environment variables |
None
|
capture_output
|
bool
|
Whether to capture output |
True
|
check
|
bool
|
Whether to raise on non-zero exit |
True
|
timeout
|
float | None
|
Command timeout in seconds |
None
|
allow_shell_features
|
bool
|
Allow shell metacharacters (default: False) |
DEFAULT_SHELL_ALLOW_FEATURES
|
**kwargs
|
Any
|
Additional subprocess arguments |
{}
|
Returns:
| Type | Description |
|---|---|
CompletedProcess
|
CompletedProcess with results |
Raises:
| Type | Description |
|---|---|
ValidationError
|
If cmd is not a string |
ShellFeatureError
|
If shell features used without explicit permission |
Security Note
For maximum security, use async_run() with a list of arguments instead. Only set allow_shell_features=True if you fully trust the command source.
Safe: await async_shell("ls -la", allow_shell_features=False) # OK Unsafe: await async_shell(user_input) # Will raise ShellFeatureError if metacharacters present Risky: await async_shell(user_input, allow_shell_features=True) # DO NOT DO THIS
Source code in provide/foundation/process/aio/shell.py
async_stream
async
¶
async_stream(
cmd: list[str],
cwd: str | Path | None = None,
env: Mapping[str, str] | None = None,
timeout: float | None = None,
stream_stderr: bool = False,
**kwargs: Any,
) -> AsyncIterator[str]
Stream command output line by line asynchronously.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cmd
|
list[str]
|
Command and arguments as a list |
required |
cwd
|
str | Path | None
|
Working directory for the command |
None
|
env
|
Mapping[str, str] | None
|
Environment variables |
None
|
timeout
|
float | None
|
Command timeout in seconds |
None
|
stream_stderr
|
bool
|
Whether to merge stderr into stdout |
False
|
**kwargs
|
Any
|
Additional subprocess arguments |
{}
|
Yields:
| Type | Description |
|---|---|
AsyncIterator[str]
|
Lines of output from the command |
Raises:
| Type | Description |
|---|---|
ProcessError
|
If command fails |
ProcessTimeoutError
|
If timeout is exceeded |