Skip to main content

Wrap any CLI tool to Python like syntax

Project description

Generic Python CLI Wrapper

Wrap any CLI tool to Python like syntax.

Quick start

from pycliwrapper import CliWrapper
apt_cache = CliWrapper("apt-cache", parser=lambda stdout: stdout.splitlines())

# Equivalent to run: "apt-cache search bash" and parsing
# the output as a list
res = ~apt_cache.search.bash
print(res)

Parsing output as JSON

# Build a wrapper on top of main command
tw = CliWrapper("tw -o json", parser=json.loads)

# Build the command that you want to execute
# using Python syntax. A dot means a subcommand and
# flags are pass as normal python variables.
print("PIPELINES")
cmd = tw.pipelines.list(filter="hello")

# You can see the actual command that will be run
# >> tw -o json pipelines list --filter="hello"
print(f"Executing: {cmd}")

# Execute it using the ~ operator and automatically
# parse the output with the given parser
print(~cmd)

# Build and execute the command in one line
# >> tw -o json compute-envs list
print(~tw.compute_envs.list)

# Mixing positional and flag arguments
# >> tw -o json launch nf-core-nanoseq --workspace="community/showcase"
print(~tw.launch("nf-core-nanoseq", workspace="community/showcase"))

# More complex example
# >> tw -o json runs view -i 2gHGbjH9fRDuaW task -t=1 --execution-time
print(~tw.runs.view(i="2gHGbjH9fRDuaW").task(t=1, execution_time=True))

Non standard CLI support

# Build a wrapper on top of main command
nextflow = CliWrapper("nextflow")

# Hello world
# >> nextflow run "nextflow-io/hello"
print(~nextflow.run("nextflow-io/hello"))

# Mixing Nextflow options and pipeline options
# >> nextflow run "nf-core/rnaseq" -profile "docker,test" -r "3.10.1" --outdir="./results"
# TIP: the _ at the beginning means that you want to use a "-" instead of a "--" even if the key has more than one character
# TIP: the _ at the end means that you want to use a " " instead of a "=" even if the key has more than one character
print(~nextflow.run("nf-core/rnaseq", _profile_="docker,test", _r_="3.10.1", outdir="./results"))

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

pycliwrapper-1.1.tar.gz (2.8 kB view details)

Uploaded Source

File details

Details for the file pycliwrapper-1.1.tar.gz.

File metadata

  • Download URL: pycliwrapper-1.1.tar.gz
  • Upload date:
  • Size: 2.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 colorama/0.4.4 importlib-metadata/4.6.4 keyring/23.5.0 pkginfo/1.8.2 readme-renderer/34.0 requests-toolbelt/0.9.1 requests/2.25.1 rfc3986/1.5.0 tqdm/4.57.0 urllib3/1.26.5 CPython/3.10.6

File hashes

Hashes for pycliwrapper-1.1.tar.gz
Algorithm Hash digest
SHA256 5e34252a9a4a45b8ed5ba333e1dbbc70f059e65e327a4039293286dd8dcffa59
MD5 680b5a2eabe4a3ebb3f04f2430e59774
BLAKE2b-256 6b2110f70910a61c92d343866637402dab75d4d9def785c28a76bbe108295f63

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page