Skip to main content

Delegator.py — Subprocesses for Humans 2.0
=======================================


.. image:: https://img.shields.io/pypi/v/delegator.py.svg
:target: https://pypi.python.org/pypi/delegator.py

.. image:: https://img.shields.io/pypi/l/delegator.py.svg
:target: https://pypi.python.org/pypi/delegator.py

.. image:: https://img.shields.io/pypi/wheel/delegator.py.svg
:target: https://pypi.python.org/pypi/delegator.py

.. image:: https://img.shields.io/pypi/pyversions/delegator.py.svg
:target: https://pypi.python.org/pypi/delegator.py

.. image:: https://img.shields.io/badge/SayThanks.io-☼-1EAEDB.svg
:target: https://saythanks.io/to/kennethreitz


**Delegator.py** is a simple library for dealing with subprocesses, inspired
by both `envoy <https://github.com/kennethreitz/envoy>`_ and `pexpect <http://pexpect.readthedocs.io>`_ (in fact, it depends on it!).

This module features two main functions ``delegator.run()`` and ``delegator.chain()``. One runs commands, blocking or non-blocking, and the other runs a chain of commands, separated by the standard unix pipe operator: ``|``.

If you're interested in financially supporting Kenneth Reitz open source, consider `visiting this link <https://cash.me/$KennethReitz>`_. Your support helps tremendously with sustainability of motivation, as Open Source is no longer part of my day job.

Basic Usage
-----------

Basic run functionality:

.. code:: pycon

>>> c = delegator.run('ls')
>>> print c.out
README.rst delegator.py

>>> c = delegator.run('long-running-process', block=False)
>>> c.pid
35199
>>> c.block()
>>> c.return_code
0

Commands can be passed in as lists as well (e.g. ``['ls', '-lrt']``), for parameterization.

Basic chain functionality:

.. code:: pycon

# Can also be called with ([['fortune'], ['cowsay']]).
# or, delegator.run('fortune').pipe('cowsay')

>>> c = delegator.chain('fortune | cowsay')
>>> print c.out
_______________________________________
/ Our swords shall play the orators for \
| us. |
| |
\ -- Christopher Marlowe /
---------------------------------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||


Expect functionality is built-in too, on non-blocking commands:

.. code:: pycon

>>> c.expect('Password:')
>>> c.send('PASSWORD')
>>> c.block()

Other functions:

.. code:: pycon

>>> c.kill()
>>> c.send('SIGTERM', signal=True)

# Only available when block=True, otherwise, use c.out.
>>> c.err
''

# Direct access to pipes.
>>> c.std_err
<open file '<fdopen>', mode 'rU' at 0x10a5351e0>

# Adjust environment variables for the command (existing will be overwritten).
>>> c = delegator.chain('env | grep NEWENV', env={'NEWENV': 'FOO_BAR'})
>>> c.out
NEWENV=FOO_BAR



Installation
------------

::

$ pip install delegator.py

✨🍰✨


Release files for delegator.py 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for delegator.py 0.1.1
File Size Uploaded
delegator.py-0.1.1.tar.gz 6.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for delegator.py 0.1.1
File Interpreter ABI Platform
delegator.py-0.1.1-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 11.3 kB

Release files / delegator.py-0.1.1.tar.gz

Download URL delegator.py-0.1.1.tar.gz
Size 6.3 kB
Tags Source
SHA-256 checksum
How to use checksums
e6cc9cedab9ae59b169ee0422e17231adedadb144e63c0b5a60e6ff8adf8521b
BLAKE2b-256 checksum
How to use checksums
0829199c7e8efd277eb00d842cb735c65f1d3d1c070e4903b0e44b30ca8e2604
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.7.0

Release files / delegator.py-0.1.1-py2.py3-none-any.whl

Download URL delegator.py-0.1.1-py2.py3-none-any.whl
Size 5.0 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
814657d96b98a244c479e3d5f6e9e850ac333e85f807d6bc846e72bbb2537806
BLAKE2b-256 checksum
How to use checksums
a7c22860c52ef858c4672b6cf637f473e9139342cdb281135db9b3c32cfb0a85
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.7.0

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

2 release files

0.0.14

2 release files

0.0.13

2 release files

0.0.10

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page