qck


Nameqck JSON
Version 2024.4.15 PyPI version JSON
download
home_pagehttps://github.com/dnouri/qck
SummaryCLI to conveniently run DuckDB SQL scripts with support for templating
upload_time2024-04-15 15:50:34
maintainerNone
docs_urlNone
authorDaniel Nouri
requires_pythonNone
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Qck πŸ¦†πŸ‘©β€πŸ’»

Qck (pronounced "quack") is a CLI script to conveniently run
[DuckDB](https://duckdb.org/) SQL scripts with support for
[Jina](https://jinja.palletsprojects.com/) templating.

## πŸ› οΈ Installation

Use `pip install qck` to install.  This will make available the `qck`
script.

## πŸš€ Usage

Run `qck --help` to view the built-in documentation.

Running `qck` with just a SQL file will execute the query and print
the results to the terminal:

```bash
qck myquery.sql
```

The default is to `LIMIT` the output to 100 lines.  You can override
this with the `--limit` option:

```bash
qck myquery.sql --limit 10  # will only print 10 rows
```

To execute a query and write the result to a Parquet file, use
`--to-parquet`:

```bash
qck myquery.sql --to-parquet myresult.parquet
```

You can also call `qck` from within Python:

```python
from qck import qck
rs = qck("myquery.sql")
rs.to_parquet("myresult.parquet")
```

For a full list of arguments to `qck`, please refer to the
[source](qck.py).

## πŸ–‹οΈ Templating

Qck can interpret SQL files as Jinja templates, enabling the use of
control structures like for loops within SQL files. Additionally, Qck
introduces a special variable, `import`, in templates, enabling access
to arbitrary Python functions. For instance, consider the following
example, where we import the `glob` function and utilize it to list
files to query from:

```jinja
{% for fname in import('glob.glob')('data/*xlsx') %}
SELECT
    "Value" AS value,
    "RΓ©gion" AS region,
FROM
    st_read('{{ fname }}')
{% if not loop.last %}
UNION ALL
{% endif %}
{% endfor %}
```
            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/dnouri/qck",
    "name": "qck",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": null,
    "author": "Daniel Nouri",
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/b0/c9/c4e73230cf8831b9e7782155cef475813bf09ac4a90cb40770ba8022fc38/qck-2024.4.15.tar.gz",
    "platform": null,
    "description": "# Qck \ud83e\udd86\ud83d\udc69\u200d\ud83d\udcbb\n\nQck (pronounced \"quack\") is a CLI script to conveniently run\n[DuckDB](https://duckdb.org/) SQL scripts with support for\n[Jina](https://jinja.palletsprojects.com/) templating.\n\n## \ud83d\udee0\ufe0f Installation\n\nUse `pip install qck` to install.  This will make available the `qck`\nscript.\n\n## \ud83d\ude80 Usage\n\nRun `qck --help` to view the built-in documentation.\n\nRunning `qck` with just a SQL file will execute the query and print\nthe results to the terminal:\n\n```bash\nqck myquery.sql\n```\n\nThe default is to `LIMIT` the output to 100 lines.  You can override\nthis with the `--limit` option:\n\n```bash\nqck myquery.sql --limit 10  # will only print 10 rows\n```\n\nTo execute a query and write the result to a Parquet file, use\n`--to-parquet`:\n\n```bash\nqck myquery.sql --to-parquet myresult.parquet\n```\n\nYou can also call `qck` from within Python:\n\n```python\nfrom qck import qck\nrs = qck(\"myquery.sql\")\nrs.to_parquet(\"myresult.parquet\")\n```\n\nFor a full list of arguments to `qck`, please refer to the\n[source](qck.py).\n\n## \ud83d\udd8b\ufe0f Templating\n\nQck can interpret SQL files as Jinja templates, enabling the use of\ncontrol structures like for loops within SQL files. Additionally, Qck\nintroduces a special variable, `import`, in templates, enabling access\nto arbitrary Python functions. For instance, consider the following\nexample, where we import the `glob` function and utilize it to list\nfiles to query from:\n\n```jinja\n{% for fname in import('glob.glob')('data/*xlsx') %}\nSELECT\n    \"Value\" AS value,\n    \"R\u00e9gion\" AS region,\nFROM\n    st_read('{{ fname }}')\n{% if not loop.last %}\nUNION ALL\n{% endif %}\n{% endfor %}\n```",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "CLI to conveniently run DuckDB SQL scripts with support for templating",
    "version": "2024.4.15",
    "project_urls": {
        "Homepage": "https://github.com/dnouri/qck"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b0c9c4e73230cf8831b9e7782155cef475813bf09ac4a90cb40770ba8022fc38",
                "md5": "b56b906d2b7a2039087d684d603e15b1",
                "sha256": "d586c48f0033659eede554f2a076b5b1463996708a7c2b51879e4c0aef450014"
            },
            "downloads": -1,
            "filename": "qck-2024.4.15.tar.gz",
            "has_sig": false,
            "md5_digest": "b56b906d2b7a2039087d684d603e15b1",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 4578,
            "upload_time": "2024-04-15T15:50:34",
            "upload_time_iso_8601": "2024-04-15T15:50:34.511026Z",
            "url": "https://files.pythonhosted.org/packages/b0/c9/c4e73230cf8831b9e7782155cef475813bf09ac4a90cb40770ba8022fc38/qck-2024.4.15.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-15 15:50:34",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "dnouri",
    "github_project": "qck",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "qck"
}
        
Elapsed time: 0.37388s