Skip to main content

Proclet

Proclet is a fluent, typed wrapper around Python's subprocess, with matching sync and async APIs, binary-safe pipelines, privilege dropping and low-priority execution.

pypi version python versions continuous integration no runtime dependencies license

🚀 Quick start

Requires Python 3.12 or newer, on Linux, macOS or Windows. No runtime dependency.

pip install proclet

Or with another package manager:

uv add proclet
poetry add proclet
pdm add proclet
pipenv install proclet
import asyncio
from io import StringIO
from proclet import Command

# Run a command and capture its output.
out = StringIO()
Command("git").args("rev-parse", "HEAD").stdout(out).timeout(10).exec()
print(out.getvalue().strip())

# Chain commands through raw OS pipes, no shell involved.
Command("git").args("log", "--format=%an").pipe(
    Command("sort").args("-u").inherit_out()
)

# Run the same configuration with asyncio.
asyncio.run(Command("git").args("fetch", "--all").inherit_out().aexec())
  • A failing command raises ErrorReturnCode, a missing binary CommandNotFound and an elapsed timeout TimeoutException.
  • The usage section covers each feature in detail; the documentation site adds recipes, migration guides and the API reference.

✨ Features

  • Fluent and typed: configure a command through a chainable API, checked by your type checker.
  • Sync and async: run the same Command with exec() or await aexec().
  • Output anywhere: redirect to files, file objects, StringIO/BytesIO or a callable receiving each line.
  • Input from anywhere: feed stdin from a string, bytes, a file object or a queue.
  • Shell-free pipelines: chain commands through raw OS pipes, safe for binary payloads.
  • Guard rails: enforce timeouts and choose the exit codes that count as success.
  • Environment control: build a command's environment and PATH from the current ones.
  • Privilege dropping: run as another user, group and set of supplementary groups.
  • Low priority: lower the CPU (and, on Linux, IO) priority of a command, Windows included.
  • Typed wrappers: turn a binary into a Python API of its own with Bind.
  • Observability: get notified of every process spawn and exit.

🎯 Motivation

  • We needed a way to run external tools from Python code without repeating subprocess boilerplate.
  • Redirecting output to a logger, feeding stdin from a queue or chaining binary-safe pipelines shouldn't require hand-written threads.
  • The same API should serve sync and asyncio code.
  • The library should stay framework-agnostic: no runtime dependencies, no logging setup, failures are exceptions the caller decides about.

Streaming a database dump through a compressor, logging both tools' stderr line by line, with a timeout and an exit code check, looks like this with subprocess:

import logging
import subprocess
import threading

log = logging.getLogger(__name__)

dump = subprocess.Popen(
    ["pg_dump", "shop"], stdout=subprocess.PIPE, stderr=subprocess.PIPE
)
pack = subprocess.Popen(
    ["zstd", "-q", "-o", "shop.sql.zst"], stdin=dump.stdout, stderr=subprocess.PIPE
)
dump.stdout.close()  # let pg_dump see a broken pipe if zstd dies


def forward(stream):
    for line in stream:
        log.warning(line.decode().rstrip("\n"))


threads = [threading.Thread(target=forward, args=(p.stderr,)) for p in (dump, pack)]
for thread in threads:
    thread.start()
try:
    dump.wait(timeout=600)
    pack.wait(timeout=600)
finally:
    for process in (dump, pack):
        if process.poll() is None:
            process.kill()
    for thread in threads:
        thread.join()
for process in (dump, pack):
    if process.returncode != 0:
        raise RuntimeError(f"{process.args} exited with {process.returncode}")

With proclet:

import logging
from proclet import Command, strip_redirect

log = logging.getLogger(__name__)
to_log = strip_redirect(log.warning)

Command("pg_dump").args("shop").stderr(to_log).timeout(600).pipe(
    Command("zstd").args("-q", "-o", "shop.sql.zst").stderr(to_log).timeout(600)
)

Compared to other libraries

subprocess sh plumbum invoke proclet
Style function arguments commands as functions local["git"] objects and operators shell command strings chainable builder
Windows yes no yes yes yes
asyncio separate API _async=True separate async commands no same Command (aexec())
Pipelines without a shell hand-wired Popens yes yes no yes, raw OS pipes
Run as another user user= _uid= no no user()
Choose the group and supplementary groups group=, extra_groups= no no no group(), extra_groups()
Lower the priority by hand (preexec_fn) no no no nice(), Windows included
  • Checked against sh 2.4, plumbum 2.0 and invoke 3.0. invoke is mainly a task runner and plumbum also covers CLI apps and remote machines: pick them for that.
  • Spotted a mistake? Please open an issue.

📖 Usage

The documentation site covers every feature with examples:

It also has recipes for common problems (streaming output to a logger, timeouts, binary pipes, running as another user, concurrency with asyncio, wrapping a CLI), migration guides from sh and from plumbum, and the API reference.

❤️ Contributing

If you find this project useful here's how you can help, please click the 👁️ Watch button to avoid missing notifications about new versions, and give it a 🌟 GitHub Star!

You can also contribute by:

  • Sending a Pull Request with your awesome new features and bug fixed.
  • Be part of the community and help resolve Issues.

Read CONTRIBUTING.md to set up the project and check your changes before opening a pull request.

🧾 License

The proclet project is free and open-source software licensed under the Apache-2.0 license.

Metadata

Release files for proclet 0.1.2

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

Source distribution (sdist)

Source distribution for proclet 0.1.2
File Size Uploaded Provenance Actions
proclet-0.1.2.tar.gz 28.2 kB With provenance Details for proclet-0.1.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for proclet 0.1.2
File Interpreter ABI Platform Actions
proclet-0.1.2-py3-none-any.whl Python 3 none any Details for proclet-0.1.2-py3-none-any.whl

Total release size: 56.3 kB

Release files / proclet-0.1.2.tar.gz

Download URL proclet-0.1.2.tar.gz
Size 28.2 kB
Tags Source
SHA-256 checksum
How to use checksums
1ec51d8ecf0c54d0048d9c2b95e4363cd52e1a0e978e21acbc316c6993f9e2b4
BLAKE2b-256 checksum
How to use checksums
1e942aadbd62d3c65e3d3e88dd20880c13a2db2feb59002de5b04aee8053d3e3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 27, 2026.

Transparency log

Release files / proclet-0.1.2-py3-none-any.whl

Download URL proclet-0.1.2-py3-none-any.whl
Size 28.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
aae65a027b2ab8f0999eb5987dc91e2af229739a8a105ea8c33a6ca3c6c523cd
BLAKE2b-256 checksum
How to use checksums
50f2079d2ee78d49e7f661a0e6737730e61c41f1f5b73bde48799c9aeea0fa09
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 27, 2026.

Transparency log

Security for proclet 0.1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for proclet-0.1.2.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 27, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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