qsv-duct


Nameqsv-duct JSON
Version 0.0.2 PyPI version JSON
download
home_pageNone
SummaryPython wrapper based on the qsv CLI tool
upload_time2024-06-03 10:41:37
maintainerNone
docs_urlNone
authorMueez Khan
requires_pythonNone
licenseNone
keywords qsv csv
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # qsv-duct

Python wrapper you may use to call [qsv](https://github.com/jqnatividad/qsv) commands using [duct.py](https://github.com/oconnor663/duct.py) for composability.

This library is compatible with qsv v0.128.0. Not all commands are available (see [`src/qsv/__init__.py`](src/qsv/__init__.py) for available commands).

**Make sure you have qsv installed on your system first and can access it anywhere as a `PATH` command.**

To install this library run:

```bash
pip install qsv-duct
```

## Basic example

We have a file `fruits.csv` with the following contents:

```csv
fruit,price
apple,2.50
banana,3.00
strawberry,1.50
```

Let's count the total number of non-header rows in `fruits.csv` using `qsv.count`:

```python
import qsv

qsv.count("fruits.csv", run=True)
```

The following output gets printed to stdout:

```console
3
```

## Reading output to a variable

You may want to save the output value to a variable and use it in your code. Use the `read` parameter instead of `run`. For example:

```python
non_header_row_count = qsv.count("fruits.csv", read=True)
print(non_header_row_count)
```

## Piping commands

Since this library uses duct.py, you may access the command as an `Expression` type by not passing `read` and `run`.

For example, let's say we want to get the first two rows of `fruits.csv` with `qsv.slice`. Normally we would use `run` to run the command:

```python
qsv.slice("fruits.csv", length=2, run=True)
```

```console
fruit,price
apple,2.50
banana,3.00
```

If we want to display this output in a pretty format, we can pipe `qsv.slice` into `qsv.table`:

```python
qsv.slice("fruits.csv", length=2).pipe(qsv.table()).run()
```

```console
fruit   price
apple   2.50
banana  3.00
```

If you use the `duct.py` library you can also pipe qsv commands with other bash-related commands using the `duct` library's `cmd` function. For example:

```python
import qsv
from duct import cmd

cmd("cat", "fruits.csv").pipe(qsv.table()).run()
```

```console
fruit       price
apple       2.50
banana      3.00
strawberry  1.50
```

## Testing

You can run the tests with the pytest package:

```bash
pytest
```


            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "qsv-duct",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "qsv, csv",
    "author": "Mueez Khan",
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/56/10/8a6d585228045a067245978fee72a6e127602103e40942fba3c4ff3cc3f4/qsv_duct-0.0.2.tar.gz",
    "platform": null,
    "description": "# qsv-duct\n\nPython wrapper you may use to call [qsv](https://github.com/jqnatividad/qsv) commands using [duct.py](https://github.com/oconnor663/duct.py) for composability.\n\nThis library is compatible with qsv v0.128.0. Not all commands are available (see [`src/qsv/__init__.py`](src/qsv/__init__.py) for available commands).\n\n**Make sure you have qsv installed on your system first and can access it anywhere as a `PATH` command.**\n\nTo install this library run:\n\n```bash\npip install qsv-duct\n```\n\n## Basic example\n\nWe have a file `fruits.csv` with the following contents:\n\n```csv\nfruit,price\napple,2.50\nbanana,3.00\nstrawberry,1.50\n```\n\nLet's count the total number of non-header rows in `fruits.csv` using `qsv.count`:\n\n```python\nimport qsv\n\nqsv.count(\"fruits.csv\", run=True)\n```\n\nThe following output gets printed to stdout:\n\n```console\n3\n```\n\n## Reading output to a variable\n\nYou may want to save the output value to a variable and use it in your code. Use the `read` parameter instead of `run`. For example:\n\n```python\nnon_header_row_count = qsv.count(\"fruits.csv\", read=True)\nprint(non_header_row_count)\n```\n\n## Piping commands\n\nSince this library uses duct.py, you may access the command as an `Expression` type by not passing `read` and `run`.\n\nFor example, let's say we want to get the first two rows of `fruits.csv` with `qsv.slice`. Normally we would use `run` to run the command:\n\n```python\nqsv.slice(\"fruits.csv\", length=2, run=True)\n```\n\n```console\nfruit,price\napple,2.50\nbanana,3.00\n```\n\nIf we want to display this output in a pretty format, we can pipe `qsv.slice` into `qsv.table`:\n\n```python\nqsv.slice(\"fruits.csv\", length=2).pipe(qsv.table()).run()\n```\n\n```console\nfruit   price\napple   2.50\nbanana  3.00\n```\n\nIf you use the `duct.py` library you can also pipe qsv commands with other bash-related commands using the `duct` library's `cmd` function. For example:\n\n```python\nimport qsv\nfrom duct import cmd\n\ncmd(\"cat\", \"fruits.csv\").pipe(qsv.table()).run()\n```\n\n```console\nfruit       price\napple       2.50\nbanana      3.00\nstrawberry  1.50\n```\n\n## Testing\n\nYou can run the tests with the pytest package:\n\n```bash\npytest\n```\n\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Python wrapper based on the qsv CLI tool",
    "version": "0.0.2",
    "project_urls": {
        "Home": "https://github.com/rzmk/qsv-duct"
    },
    "split_keywords": [
        "qsv",
        " csv"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b65d92534603eb69c6fb6e1c409730e72f0f59fce7b1e1a44345f77d0b3e64d1",
                "md5": "eb9ecf40327e8b0b2ea67fcaed817fc6",
                "sha256": "d482715e099ac2b32041a72c19974f792c58cbb90eeafc8c853a6fd41ea08285"
            },
            "downloads": -1,
            "filename": "qsv_duct-0.0.2-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "eb9ecf40327e8b0b2ea67fcaed817fc6",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": null,
            "size": 8211,
            "upload_time": "2024-06-03T10:41:36",
            "upload_time_iso_8601": "2024-06-03T10:41:36.579819Z",
            "url": "https://files.pythonhosted.org/packages/b6/5d/92534603eb69c6fb6e1c409730e72f0f59fce7b1e1a44345f77d0b3e64d1/qsv_duct-0.0.2-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "56108a6d585228045a067245978fee72a6e127602103e40942fba3c4ff3cc3f4",
                "md5": "34bc8c1de3e7fc2f8c8854f98683ad39",
                "sha256": "b92c46c637164e8c65fe2c6900414b494f8a648429d249951bde42e4bf339967"
            },
            "downloads": -1,
            "filename": "qsv_duct-0.0.2.tar.gz",
            "has_sig": false,
            "md5_digest": "34bc8c1de3e7fc2f8c8854f98683ad39",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 5395,
            "upload_time": "2024-06-03T10:41:37",
            "upload_time_iso_8601": "2024-06-03T10:41:37.770066Z",
            "url": "https://files.pythonhosted.org/packages/56/10/8a6d585228045a067245978fee72a6e127602103e40942fba3c4ff3cc3f4/qsv_duct-0.0.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-06-03 10:41:37",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "rzmk",
    "github_project": "qsv-duct",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "qsv-duct"
}
        
Elapsed time: 0.26140s