I currently do:
(local['echo'][var] | sth)()
Which seems inelegant and inefficient.
I found the solution in the plumbum documentation:
You can use the shift-left operator <<
.
from plumbum import local
if __name__ == '__main__':
var = "some text in a python variable"
sth = local["cat"]
x = (local['echo'][var] | sth)()
print(x)
print("alternative:")
x = (sth << var)()
print(x)