tha-snowflake-runner 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,36 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: ["main"]
6
+ pull_request:
7
+
8
+ jobs:
9
+ test:
10
+ runs-on: ubuntu-latest
11
+ strategy:
12
+ matrix:
13
+ python-version: ["3.10", "3.11", "3.12"]
14
+
15
+ steps:
16
+ - uses: actions/checkout@v4
17
+
18
+ - name: Install uv
19
+ uses: astral-sh/setup-uv@v4
20
+ with:
21
+ version: "latest"
22
+
23
+ - name: Set up Python ${{ matrix.python-version }}
24
+ run: uv python install ${{ matrix.python-version }}
25
+
26
+ - name: Install dependencies
27
+ run: uv sync --extra dev --python ${{ matrix.python-version }}
28
+
29
+ - name: Lint
30
+ run: uv run ruff check src/ tests/
31
+
32
+ - name: Test
33
+ run: uv run pytest
34
+
35
+ - name: Type check
36
+ run: uv run mypy src/
@@ -0,0 +1,53 @@
1
+ name: Publish
2
+
3
+ on:
4
+ push:
5
+ tags:
6
+ - "v*"
7
+
8
+ jobs:
9
+ build:
10
+ runs-on: ubuntu-latest
11
+ steps:
12
+ - uses: actions/checkout@v4
13
+ - name: Install uv
14
+ uses: astral-sh/setup-uv@v4
15
+ - name: Build
16
+ run: uv build
17
+ - name: Upload dist
18
+ uses: actions/upload-artifact@v4
19
+ with:
20
+ name: dist
21
+ path: dist/
22
+
23
+ publish-testpypi:
24
+ needs: build
25
+ runs-on: ubuntu-latest
26
+ environment: testpypi
27
+ permissions:
28
+ id-token: write
29
+ steps:
30
+ - name: Download dist
31
+ uses: actions/download-artifact@v4
32
+ with:
33
+ name: dist
34
+ path: dist/
35
+ - name: Publish to TestPyPI
36
+ uses: pypa/gh-action-pypi-publish@release/v1
37
+ with:
38
+ repository-url: https://test.pypi.org/legacy/
39
+
40
+ publish-pypi:
41
+ needs: publish-testpypi
42
+ runs-on: ubuntu-latest
43
+ environment: pypi
44
+ permissions:
45
+ id-token: write
46
+ steps:
47
+ - name: Download dist
48
+ uses: actions/download-artifact@v4
49
+ with:
50
+ name: dist
51
+ path: dist/
52
+ - name: Publish to PyPI
53
+ uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,218 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[codz]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py.cover
50
+ .hypothesis/
51
+ .pytest_cache/
52
+ cover/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ .pybuilder/
76
+ target/
77
+
78
+ # Jupyter Notebook
79
+ .ipynb_checkpoints
80
+
81
+ # IPython
82
+ profile_default/
83
+ ipython_config.py
84
+
85
+ # pyenv
86
+ # For a library or package, you might want to ignore these files since the code is
87
+ # intended to run in multiple environments; otherwise, check them in:
88
+ # .python-version
89
+
90
+ # pipenv
91
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
93
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
94
+ # install all needed dependencies.
95
+ # Pipfile.lock
96
+
97
+ # UV
98
+ # Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
99
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
100
+ # commonly ignored for libraries.
101
+ # uv.lock
102
+
103
+ # poetry
104
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
105
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
106
+ # commonly ignored for libraries.
107
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
108
+ # poetry.lock
109
+ # poetry.toml
110
+
111
+ # pdm
112
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
113
+ # pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
114
+ # https://pdm-project.org/en/latest/usage/project/#working-with-version-control
115
+ # pdm.lock
116
+ # pdm.toml
117
+ .pdm-python
118
+ .pdm-build/
119
+
120
+ # pixi
121
+ # Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
122
+ # pixi.lock
123
+ # Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
124
+ # in the .venv directory. It is recommended not to include this directory in version control.
125
+ .pixi
126
+
127
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
128
+ __pypackages__/
129
+
130
+ # Celery stuff
131
+ celerybeat-schedule
132
+ celerybeat.pid
133
+
134
+ # Redis
135
+ *.rdb
136
+ *.aof
137
+ *.pid
138
+
139
+ # RabbitMQ
140
+ mnesia/
141
+ rabbitmq/
142
+ rabbitmq-data/
143
+
144
+ # ActiveMQ
145
+ activemq-data/
146
+
147
+ # SageMath parsed files
148
+ *.sage.py
149
+
150
+ # Environments
151
+ .env
152
+ .envrc
153
+ .venv
154
+ env/
155
+ venv/
156
+ ENV/
157
+ env.bak/
158
+ venv.bak/
159
+
160
+ # Spyder project settings
161
+ .spyderproject
162
+ .spyproject
163
+
164
+ # Rope project settings
165
+ .ropeproject
166
+
167
+ # mkdocs documentation
168
+ /site
169
+
170
+ # mypy
171
+ .mypy_cache/
172
+ .dmypy.json
173
+ dmypy.json
174
+
175
+ # Pyre type checker
176
+ .pyre/
177
+
178
+ # pytype static type analyzer
179
+ .pytype/
180
+
181
+ # Cython debug symbols
182
+ cython_debug/
183
+
184
+ # PyCharm
185
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
186
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
187
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
188
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
189
+ # .idea/
190
+
191
+ # Abstra
192
+ # Abstra is an AI-powered process automation framework.
193
+ # Ignore directories containing user credentials, local state, and settings.
194
+ # Learn more at https://abstra.io/docs
195
+ .abstra/
196
+
197
+ # Visual Studio Code
198
+ # Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
199
+ # that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
200
+ # and can be added to the global gitignore or merged into this file. However, if you prefer,
201
+ # you could uncomment the following to ignore the entire vscode folder
202
+ # .vscode/
203
+ # Temporary file for partial code execution
204
+ tempCodeRunnerFile.py
205
+
206
+ # Ruff stuff:
207
+ .ruff_cache/
208
+
209
+ # PyPI configuration file
210
+ .pypirc
211
+
212
+ # Marimo
213
+ marimo/_static/
214
+ marimo/_lsp/
215
+ __marimo__/
216
+
217
+ # Streamlit
218
+ .streamlit/secrets.toml
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Nathan Wright
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,244 @@
1
+ Metadata-Version: 2.4
2
+ Name: tha-snowflake-runner
3
+ Version: 0.1.0
4
+ Summary: A Tabular Helper API library that wraps snowflake-connector-python with typed connection management, multi-format profile support, and a normalized query return shape.
5
+ Project-URL: Homepage, https://github.com/tha-guy-nate/tha-snowflake-runner
6
+ Project-URL: Issues, https://github.com/tha-guy-nate/tha-snowflake-runner/issues
7
+ Author: Nate Wright
8
+ License: MIT
9
+ License-File: LICENSE
10
+ Keywords: connector,helper,snowflake,sql,tabular,warehouse
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: License :: OSI Approved :: MIT License
13
+ Classifier: Operating System :: OS Independent
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.10
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Topic :: Utilities
19
+ Classifier: Typing :: Typed
20
+ Requires-Python: >=3.10
21
+ Requires-Dist: snowflake-connector-python>=3.6
22
+ Requires-Dist: tomli>=2.0; python_version < '3.11'
23
+ Provides-Extra: dev
24
+ Requires-Dist: mypy>=1.10; extra == 'dev'
25
+ Requires-Dist: pytest>=8; extra == 'dev'
26
+ Requires-Dist: ruff>=0.5; extra == 'dev'
27
+ Description-Content-Type: text/markdown
28
+
29
+ # tha-snowflake-runner
30
+
31
+ [![CI](https://github.com/tha-guy-nate/tha-snowflake-runner/actions/workflows/ci.yml/badge.svg)](https://github.com/tha-guy-nate/tha-snowflake-runner/actions/workflows/ci.yml)
32
+
33
+ A Tabular Helper API library that wraps snowflake-connector-python with typed connection management, multi-format profile support, and a normalized query return shape.
34
+
35
+ ## Install
36
+
37
+ ```bash
38
+ pip install tha-snowflake-runner
39
+ ```
40
+
41
+ ## Quick start
42
+
43
+ ```python
44
+ from tha_snowflake_runner import ThaSnowflake
45
+
46
+ sf = ThaSnowflake(role="ANALYST", warehouse="COMPUTE_WH", database="PROD", schema="PUBLIC")
47
+
48
+ # inline SQL
49
+ result = sf.query("SELECT id, name FROM users WHERE active = %s", params=(True,))
50
+ # {"rows": [{"ID": "u1", "NAME": "Alice"}], "rowcount": 1, "status": None}
51
+
52
+ # or load SQL from a file
53
+ result = sf.query(file="queries/users.sql", params=(True,))
54
+ ```
55
+
56
+ ## Connection modes
57
+
58
+ ### Mode 1 — native connections.toml (default)
59
+
60
+ Delegates profile lookup to the connector, which reads `~/.snowflake/connections.toml` (or the path in `SNOWFLAKE_HOME`).
61
+
62
+ ```python
63
+ sf = ThaSnowflake(role="ANALYST", warehouse="WH")
64
+
65
+ # Named profile
66
+ sf = ThaSnowflake(connection_name="prod", role="ANALYST", warehouse="WH")
67
+ ```
68
+
69
+ ### Mode 2 — custom connections file
70
+
71
+ Pass any `.toml`, `.ini`/`.cfg`, or `.json` file. Both flat (`[profile]`) and nested (`[connections.profile]`) TOML styles are supported.
72
+
73
+ ```python
74
+ sf = ThaSnowflake(
75
+ connections_file="~/my_connections.toml",
76
+ connection_name="prod",
77
+ role="ANALYST",
78
+ warehouse="WH",
79
+ )
80
+
81
+ # List available profile names from the file
82
+ names = sf.list_profiles() # ["default", "prod", "dev"]
83
+
84
+ # Module-level convenience — no ThaSnowflake instance needed
85
+ from tha_snowflake_runner import list_profiles
86
+ names = list_profiles("~/my_connections.toml")
87
+ ```
88
+
89
+ ### Mode 3 — inline (no file)
90
+
91
+ Supply all connection parameters directly. `account` being set triggers inline mode.
92
+
93
+ ```python
94
+ # Okta SSO — opens a browser window
95
+ sf = ThaSnowflake(account="myorg", user="me@example.com", authenticator="externalbrowser")
96
+
97
+ # Password (service accounts)
98
+ sf = ThaSnowflake(account="myorg", user="svc@example.com", password="secret")
99
+
100
+ # Key-pair
101
+ sf = ThaSnowflake(
102
+ account="myorg",
103
+ user="svc@example.com",
104
+ private_key_file="~/keys/rsa_key.p8",
105
+ private_key_passphrase="mypass",
106
+ )
107
+
108
+ # OAuth token
109
+ sf = ThaSnowflake(account="myorg", authenticator="oauth", token="...")
110
+ ```
111
+
112
+ Pass `quiet_connect=True` to suppress connector stdout (e.g. the `externalbrowser` browser-open message).
113
+
114
+ ## Query return shape
115
+
116
+ Every `query()` call returns a normalized dict:
117
+
118
+ ```python
119
+ result = sf.query("SELECT * FROM orders WHERE id = %s", params=("o1",))
120
+ # {
121
+ # "rows": [{"ID": "o1", "TOTAL": 99.0}],
122
+ # "rowcount": 1,
123
+ # "status": None, # None on success, error string on Snowflake query failure
124
+ # }
125
+ ```
126
+
127
+ `sf.rows` always holds the result of the most recent query (thread-local).
128
+
129
+ ## Session — multiple queries on one connection
130
+
131
+ ```python
132
+ with sf.session(role="ANALYST", warehouse="WH") as sess:
133
+ users = sess.query("SELECT * FROM users")
134
+ orders = sess.query("SELECT * FROM orders")
135
+ # one connection opened, two queries run, connection closed on exit
136
+ ```
137
+
138
+ Pass `accumulate=True` to append rows across queries into `sess.rows`:
139
+
140
+ ```python
141
+ with sf.session(accumulate=True) as sess:
142
+ sess.query("SELECT * FROM users WHERE region = 'US'")
143
+ sess.query("SELECT * FROM users WHERE region = 'EU'")
144
+ all_users = sess.rows # combined result from both queries
145
+ ```
146
+
147
+ The return value of each `sess.query()` is always the current query's result only — `sess.rows` is the accumulation point.
148
+
149
+ ## Threading
150
+
151
+ `sf.rows` is thread-local — each thread sees only its own query results. For concurrent workloads, open a `Session` inside each worker:
152
+
153
+ ```python
154
+ from concurrent.futures import ThreadPoolExecutor
155
+
156
+ def worker(sql):
157
+ with sf.session() as sess:
158
+ return sess.query(sql)
159
+
160
+ with ThreadPoolExecutor(max_workers=4) as pool:
161
+ results = list(pool.map(worker, queries))
162
+ ```
163
+
164
+ ## Retry
165
+
166
+ ```python
167
+ sf = ThaSnowflake(
168
+ account="myorg",
169
+ retry_connect=3, # up to 3 retries (4 total attempts)
170
+ retry_on=(OSError,), # only retry on these exception types
171
+ retry_delay=2.0, # seconds between attempts
172
+ status_cb=print, # called with a message on each failed attempt
173
+ )
174
+ ```
175
+
176
+ ## API
177
+
178
+ ### `ThaSnowflake(*, ...)`
179
+
180
+ | Parameter | Type | Default | Description |
181
+ |-----------|------|---------|-------------|
182
+ | `connection_name` | `str` | `"default"` | Profile name for Mode 1/2 |
183
+ | `connections_file` | `str \| None` | `None` | Path to custom connections file (Mode 2) |
184
+ | `account` | `str \| None` | `None` | Snowflake account identifier (Mode 3) |
185
+ | `user` | `str \| None` | `None` | Username (Mode 3) |
186
+ | `authenticator` | `str \| None` | `None` | `"externalbrowser"`, `"oauth"`, etc. |
187
+ | `password` | `str \| None` | `None` | Password auth (Mode 3) |
188
+ | `private_key_file` | `str \| None` | `None` | Path to `.p8` key file; `~` is expanded |
189
+ | `private_key_passphrase` | `str \| None` | `None` | Passphrase for encrypted private key |
190
+ | `token` | `str \| None` | `None` | OAuth token (Mode 3) |
191
+ | `role` | `str \| None` | `None` | Default Snowflake role |
192
+ | `warehouse` | `str \| None` | `None` | Default warehouse |
193
+ | `database` | `str \| None` | `None` | Default database |
194
+ | `schema` | `str \| None` | `None` | Default schema |
195
+ | `quiet_connect` | `bool` | `False` | Suppress connector stdout on connect |
196
+ | `status_cb` | `callable \| None` | `None` | Called with status strings (retry messages, etc.) |
197
+ | `mode` | `str` | `"app"` | Reserved — `"app"` or `"cli"` |
198
+ | `retry_connect` | `int` | `0` | Number of reconnect retries on failure |
199
+ | `retry_on` | `type \| tuple` | `()` | Exception types that trigger a retry |
200
+ | `retry_delay` | `float` | `1.0` | Seconds to wait between retry attempts |
201
+
202
+ ### Methods
203
+
204
+ | Method | Returns | Description |
205
+ |--------|---------|-------------|
206
+ | `set_context(*, role, warehouse, database, schema)` | `None` | Update default context; only non-`None` values are applied |
207
+ | `build_connect_kwargs(*, role, warehouse, database, schema)` | `dict` | Return kwargs that would be passed to `snowflake.connector.connect` — useful for debugging |
208
+ | `connect(**kwargs)` | `SnowflakeConnection` | Open and return a raw connection |
209
+ | `connection(**kwargs)` | context manager | Open a connection, close it on exit |
210
+ | `session(*, accumulate=False, **kwargs)` | context manager → `Session` | Open a `Session` backed by one connection |
211
+ | `query(sql=None, *, file=None, params, conn, role, warehouse, database, schema)` | `dict` | Execute a SELECT; pass `sql` or `file=` (not both); returns `{"rows", "rowcount", "status"}` |
212
+ | `list_profiles()` | `list[str]` | Profile names from `connections_file` (requires Mode 2) |
213
+
214
+ ### `Session`
215
+
216
+ Obtain via `sf.session()`. Not thread-safe — one `Session` per thread.
217
+
218
+ | Member | Description |
219
+ |--------|-------------|
220
+ | `query(sql=None, *, file=None, params)` | Execute a SELECT on the persistent connection; pass `sql` or `file=` (not both); returns `{"rows", "rowcount", "status"}` |
221
+ | `rows` | Running result — latest query only when `accumulate=False` (default), all queries combined when `accumulate=True` |
222
+ | `close()` | Close the underlying connection |
223
+
224
+ ### `list_profiles(path)` — module-level
225
+
226
+ ```python
227
+ from tha_snowflake_runner import list_profiles
228
+
229
+ names = list_profiles("~/connections.toml") # ["default", "prod", "dev"]
230
+ ```
231
+
232
+ Supports the same formats as Mode 2: `.toml`, `.ini`, `.cfg`, `.json`.
233
+
234
+ ## Alternatives
235
+
236
+ - **[snowflake-connector-python](https://docs.snowflake.com/en/developer-guide/python-connector/python-connector)** — the official Snowflake connector; `tha-snowflake-runner` is a thin typed convenience layer on top of it
237
+ - **[snowflake-sqlalchemy](https://docs.snowflake.com/en/developer-guide/python-connector/sqlalchemy)** — SQLAlchemy dialect for Snowflake with ORM support
238
+ - **[snowpark-python](https://docs.snowflake.com/en/developer-guide/snowpark/python/index)** — Snowflake's DataFrame/ML API for in-warehouse computation
239
+
240
+ `tha-snowflake-runner` is intentionally narrow: no ORM, no Snowpark, no async — just a thin typed wrapper for common query patterns and connection-file management.
241
+
242
+ ## License
243
+
244
+ MIT