Skip to main content

a library for running child processes

Project description

duct.py Actions Status PyPI version Documentation Status

Duct is a library for running child processes. Duct makes it easy to build pipelines and redirect IO like a shell. At the same time, Duct helps you write correct, portable code: whitespace is never significant, errors from child processes get reported by default, and a variety of gotchas, bugs, and platform inconsistencies are handled for you the Right Way™.

Examples

Run a command without capturing any output. Here "hi" is printed directly to the terminal:

>>> from duct import cmd
>>> cmd("echo", "hi").run()
hi
Output(status=0, stdout=None, stderr=None)

Capture the standard output of a command. Here "hi" is returned as a string:

>>> cmd("echo", "hi").read()
'hi'

Capture the standard output of a pipeline:

>>> cmd("echo", "hi").pipe(cmd("sed", "s/i/o/")).read()
'ho'

Merge standard error into standard output and read both incrementally:

>>> big_cmd = cmd("bash", "-c", "echo out && echo err 1>&2")
>>> reader = big_cmd.stderr_to_stdout().reader()
>>> with reader:
...     reader.readlines()
[b'out\n', b'err\n']

Children that exit with a non-zero status raise an exception by default:

>>> cmd("false").run()
Traceback (most recent call last):
...
duct.StatusError: Expression cmd('false') returned non-zero exit status: Output(status=1, stdout=None, stderr=None)
>>> cmd("false").unchecked().run()
Output(status=1, stdout=None, stderr=None)

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

duct-1.0.1.tar.gz (17.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

duct-1.0.1-py3-none-any.whl (17.9 kB view details)

Uploaded Python 3

File details

Details for the file duct-1.0.1.tar.gz.

File metadata

  • Download URL: duct-1.0.1.tar.gz
  • Upload date:
  • Size: 17.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for duct-1.0.1.tar.gz
Algorithm Hash digest
SHA256 a46839355f82585e64f348ac6401f1ec21ab19c186e661d161d4e9ceb3a240d7
MD5 29295e6942970258a6fd9473368f5c9f
BLAKE2b-256 0368505d551c5c7e6ba31b0e176861ea9f87fed45c6357e42e0f3cb436f30ec1

See more details on using hashes here.

File details

Details for the file duct-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: duct-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 17.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for duct-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ce8a93bd4b081b0244cd71c337edc4d6df78dc6d20b42da283e984780a5e9b1e
MD5 74cefff97a5e7253793654c39bc29a6a
BLAKE2b-256 f9b95e71b1f3149916e73523b43e150e33ddd6ed4da38b96ee0a746f08471881

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