{"id":23907622,"url":"https://github.com/bradleybonitatibus/qtrex","last_synced_at":"2026-04-14T15:33:49.278Z","repository":{"id":110263927,"uuid":"553296404","full_name":"bradleybonitatibus/qtrex","owner":"bradleybonitatibus","description":"Query template rendering and execution library written in Python","archived":false,"fork":false,"pushed_at":"2023-08-17T20:43:54.000Z","size":73,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-09-03T10:57:20.258Z","etag":null,"topics":["google-bigquery","python","sql","yaml"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bradleybonitatibus.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-10-18T02:21:10.000Z","updated_at":"2023-08-18T14:01:57.000Z","dependencies_parsed_at":null,"dependency_job_id":"bc657532-697c-48c8-b9df-1307a3b59a60","html_url":"https://github.com/bradleybonitatibus/qtrex","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/bradleybonitatibus/qtrex","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bradleybonitatibus%2Fqtrex","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bradleybonitatibus%2Fqtrex/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bradleybonitatibus%2Fqtrex/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bradleybonitatibus%2Fqtrex/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bradleybonitatibus","download_url":"https://codeload.github.com/bradleybonitatibus/qtrex/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bradleybonitatibus%2Fqtrex/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31803512,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-14T11:13:53.975Z","status":"ssl_error","status_checked_at":"2026-04-14T11:13:53.299Z","response_time":153,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["google-bigquery","python","sql","yaml"],"created_at":"2025-01-05T03:13:32.787Z","updated_at":"2026-04-14T15:33:49.273Z","avatar_url":"https://github.com/bradleybonitatibus.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# qtrex\n[![CI](https://github.com/bradleybonitatibus/qtrex/actions/workflows/ci.yml/badge.svg)](https://github.com/bradleybonitatibus/qtrex/actions/workflows/ci.yml)\n\n[![PyPI version](https://badge.fury.io/py/qtrex.svg)](https://badge.fury.io/py/qtrex)\n\nQuery template rendering and execution library written in Python.\n\nThe goal of `qtrex` is to provide a simple API that supports loading `.sql`\nfiles that can be templated with `jinja`, and provide extensible configuration\noptions to either compile the files, and execute the rendered templates against\nvarious databases.\n\n## Getting Started\n\n`qtrex` is installable at https://pypi.org/project/qtrex/ via `pip` using:\n\nWe currently only support `bigquery`, but plan on adding other DB support as\noptional dependencies.\n\n```\npip install 'qtrex[bigquery]==0.0.5'\n```\n\n## Examples\n\nHere is a brief example usage of `qtrex`. \n\nAssuming you have query templates in a directory on a local filesystem, using\nour test suite as an example:\n\n```text\n|tests\n    |--test_*.py\n    |--testdata\n        |--mytemplate.sql\n        |--ingest\n            |--another_file_ext.j2\n            |--another_query.sql\n```\n\nWhere `./tests/testdata/mytemplate.sql` has the following contents:\n```sql\nSELECT SUM(x)\nFROM UNNEST({{ params.test_array }}) AS x\n```\nand `./tests/testdata/ingest/another_query.sql` has:\n\n```sql\nSELECT\n    *\nFROM\n    `{{ params.my_project_id }}.{{ params.my_dataset }}.{{ params.my_table }}`\n```\nand lastly, `./tests/testdata/nested_params.sql` has:\n```sql\nSELECT\n    {{ params.test_dict_key.one }} + {{ params.test_dict_key.two }}\n```\n\nNext, we want to have our `.yaml` config (or extend `qtrex.config.BaseConfig`)\nto implement your own config mechanism.\n\nOur `./tests/example.yaml` will look like:\n```yaml\nparams:\n  - key: test_string_key\n    value: \"string_value\"\n  - key: test_array_key\n    value: [1, 2, 3]\n  - key: test_dict_key\n    value:\n      one: 1\n      two: 2\n      three: 3\n```\n\nWe can now run the following script (`./tests/example.py`) after changing\ninto the `./tests` directory\n```python\nfrom qtrex.executor import BigQueryExecutor\nfrom qtrex.store import Store\nfrom qtrex.config import YAMLConfig\n\n\ndef main():\n    with open(\"./example.yaml\", \"r\") as f:\n        cfg = YAMLConfig(f)\n\n    store = Store.from_path(cfg, \"./testdata\")\n    ex = BigQueryExecutor()\n    for query_ref in store:\n        print(f\"{query_ref.name}: {query_ref.template}\\n\")\n        res = ex.execute(query_ref, dry_run=True)\n        print(f\"results: {res}\")\n\n\nif __name__ == \"__main__\":\n    main()\n\n```\n\nWhen we run this script:\n```shell\ncd ./tests\npython example.py\n```\nwe should see the following in `stdout`\n\n```text\nmytemplate.sql: SELECT SUM(x)\nFROM UNNEST([1, 2, 3]) AS x\n\nresults: QueryResult(query_ref=QueryRef(filename='./testdata\\\\mytemplate.sql', template='SELECT SUM(x)\\nFROM UNNEST([1, 2, 3]) AS x', name='mytemplate.sql'), df=None, error=None)\nnested_params.sql: SELECT\n    1 + 2\n\nresults: QueryResult(query_ref=QueryRef(filename='./testdata\\\\nested_params.sql', template='SELECT\\n    1 + 2', name='nested_params.sql'), df=None, error=None)\n\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbradleybonitatibus%2Fqtrex","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbradleybonitatibus%2Fqtrex","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbradleybonitatibus%2Fqtrex/lists"}