Skip to main content

Python wrapper based on the qsv CLI tool

Project description

qsv-duct

Python wrapper you may use to call qsv commands using duct.py for composability.

This library is compatible with qsv v0.128.0. Not all commands are available (see 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:

pip install qsv-duct

Basic example

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

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:

import qsv

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

The following output gets printed to stdout:

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:

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:

qsv.slice("fruits.csv", length=2, run=True)
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:

qsv.slice("fruits.csv", length=2).pipe(qsv.table()).run()
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:

import qsv
from duct import cmd

cmd("cat", "fruits.csv").pipe(qsv.table()).run()
fruit       price
apple       2.50
banana      3.00
strawberry  1.50

Testing

You can run the tests with the pytest package:

pytest

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

qsv_duct-0.0.2.tar.gz (5.4 kB view hashes)

Uploaded Source

Built Distribution

qsv_duct-0.0.2-py2.py3-none-any.whl (8.2 kB view hashes)

Uploaded Python 2 Python 3

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