Skip to main content

Convenience methods for file/process operations

Project description

Convenience methods for file/process operations

Version on pypi Travis CI codecov Python versions tested (link to github project)


runez is a small convenience library for common operations I found myself rewriting multiple times.

It comes in handy for programs that need to run other programs, or copy/move files etc.

The name was initially meant as “run ez” (“run easy”), the fact that it sounds like “runes” gives it a bit of a mystery/magic side that’s also relatively appropriate (it does indeed concentrate a bit of invocation magic, as you can save quite a few lines of repetitive code by using it)


  • Support for dryrun mode (show what would be done, but don’t do it)

  • Perform most typical logging setups in one call to runez.log.setup()

  • Log operations systematically (at debug level mostly), examples:

    Running: foo ...
    Copy foo -> bar
    Would move foo -> bar    (for dryrun)
  • CaptureOutput context manager -> grab output/logging from any code section

  • Take care of most edge cases, with nice errors

  • Functions can be called without checking for return code etc (abort by default, with nice error)

  • They can also be called with fatal=False, in which case the return value will indicate whether call succeeded or not

  • 100% test coverage


Run a program:

import runez

# Aborts if "foo" doesn't exist
output ="ls", "foo")

# Output can also be ignored"ls", "foo")

# Don't capture output, just run the command and let output "pass through""ls", "foo", stdout=None, stderr=None)

# Don't abort, return False on failure (or actual output when successful)
output ="ls", "foo", fatal=False)

File operations:

import runez

runez.copy("foo", "bar")
runez.move("foo", "baz")

runez.write("foo", "bar\nbaz\n")
first = runez.first_line("foo")
lines = runez.get_lines("foo")

full_path = runez.resolved_path("foo/bar")
folder = runez.parent_folder(full_path)
with runez.Anchored(folder):
    assert runez.short(full_path) == "bar"


As usual, available on pypi: pip install runez

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for runez, version 1.10.22
Filename, size File type Python version Upload date Hashes
Filename, size runez-1.10.22-py2.py3-none-any.whl (62.7 kB) File type Wheel Python version py2.py3 Upload date Hashes View hashes
Filename, size runez-1.10.22.tar.gz (53.4 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page