pycliwrapper


Namepycliwrapper JSON
Version 1.1 PyPI version JSON
download
home_page
SummaryWrap any CLI tool to Python like syntax
upload_time2023-05-26 07:48:46
maintainer
docs_urlNone
authorJordi Deu-Pons
requires_python
licenseApache License 2.0
keywords cli wrapper
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Generic Python CLI Wrapper

Wrap any CLI tool to Python like syntax.

## Quick start

```python
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

```python
# 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

```python
# 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"))
```


            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "pycliwrapper",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "cli,wrapper",
    "author": "Jordi Deu-Pons",
    "author_email": "",
    "download_url": "https://files.pythonhosted.org/packages/6b/21/10f70910a61c92d343866637402dab75d4d9def785c28a76bbe108295f63/pycliwrapper-1.1.tar.gz",
    "platform": null,
    "description": "# Generic Python CLI Wrapper\n\nWrap any CLI tool to Python like syntax.\n\n## Quick start\n\n```python\nfrom pycliwrapper import CliWrapper\napt_cache = CliWrapper(\"apt-cache\", parser=lambda stdout: stdout.splitlines())\n\n# Equivalent to run: \"apt-cache search bash\" and parsing\n# the output as a list\nres = ~apt_cache.search.bash\nprint(res)\n```\n\n## Parsing output as JSON\n\n```python\n# Build a wrapper on top of main command\ntw = CliWrapper(\"tw -o json\", parser=json.loads)\n\n# Build the command that you want to execute\n# using Python syntax. A dot means a subcommand and\n# flags are pass as normal python variables.\nprint(\"PIPELINES\")\ncmd = tw.pipelines.list(filter=\"hello\")\n\n# You can see the actual command that will be run\n# >> tw -o json pipelines list --filter=\"hello\"\nprint(f\"Executing: {cmd}\")\n\n# Execute it using the ~ operator and automatically\n# parse the output with the given parser\nprint(~cmd)\n\n# Build and execute the command in one line\n# >> tw -o json compute-envs list\nprint(~tw.compute_envs.list)\n\n# Mixing positional and flag arguments\n# >> tw -o json launch nf-core-nanoseq --workspace=\"community/showcase\"\nprint(~tw.launch(\"nf-core-nanoseq\", workspace=\"community/showcase\"))\n\n# More complex example\n# >> tw -o json runs view -i 2gHGbjH9fRDuaW task -t=1 --execution-time\nprint(~tw.runs.view(i=\"2gHGbjH9fRDuaW\").task(t=1, execution_time=True))\n```\n\n## Non standard CLI support\n\n```python\n# Build a wrapper on top of main command\nnextflow = CliWrapper(\"nextflow\")\n\n# Hello world\n# >> nextflow run \"nextflow-io/hello\"\nprint(~nextflow.run(\"nextflow-io/hello\"))\n\n# Mixing Nextflow options and pipeline options\n# >> nextflow run \"nf-core/rnaseq\" -profile \"docker,test\" -r \"3.10.1\" --outdir=\"./results\"\n# TIP: the _ at the beginning means that you want to use a \"-\" instead of a \"--\" even if the key has more than one character\n# TIP: the _ at the end means that you want to use a \" \" instead of a \"=\" even if the key has more than one character\nprint(~nextflow.run(\"nf-core/rnaseq\", _profile_=\"docker,test\", _r_=\"3.10.1\", outdir=\"./results\"))\n```\n\n",
    "bugtrack_url": null,
    "license": "Apache License 2.0",
    "summary": "Wrap any CLI tool to Python like syntax",
    "version": "1.1",
    "project_urls": null,
    "split_keywords": [
        "cli",
        "wrapper"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "6b2110f70910a61c92d343866637402dab75d4d9def785c28a76bbe108295f63",
                "md5": "680b5a2eabe4a3ebb3f04f2430e59774",
                "sha256": "5e34252a9a4a45b8ed5ba333e1dbbc70f059e65e327a4039293286dd8dcffa59"
            },
            "downloads": -1,
            "filename": "pycliwrapper-1.1.tar.gz",
            "has_sig": false,
            "md5_digest": "680b5a2eabe4a3ebb3f04f2430e59774",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 2830,
            "upload_time": "2023-05-26T07:48:46",
            "upload_time_iso_8601": "2023-05-26T07:48:46.762169Z",
            "url": "https://files.pythonhosted.org/packages/6b/21/10f70910a61c92d343866637402dab75d4d9def785c28a76bbe108295f63/pycliwrapper-1.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-05-26 07:48:46",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "pycliwrapper"
}
        
Elapsed time: 1.57161s