strata-client 0.3.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.
- strata_client-0.3.0/.gitignore +251 -0
- strata_client-0.3.0/PKG-INFO +63 -0
- strata_client-0.3.0/README.md +30 -0
- strata_client-0.3.0/pyproject.toml +45 -0
- strata_client-0.3.0/src/strata_client/__init__.py +52 -0
- strata_client-0.3.0/src/strata_client/_clientconfig.py +69 -0
- strata_client-0.3.0/src/strata_client/client.py +1876 -0
- strata_client-0.3.0/src/strata_client/filters.py +172 -0
- strata_client-0.3.0/src/strata_client/integration/__init__.py +54 -0
- strata_client-0.3.0/src/strata_client/integration/arrow.py +389 -0
- strata_client-0.3.0/src/strata_client/integration/datafusion.py +290 -0
- strata_client-0.3.0/src/strata_client/integration/duckdb.py +322 -0
- strata_client-0.3.0/src/strata_client/integration/pandas.py +201 -0
- strata_client-0.3.0/src/strata_client/integration/polars.py +285 -0
|
@@ -0,0 +1,251 @@
|
|
|
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
|
+
# SageMath parsed files
|
|
135
|
+
*.sage.py
|
|
136
|
+
|
|
137
|
+
# Environments
|
|
138
|
+
.env
|
|
139
|
+
.envrc
|
|
140
|
+
.venv
|
|
141
|
+
env/
|
|
142
|
+
venv/
|
|
143
|
+
ENV/
|
|
144
|
+
env.bak/
|
|
145
|
+
venv.bak/
|
|
146
|
+
|
|
147
|
+
# Spyder project settings
|
|
148
|
+
.spyderproject
|
|
149
|
+
.spyproject
|
|
150
|
+
|
|
151
|
+
# Rope project settings
|
|
152
|
+
.ropeproject
|
|
153
|
+
|
|
154
|
+
# mkdocs documentation
|
|
155
|
+
/site
|
|
156
|
+
|
|
157
|
+
# mypy
|
|
158
|
+
.mypy_cache/
|
|
159
|
+
.dmypy.json
|
|
160
|
+
dmypy.json
|
|
161
|
+
|
|
162
|
+
# Pyre type checker
|
|
163
|
+
.pyre/
|
|
164
|
+
|
|
165
|
+
# pytype static type analyzer
|
|
166
|
+
.pytype/
|
|
167
|
+
|
|
168
|
+
# Cython debug symbols
|
|
169
|
+
cython_debug/
|
|
170
|
+
|
|
171
|
+
# PyCharm
|
|
172
|
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
|
173
|
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
|
174
|
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
|
175
|
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
|
176
|
+
#.idea/
|
|
177
|
+
|
|
178
|
+
# Abstra
|
|
179
|
+
# Abstra is an AI-powered process automation framework.
|
|
180
|
+
# Ignore directories containing user credentials, local state, and settings.
|
|
181
|
+
# Learn more at https://abstra.io/docs
|
|
182
|
+
.abstra/
|
|
183
|
+
|
|
184
|
+
# Visual Studio Code
|
|
185
|
+
# Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
|
|
186
|
+
# that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
|
|
187
|
+
# and can be added to the global gitignore or merged into this file. However, if you prefer,
|
|
188
|
+
# you could uncomment the following to ignore the entire vscode folder
|
|
189
|
+
# .vscode/
|
|
190
|
+
|
|
191
|
+
# Ruff stuff:
|
|
192
|
+
.ruff_cache/
|
|
193
|
+
|
|
194
|
+
# PyPI configuration file
|
|
195
|
+
.pypirc
|
|
196
|
+
|
|
197
|
+
# Cursor
|
|
198
|
+
# Cursor is an AI-powered code editor. `.cursorignore` specifies files/directories to
|
|
199
|
+
# exclude from AI features like autocomplete and code analysis. Recommended for sensitive data
|
|
200
|
+
# refer to https://docs.cursor.com/context/ignore-files
|
|
201
|
+
.cursorignore
|
|
202
|
+
.cursorindexingignore
|
|
203
|
+
|
|
204
|
+
# Marimo
|
|
205
|
+
marimo/_static/
|
|
206
|
+
marimo/_lsp/
|
|
207
|
+
__marimo__/
|
|
208
|
+
|
|
209
|
+
# macOS
|
|
210
|
+
.DS_Store
|
|
211
|
+
|
|
212
|
+
# Rust build artifacts
|
|
213
|
+
rust/target/
|
|
214
|
+
|
|
215
|
+
# Strata demo data (generated)
|
|
216
|
+
demo-warehouse/
|
|
217
|
+
benchmarks/results/
|
|
218
|
+
site/
|
|
219
|
+
|
|
220
|
+
# Internal design and planning docs — kept local only.
|
|
221
|
+
docs/internal/
|
|
222
|
+
|
|
223
|
+
# Auto-generated example renderings produced by the export hook
|
|
224
|
+
# (docs_hooks/export_examples.py). Regenerated on every `mkdocs build`.
|
|
225
|
+
docs/examples/
|
|
226
|
+
|
|
227
|
+
# Per-notebook runtime state — artifacts, blobs, console output,
|
|
228
|
+
# environment lockfiles, example DuckDB files. Generated whenever a
|
|
229
|
+
# notebook runs; never meant to be shared.
|
|
230
|
+
examples/*/.strata/
|
|
231
|
+
examples/*/uv.lock
|
|
232
|
+
examples/*/*.db
|
|
233
|
+
examples/*/*.duckdb
|
|
234
|
+
experiments/**/.strata/
|
|
235
|
+
experiments/**/uv.lock
|
|
236
|
+
experiments/**/*.db
|
|
237
|
+
experiments/**/*.duckdb
|
|
238
|
+
# Experiment runtime/scratch: per-server cache + artifact blobs (named
|
|
239
|
+
# .strata-server-<thing>/, not .strata/) and the Arrow blobs they hold —
|
|
240
|
+
# hundreds of MB, GitHub-rejected. Experiment *code* (e.g. circle_packing_26/)
|
|
241
|
+
# stays tracked; only this generated state is ignored.
|
|
242
|
+
experiments/**/.strata-server*/
|
|
243
|
+
experiments/**/*.arrow
|
|
244
|
+
experiments/**/*.arrowstream
|
|
245
|
+
|
|
246
|
+
# Frontend build output, copied into the package by the release
|
|
247
|
+
# workflow. Source of truth lives at frontend/dist/.
|
|
248
|
+
src/strata/_frontend/
|
|
249
|
+
|
|
250
|
+
# Claude Code session state
|
|
251
|
+
.claude/
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: strata-client
|
|
3
|
+
Version: 0.3.0
|
|
4
|
+
Summary: Lightweight Python client for Strata — materialize, persist, and query artifacts over HTTP.
|
|
5
|
+
Project-URL: Homepage, https://github.com/bearing-research/strata
|
|
6
|
+
Project-URL: Repository, https://github.com/bearing-research/strata
|
|
7
|
+
Author-email: Fangchen Li <fangchen.li@outlook.com>
|
|
8
|
+
License-Expression: Apache-2.0
|
|
9
|
+
Classifier: Development Status :: 3 - Alpha
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
16
|
+
Requires-Python: >=3.12
|
|
17
|
+
Requires-Dist: httpx>=0.28.0
|
|
18
|
+
Requires-Dist: pyarrow>=18.0.0
|
|
19
|
+
Provides-Extra: all
|
|
20
|
+
Requires-Dist: datafusion>=50.1.0; extra == 'all'
|
|
21
|
+
Requires-Dist: duckdb>=1.1.0; extra == 'all'
|
|
22
|
+
Requires-Dist: pandas>=2.0.0; extra == 'all'
|
|
23
|
+
Requires-Dist: polars>=1.36.1; extra == 'all'
|
|
24
|
+
Provides-Extra: datafusion
|
|
25
|
+
Requires-Dist: datafusion>=50.1.0; extra == 'datafusion'
|
|
26
|
+
Provides-Extra: duckdb
|
|
27
|
+
Requires-Dist: duckdb>=1.1.0; extra == 'duckdb'
|
|
28
|
+
Provides-Extra: pandas
|
|
29
|
+
Requires-Dist: pandas>=2.0.0; extra == 'pandas'
|
|
30
|
+
Provides-Extra: polars
|
|
31
|
+
Requires-Dist: polars>=1.36.1; extra == 'polars'
|
|
32
|
+
Description-Content-Type: text/markdown
|
|
33
|
+
|
|
34
|
+
# strata-client
|
|
35
|
+
|
|
36
|
+
A lightweight Python client for a [Strata](https://github.com/bearing-research/strata)
|
|
37
|
+
server. Depends only on `httpx` + `pyarrow` — none of the server's stack
|
|
38
|
+
(no pyiceberg / fastapi / duckdb / pydantic, no Rust extension), so it drops
|
|
39
|
+
into any analysis venv, training image, CI job, or notebook without dragging
|
|
40
|
+
the deployable service along.
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
pip install strata-client
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
```python
|
|
47
|
+
from strata_client import StrataClient
|
|
48
|
+
|
|
49
|
+
with StrataClient() as client: # resolves the server URL from
|
|
50
|
+
# STRATA_SERVER_URL / STRATA_HOST / STRATA_PORT
|
|
51
|
+
art = client.materialize(
|
|
52
|
+
inputs=["file:///warehouse#db.events"],
|
|
53
|
+
transform={"executor": "scan@v1", "params": {}},
|
|
54
|
+
)
|
|
55
|
+
table = client.fetch(art.uri)
|
|
56
|
+
|
|
57
|
+
# Registry: names, aliases, tags, audit
|
|
58
|
+
client.put(table, name="team/dataset/raw")
|
|
59
|
+
client.set_alias("taxi/tip-model", "champion", art.artifact_id, art.version)
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
The server distribution (`strata-notebook`) depends on this package and
|
|
63
|
+
re-exports it as `strata.client` for backward compatibility.
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# strata-client
|
|
2
|
+
|
|
3
|
+
A lightweight Python client for a [Strata](https://github.com/bearing-research/strata)
|
|
4
|
+
server. Depends only on `httpx` + `pyarrow` — none of the server's stack
|
|
5
|
+
(no pyiceberg / fastapi / duckdb / pydantic, no Rust extension), so it drops
|
|
6
|
+
into any analysis venv, training image, CI job, or notebook without dragging
|
|
7
|
+
the deployable service along.
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pip install strata-client
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
```python
|
|
14
|
+
from strata_client import StrataClient
|
|
15
|
+
|
|
16
|
+
with StrataClient() as client: # resolves the server URL from
|
|
17
|
+
# STRATA_SERVER_URL / STRATA_HOST / STRATA_PORT
|
|
18
|
+
art = client.materialize(
|
|
19
|
+
inputs=["file:///warehouse#db.events"],
|
|
20
|
+
transform={"executor": "scan@v1", "params": {}},
|
|
21
|
+
)
|
|
22
|
+
table = client.fetch(art.uri)
|
|
23
|
+
|
|
24
|
+
# Registry: names, aliases, tags, audit
|
|
25
|
+
client.put(table, name="team/dataset/raw")
|
|
26
|
+
client.set_alias("taxi/tip-model", "champion", art.artifact_id, art.version)
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
The server distribution (`strata-notebook`) depends on this package and
|
|
30
|
+
re-exports it as `strata.client` for backward compatibility.
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "strata-client"
|
|
3
|
+
version = "0.3.0"
|
|
4
|
+
description = "Lightweight Python client for Strata — materialize, persist, and query artifacts over HTTP."
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
requires-python = ">=3.12"
|
|
7
|
+
license = "Apache-2.0"
|
|
8
|
+
authors = [{ name = "Fangchen Li", email = "fangchen.li@outlook.com" }]
|
|
9
|
+
classifiers = [
|
|
10
|
+
"Development Status :: 3 - Alpha",
|
|
11
|
+
"Intended Audience :: Developers",
|
|
12
|
+
"License :: OSI Approved :: Apache Software License",
|
|
13
|
+
"Programming Language :: Python :: 3",
|
|
14
|
+
"Programming Language :: Python :: 3.12",
|
|
15
|
+
"Programming Language :: Python :: 3.13",
|
|
16
|
+
"Programming Language :: Python :: 3.14",
|
|
17
|
+
]
|
|
18
|
+
dependencies = [
|
|
19
|
+
"httpx>=0.28.0",
|
|
20
|
+
"pyarrow>=18.0.0",
|
|
21
|
+
]
|
|
22
|
+
|
|
23
|
+
# Optional integrations: query Strata directly from duckdb / pandas / polars /
|
|
24
|
+
# datafusion. Each pulls only its own engine; the base client stays slim.
|
|
25
|
+
# (The arrow integration needs only pyarrow, already a base dependency.)
|
|
26
|
+
[project.optional-dependencies]
|
|
27
|
+
duckdb = ["duckdb>=1.1.0"]
|
|
28
|
+
pandas = ["pandas>=2.0.0"]
|
|
29
|
+
polars = ["polars>=1.36.1"]
|
|
30
|
+
datafusion = ["datafusion>=50.1.0"]
|
|
31
|
+
all = ["duckdb>=1.1.0", "pandas>=2.0.0", "polars>=1.36.1", "datafusion>=50.1.0"]
|
|
32
|
+
|
|
33
|
+
[project.urls]
|
|
34
|
+
Homepage = "https://github.com/bearing-research/strata"
|
|
35
|
+
Repository = "https://github.com/bearing-research/strata"
|
|
36
|
+
|
|
37
|
+
[build-system]
|
|
38
|
+
requires = ["hatchling"]
|
|
39
|
+
build-backend = "hatchling.build"
|
|
40
|
+
|
|
41
|
+
[tool.hatch.build.targets.wheel]
|
|
42
|
+
packages = ["src/strata_client"]
|
|
43
|
+
|
|
44
|
+
[tool.hatch.build.targets.sdist]
|
|
45
|
+
include = ["src/strata_client", "README.md"]
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"""strata_client — a lightweight Python client for a Strata server.
|
|
2
|
+
|
|
3
|
+
Depends only on ``httpx`` + ``pyarrow`` — none of the Strata server's stack
|
|
4
|
+
(no pyiceberg / fastapi / duckdb / pydantic, no Rust extension). Install it
|
|
5
|
+
anywhere you want to *use* Strata as a library::
|
|
6
|
+
|
|
7
|
+
pip install strata-client
|
|
8
|
+
|
|
9
|
+
from strata_client import StrataClient
|
|
10
|
+
|
|
11
|
+
with StrataClient() as client:
|
|
12
|
+
art = client.materialize(
|
|
13
|
+
inputs=["file:///warehouse#db.events"],
|
|
14
|
+
transform={"executor": "scan@v1", "params": {}},
|
|
15
|
+
)
|
|
16
|
+
table = client.fetch(art.uri)
|
|
17
|
+
|
|
18
|
+
The server distribution (``strata-notebook``) depends on this package and
|
|
19
|
+
re-exports it as ``strata.client`` / ``strata.filters`` for backward
|
|
20
|
+
compatibility. See docs/internal/design-strata-client.md.
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
from strata_client.client import (
|
|
24
|
+
Artifact,
|
|
25
|
+
AsyncStrataClient,
|
|
26
|
+
RetryConfig,
|
|
27
|
+
StrataClient,
|
|
28
|
+
eq,
|
|
29
|
+
ge,
|
|
30
|
+
gt,
|
|
31
|
+
le,
|
|
32
|
+
lt,
|
|
33
|
+
ne,
|
|
34
|
+
)
|
|
35
|
+
from strata_client.filters import Filter, FilterOp, FilterValue, compute_filter_fingerprint
|
|
36
|
+
|
|
37
|
+
__all__ = [
|
|
38
|
+
"Artifact",
|
|
39
|
+
"AsyncStrataClient",
|
|
40
|
+
"Filter",
|
|
41
|
+
"FilterOp",
|
|
42
|
+
"FilterValue",
|
|
43
|
+
"RetryConfig",
|
|
44
|
+
"StrataClient",
|
|
45
|
+
"compute_filter_fingerprint",
|
|
46
|
+
"eq",
|
|
47
|
+
"ge",
|
|
48
|
+
"gt",
|
|
49
|
+
"le",
|
|
50
|
+
"lt",
|
|
51
|
+
"ne",
|
|
52
|
+
]
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"""Slim server-URL resolution for the client.
|
|
2
|
+
|
|
3
|
+
The full :class:`strata.config.StrataConfig` pulls in pydantic, pydantic-settings,
|
|
4
|
+
and notebook submodules — far more than a client needs just to find the server.
|
|
5
|
+
This module replicates *only* the server-URL resolution, standard library only,
|
|
6
|
+
so ``StrataClient()`` can locate the server without importing the server's config
|
|
7
|
+
stack. ``StrataClient(config=...)`` still accepts a full ``StrataConfig`` (it has
|
|
8
|
+
a ``server_url``); this is just the default path.
|
|
9
|
+
|
|
10
|
+
Resolution precedence (highest wins):
|
|
11
|
+
|
|
12
|
+
1. ``STRATA_SERVER_URL`` env var (a full URL — the simplest knob for pointing a
|
|
13
|
+
client at a remote server; not read by the server config itself).
|
|
14
|
+
2. ``STRATA_HOST`` / ``STRATA_PORT`` env vars.
|
|
15
|
+
3. ``[tool.strata]`` ``host`` / ``port`` in the nearest ``pyproject.toml``.
|
|
16
|
+
4. Defaults ``127.0.0.1:8765`` — matching ``StrataConfig`` defaults.
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
from __future__ import annotations
|
|
20
|
+
|
|
21
|
+
import os
|
|
22
|
+
import tomllib
|
|
23
|
+
from pathlib import Path
|
|
24
|
+
from typing import Protocol
|
|
25
|
+
|
|
26
|
+
_DEFAULT_HOST = "127.0.0.1"
|
|
27
|
+
_DEFAULT_PORT = 8765
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class HasServerUrl(Protocol):
|
|
31
|
+
"""Anything carrying a ``server_url`` — e.g. a full ``StrataConfig``."""
|
|
32
|
+
|
|
33
|
+
@property
|
|
34
|
+
def server_url(self) -> str: ...
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def _find_pyproject() -> Path | None:
|
|
38
|
+
"""Find pyproject.toml in the current or a parent directory."""
|
|
39
|
+
current = Path.cwd()
|
|
40
|
+
for parent in [current, *current.parents]:
|
|
41
|
+
candidate = parent / "pyproject.toml"
|
|
42
|
+
if candidate.exists():
|
|
43
|
+
return candidate
|
|
44
|
+
return None
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def _pyproject_strata() -> dict:
|
|
48
|
+
"""Return the ``[tool.strata]`` table, or ``{}`` if none is found."""
|
|
49
|
+
path = _find_pyproject()
|
|
50
|
+
if path is None:
|
|
51
|
+
return {}
|
|
52
|
+
try:
|
|
53
|
+
with open(path, "rb") as f:
|
|
54
|
+
data = tomllib.load(f)
|
|
55
|
+
except (OSError, tomllib.TOMLDecodeError):
|
|
56
|
+
return {}
|
|
57
|
+
return data.get("tool", {}).get("strata", {})
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def resolve_server_url() -> str:
|
|
61
|
+
"""Resolve the Strata server URL for a client (see module docstring)."""
|
|
62
|
+
direct = os.environ.get("STRATA_SERVER_URL")
|
|
63
|
+
if direct:
|
|
64
|
+
return direct
|
|
65
|
+
|
|
66
|
+
strata_table = _pyproject_strata()
|
|
67
|
+
host = os.environ.get("STRATA_HOST") or strata_table.get("host") or _DEFAULT_HOST
|
|
68
|
+
port = os.environ.get("STRATA_PORT") or strata_table.get("port") or _DEFAULT_PORT
|
|
69
|
+
return f"http://{host}:{port}"
|