dazapiz 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.
- dazapiz-0.1.0/.gitattributes +3 -0
- dazapiz-0.1.0/.gitignore +7 -0
- dazapiz-0.1.0/CHANGELOG.md +135 -0
- dazapiz-0.1.0/LICENSE +21 -0
- dazapiz-0.1.0/PKG-INFO +107 -0
- dazapiz-0.1.0/README.md +76 -0
- dazapiz-0.1.0/pyproject.toml +92 -0
- dazapiz-0.1.0/src/dazapiz/__init__.py +62 -0
- dazapiz-0.1.0/src/dazapiz/_api_client.py +698 -0
- dazapiz-0.1.0/src/dazapiz/_app_credential.py +251 -0
- dazapiz-0.1.0/src/dazapiz/_az.py +505 -0
- dazapiz-0.1.0/src/dazapiz/_az_cli_token.py +253 -0
- dazapiz-0.1.0/src/dazapiz/_credential.py +187 -0
- dazapiz-0.1.0/src/dazapiz/_interactive.py +260 -0
- dazapiz-0.1.0/src/dazapiz/_json.py +20 -0
- dazapiz-0.1.0/src/dazapiz/_pasted_code.py +145 -0
- dazapiz-0.1.0/src/dazapiz/_refresh_token.py +178 -0
- dazapiz-0.1.0/src/dazapiz/_session.py +36 -0
- dazapiz-0.1.0/src/dazapiz/_spark_conf.py +359 -0
- dazapiz-0.1.0/src/dazapiz/duckdb.py +618 -0
- dazapiz-0.1.0/src/dazapiz/errors.py +153 -0
- dazapiz-0.1.0/src/dazapiz/py.typed +0 -0
- dazapiz-0.1.0/src/dazapiz/testing.py +150 -0
- dazapiz-0.1.0/tests/conftest.py +86 -0
- dazapiz-0.1.0/tests/fake_az/az +3 -0
- dazapiz-0.1.0/tests/fake_az/az.cmd +4 -0
- dazapiz-0.1.0/tests/fake_az/fake_az.py +85 -0
- dazapiz-0.1.0/tests/fake_entra.py +68 -0
- dazapiz-0.1.0/tests/fixtures/azr_json_body.json +140 -0
- dazapiz-0.1.0/tests/fixtures/azr_spark_conf.json +2151 -0
- dazapiz-0.1.0/tests/helpers.py +149 -0
- dazapiz-0.1.0/tests/manual/README.md +374 -0
- dazapiz-0.1.0/tests/manual/conftest.py +89 -0
- dazapiz-0.1.0/tests/manual/interactive.py +127 -0
- dazapiz-0.1.0/tests/manual/live_helpers.py +15 -0
- dazapiz-0.1.0/tests/manual/test_live_api_client.py +71 -0
- dazapiz-0.1.0/tests/manual/test_live_az_cli.py +52 -0
- dazapiz-0.1.0/tests/manual/test_live_duckdb.py +66 -0
- dazapiz-0.1.0/tests/manual/test_live_petstore.py +84 -0
- dazapiz-0.1.0/tests/manual/test_live_spark.py +116 -0
- dazapiz-0.1.0/tests/recording_transport.py +66 -0
- dazapiz-0.1.0/tests/test_api_client.py +760 -0
- dazapiz-0.1.0/tests/test_api_client_httpbin.py +232 -0
- dazapiz-0.1.0/tests/test_app_credential.py +330 -0
- dazapiz-0.1.0/tests/test_az.py +482 -0
- dazapiz-0.1.0/tests/test_az_cli_token.py +353 -0
- dazapiz-0.1.0/tests/test_duckdb.py +396 -0
- dazapiz-0.1.0/tests/test_fake_az.py +79 -0
- dazapiz-0.1.0/tests/test_fetch_typed.py +347 -0
- dazapiz-0.1.0/tests/test_helpers.py +52 -0
- dazapiz-0.1.0/tests/test_interactive.py +218 -0
- dazapiz-0.1.0/tests/test_manual_checklist.py +107 -0
- dazapiz-0.1.0/tests/test_package.py +7 -0
- dazapiz-0.1.0/tests/test_pasted_code.py +439 -0
- dazapiz-0.1.0/tests/test_recording_transport.py +43 -0
- dazapiz-0.1.0/tests/test_refresh_token.py +114 -0
- dazapiz-0.1.0/tests/test_refresh_token_credential.py +234 -0
- dazapiz-0.1.0/tests/test_secrets.py +381 -0
- dazapiz-0.1.0/tests/test_spark_conf.py +263 -0
- dazapiz-0.1.0/tests/test_testing.py +76 -0
- dazapiz-0.1.0/tests/typing/test_fetch_types.py +76 -0
- dazapiz-0.1.0/tools/azr_json_body_fixture.R +128 -0
- dazapiz-0.1.0/tools/azr_spark_fixture.R +124 -0
dazapiz-0.1.0/.gitignore
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.1.0 (2026-11-26)
|
|
4
|
+
|
|
5
|
+
The first release. `dazapiz` adds what `azure-identity` lacks: your
|
|
6
|
+
`az login` carried into Spark, DuckDB and any Azure REST API. Where
|
|
7
|
+
`azure-identity` or `msal` already does a job, `dazapiz` calls it. It needs
|
|
8
|
+
Python 3.10 or later.
|
|
9
|
+
|
|
10
|
+
### Refresh tokens and credentials
|
|
11
|
+
|
|
12
|
+
- `refresh_token_from_az_cli()` returns the refresh token of the account
|
|
13
|
+
the Azure CLI is signed in as, read from `azureProfile.json` and
|
|
14
|
+
`msal_token_cache.json` without running `az` (macOS and Linux; Windows
|
|
15
|
+
raises `UnsupportedPlatformError`).
|
|
16
|
+
- When one username is several accounts in the Azure CLI's cache (the same
|
|
17
|
+
name in two clouds, or two home accounts), `refresh_token_from_az_cli()`
|
|
18
|
+
takes the one in the profile's cloud and tenant, not the newest (#47).
|
|
19
|
+
- `RefreshTokenCredential` redeems a refresh token for access tokens as a
|
|
20
|
+
`TokenCredential`, caching them until five minutes before expiry and
|
|
21
|
+
keeping the rotated refresh token.
|
|
22
|
+
- `RefreshTokenInfo`, `SupportsRefreshToken` and `AZURE_CLI_CLIENT_ID`: a
|
|
23
|
+
refresh token always travels with its client ID and tenant; a plain
|
|
24
|
+
string or `$AZURE_REFRESH_TOKEN` takes `$AZURE_CLIENT_ID` (else the CLI's
|
|
25
|
+
client ID) and `$AZURE_TENANT_ID` (else `"common"`).
|
|
26
|
+
- `DeviceCodeCredential` and `InteractiveBrowserCredential` subclass the
|
|
27
|
+
`azure-identity` classes, keep their token cache in the platform store
|
|
28
|
+
under the name `"dazapiz"` (`allow_unencrypted_storage=True` falls back
|
|
29
|
+
to a plain file), and add `get_refresh_token()`, which signs in if
|
|
30
|
+
needed and returns the refresh token from that cache.
|
|
31
|
+
- `InteractiveBrowserCredential` with a redirect URI that is not on
|
|
32
|
+
localhost signs in as `httr2::req_oauth_auth_code()` does: it prints
|
|
33
|
+
the sign-in URL and reads back the callback URL, base64 JSON, or the
|
|
34
|
+
code and state shown by the callback page, so it works from
|
|
35
|
+
code-server and notebooks in the cloud.
|
|
36
|
+
- `app_credential()` chooses an API's credential from its own service
|
|
37
|
+
principal variables (`client_id_env`, `client_secret_env`,
|
|
38
|
+
`tenant_id_env`) and the mode (`prod`, `dev`, a single credential
|
|
39
|
+
name, or automatic), from the argument or `$AZURE_TOKEN_CREDENTIALS`;
|
|
40
|
+
a partly set service principal raises `ValueError` naming the missing
|
|
41
|
+
variable. In `dev` mode the device code has no persisted cache, so it
|
|
42
|
+
prompts on headless Linux too (#39). A `$AZURE_TOKEN_CREDENTIALS` value
|
|
43
|
+
that `DefaultAzureCredential` takes but dazapiz does not build
|
|
44
|
+
(`AzureDeveloperCliCredential`, ...) means automatic, with a warning
|
|
45
|
+
(#44).
|
|
46
|
+
|
|
47
|
+
### Spark
|
|
48
|
+
|
|
49
|
+
- `spark_storage_conf()` builds the Hadoop `fs.azure.*` keys for Spark
|
|
50
|
+
to read ADLS Gen2 with a refresh token, a service principal, workload
|
|
51
|
+
or managed identity, or an account key, key for key as
|
|
52
|
+
`azr::azure_spark_storage_conf()` when arguments are explicit. Its
|
|
53
|
+
defaults differ from `azr`'s: a service principal or workload identity
|
|
54
|
+
needs `$AZURE_CLIENT_ID` and `$AZURE_TENANT_ID` rather than falling back
|
|
55
|
+
to the CLI client ID, and managed identity without a client ID is the
|
|
56
|
+
system-assigned identity. It returns a `SparkStorageConf`, a
|
|
57
|
+
`dict[str, str]` whose `repr` and `str` redact the secret, refresh token
|
|
58
|
+
and account key.
|
|
59
|
+
|
|
60
|
+
### Azure CLI
|
|
61
|
+
|
|
62
|
+
- `az_account_show()`, `az_is_login()`, `az_login()` and `az_logout()` run
|
|
63
|
+
the `az` found on `PATH`, with `--only-show-errors` and a 10-second
|
|
64
|
+
timeout (none for `az_login()`). `az_login()` reuses an existing login
|
|
65
|
+
(into `tenant_id`, if given) unless `force=True`; otherwise it runs
|
|
66
|
+
`az login --use-device-code`, prints the device code and URL as `az`
|
|
67
|
+
streams them, copies the code to the clipboard when a clipboard tool is
|
|
68
|
+
found, and returns the account. Its `timeout` covers the whole login,
|
|
69
|
+
the `az account show` checks included (#37), and a `tenant_id` domain
|
|
70
|
+
matches the account's default domain (#38). Errors: `AzCliError` and its
|
|
71
|
+
subclasses `AzCliNotFoundError`, `AzCliNotLoggedInError`,
|
|
72
|
+
`AzCliNonInteractiveError` (no TTY or notebook kernel) and
|
|
73
|
+
`AzCliTimeoutError`.
|
|
74
|
+
|
|
75
|
+
### REST client
|
|
76
|
+
|
|
77
|
+
- `ApiClient`, a small `httpx` client for one REST API, meant to be
|
|
78
|
+
subclassed: `fetch()` fills `{name}` path placeholders (URL-encoded; a
|
|
79
|
+
conversion or format spec is refused, #45), refuses an absolute URL so
|
|
80
|
+
the bearer token never leaves the client's host (#36), leaves `None`
|
|
81
|
+
query values out (#40), retries 429, 503 and connection failures up to
|
|
82
|
+
`max_tries` with `Retry-After` (an invalid or infinite one falls back,
|
|
83
|
+
#41) or `azr`'s backoff, parses JSON (`application/json`, `text/json`,
|
|
84
|
+
`+json`), XML (`application/xml`, `text/xml`, `+xml`) or text by content
|
|
85
|
+
type (#43), and raises `ApiError` (an `httpx.HTTPStatusError`) with the
|
|
86
|
+
method, URL, status and body. The bearer token is fetched from the
|
|
87
|
+
credential once and renewed five minutes before expiry. Subclasses
|
|
88
|
+
that set `client_id_env` and `client_secret_env` get their credential
|
|
89
|
+
from `app_credential()`; `with SomeApiClient() as client:` types
|
|
90
|
+
`client` as the subclass.
|
|
91
|
+
- `fetch(..., parse=f)` returns `f(body)`, typed as `f`'s result, so
|
|
92
|
+
`parse=Model.model_validate` or `TypeAdapter(list[Model]).validate_python`
|
|
93
|
+
validates the body. A body that does not parse, or an exception from
|
|
94
|
+
`f`, raises `ResponseParseError`, which names the method and URL but not
|
|
95
|
+
the body.
|
|
96
|
+
- `fetch(json=...)` sends a pydantic model as
|
|
97
|
+
`model_dump(mode="json", by_alias=True, exclude_unset=True)` and a
|
|
98
|
+
dataclass as `dataclasses.asdict()`, also when nested; `dazapiz` does not
|
|
99
|
+
depend on pydantic.
|
|
100
|
+
- `verbose=True` logs requests and responses in `azr`'s format on the
|
|
101
|
+
`dazapiz.http` logger, through `rich`, with long JSON bodies abbreviated
|
|
102
|
+
as `azr`'s `format_json_body()`; headers are never logged. Log messages
|
|
103
|
+
are plain text, so other handlers print no `rich` markup (#42).
|
|
104
|
+
- For tests: `ApiClient` takes keyword-only `transport=` (such as
|
|
105
|
+
`httpx.MockTransport`) and `sleep=` (the function retries wait with),
|
|
106
|
+
and has a read-only `credential` property.
|
|
107
|
+
`dazapiz.testing.StaticTokenCredential` is a fake `TokenCredential` that
|
|
108
|
+
returns a fixed token and records the scopes it was asked for.
|
|
109
|
+
|
|
110
|
+
### DuckDB
|
|
111
|
+
|
|
112
|
+
- `dazapiz.duckdb` (extra `duckdb`) registers DuckDB Azure secrets as
|
|
113
|
+
`quak` does, named `dazapiz_default` or `dazapiz_<account>` and, with
|
|
114
|
+
`account`, scoped to the account's `abfss://`, `abfs://`, `az://` and
|
|
115
|
+
`azure://` hosts: `set_token_secret()`, `set_sp_secret()`,
|
|
116
|
+
`set_chain_secret()`, and `set_credential_secret()`, which registers an
|
|
117
|
+
access token from any `TokenCredential` and returns its `expires_on`.
|
|
118
|
+
`list_secrets()` and `azure_settings()` return DuckDB relations;
|
|
119
|
+
`tune()` sets the six Azure read and cache settings. The `azure`
|
|
120
|
+
extension is installed and loaded when needed. `import dazapiz` never
|
|
121
|
+
imports `duckdb`; without it, `dazapiz.duckdb` raises `ImportError`
|
|
122
|
+
naming `pip install 'dazapiz[duckdb]'`.
|
|
123
|
+
|
|
124
|
+
### Errors and secrets
|
|
125
|
+
|
|
126
|
+
- `dazapiz.errors`: `DazapizError`, `RefreshTokenNotFoundError`,
|
|
127
|
+
`UnsupportedPlatformError`, `ApiError`, `ResponseParseError`, and the
|
|
128
|
+
`AzCliError` family. No refresh token, client secret, account key or
|
|
129
|
+
bearer token appears in a `repr`, `str`, log record or error message.
|
|
130
|
+
|
|
131
|
+
### Documentation
|
|
132
|
+
|
|
133
|
+
- A site, <https://pedrobtz.github.io/py-dazapiz/>: a guide (get started,
|
|
134
|
+
REST client with the Petstore example, DuckDB, browser-hosted sign-in,
|
|
135
|
+
testing your API client) and an API reference.
|
dazapiz-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 pedrobtz
|
|
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.
|
dazapiz-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: dazapiz
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: The Azure helpers azure-identity lacks: your az login carried into Spark, DuckDB and any Azure REST API.
|
|
5
|
+
Project-URL: Homepage, https://github.com/pedrobtz/py-dazapiz
|
|
6
|
+
Project-URL: Documentation, https://pedrobtz.github.io/py-dazapiz/
|
|
7
|
+
Project-URL: Issues, https://github.com/pedrobtz/py-dazapiz/issues
|
|
8
|
+
Project-URL: Changelog, https://github.com/pedrobtz/py-dazapiz/blob/main/CHANGELOG.md
|
|
9
|
+
Author-email: pedrobtz <pedrobtz@gmail.com>
|
|
10
|
+
License-Expression: MIT
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Keywords: abfs,azure,azure-identity,duckdb,oauth,refresh-token,spark
|
|
13
|
+
Classifier: Development Status :: 3 - Alpha
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
22
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
23
|
+
Classifier: Typing :: Typed
|
|
24
|
+
Requires-Python: >=3.10
|
|
25
|
+
Requires-Dist: azure-identity>=1.27
|
|
26
|
+
Requires-Dist: httpx>=0.28
|
|
27
|
+
Requires-Dist: rich>=13
|
|
28
|
+
Provides-Extra: duckdb
|
|
29
|
+
Requires-Dist: duckdb>=1.1; extra == 'duckdb'
|
|
30
|
+
Description-Content-Type: text/markdown
|
|
31
|
+
|
|
32
|
+
# dazapiz
|
|
33
|
+
|
|
34
|
+
[](https://github.com/pedrobtz/py-dazapiz/actions/workflows/ci.yml)
|
|
35
|
+
[](https://pedrobtz.github.io/py-dazapiz/)
|
|
36
|
+
[](https://pypi.org/project/dazapiz/)
|
|
37
|
+
|
|
38
|
+
The Azure helpers `azure-identity` lacks: your `az login` in Python,
|
|
39
|
+
carried into Spark, DuckDB and any Azure REST API, with one small package
|
|
40
|
+
on top of the official SDK. Documentation:
|
|
41
|
+
<https://pedrobtz.github.io/py-dazapiz/>.
|
|
42
|
+
|
|
43
|
+
- **Spark from your `az login`.** Neither PySpark nor the Azure SDK turns
|
|
44
|
+
an `az login` into Spark's ABFS settings; `spark_storage_conf()` finds
|
|
45
|
+
the refresh token the Azure CLI keeps and writes the keys.
|
|
46
|
+
- **A REST client for one API.** `ApiClient` is a typed `httpx` client:
|
|
47
|
+
bearer token, retries, parsing, and errors that never show a secret.
|
|
48
|
+
- **DuckDB secrets** from any credential, scoped per storage account.
|
|
49
|
+
- **Sign-in that works in a browser-hosted IDE**: device code, browser,
|
|
50
|
+
and a pasted-code flow for code-server and cloud notebooks.
|
|
51
|
+
|
|
52
|
+
Where `azure-identity` or `msal` already does a job, `dazapiz` calls it.
|
|
53
|
+
|
|
54
|
+
## Installation
|
|
55
|
+
|
|
56
|
+
From [PyPI](https://pypi.org/project/dazapiz/):
|
|
57
|
+
|
|
58
|
+
```sh
|
|
59
|
+
pip install dazapiz
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
It needs Python 3.10 or later. The `duckdb` extra adds the DuckDB secrets:
|
|
63
|
+
|
|
64
|
+
```sh
|
|
65
|
+
pip install "dazapiz[duckdb]"
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
The development version installs from GitHub:
|
|
69
|
+
`pip install git+https://github.com/pedrobtz/py-dazapiz`.
|
|
70
|
+
|
|
71
|
+
## A first run
|
|
72
|
+
|
|
73
|
+
```python
|
|
74
|
+
from pyspark.sql import SparkSession
|
|
75
|
+
from dazapiz import az_login, spark_storage_conf, refresh_token_from_az_cli
|
|
76
|
+
|
|
77
|
+
az_login() # device code, once per machine
|
|
78
|
+
conf = spark_storage_conf(refresh_token=refresh_token_from_az_cli())
|
|
79
|
+
spark = SparkSession.builder.config(map=conf).getOrCreate()
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
- [Get started](https://pedrobtz.github.io/py-dazapiz/user-guide/get-started.html):
|
|
83
|
+
install, `az login`, Spark, and the other ways to authenticate.
|
|
84
|
+
- [REST client](https://pedrobtz.github.io/py-dazapiz/user-guide/rest-client.html):
|
|
85
|
+
a typed client for one Azure-protected API, with a Petstore example.
|
|
86
|
+
- [DuckDB](https://pedrobtz.github.io/py-dazapiz/user-guide/duckdb.html):
|
|
87
|
+
Azure secrets from any credential, scoped per account.
|
|
88
|
+
- [Browser-hosted sign-in](https://pedrobtz.github.io/py-dazapiz/user-guide/browser-sign-in.html):
|
|
89
|
+
device code, browser, and the pasted-code flow for code-server.
|
|
90
|
+
- [Testing your API client](https://pedrobtz.github.io/py-dazapiz/user-guide/testing.html):
|
|
91
|
+
an `ApiClient` subclass tested in CI without Azure.
|
|
92
|
+
- The [reference](https://pedrobtz.github.io/py-dazapiz/reference/) lists
|
|
93
|
+
every public name.
|
|
94
|
+
|
|
95
|
+
## Status
|
|
96
|
+
|
|
97
|
+
0.1.0 is the first release; the interface may still change before 1.0.
|
|
98
|
+
Changes are listed in
|
|
99
|
+
[`CHANGELOG.md`](https://github.com/pedrobtz/py-dazapiz/blob/main/CHANGELOG.md).
|
|
100
|
+
The design is in
|
|
101
|
+
[`.agents/design.md`](https://github.com/pedrobtz/py-dazapiz/blob/main/.agents/design.md)
|
|
102
|
+
and the order of work in
|
|
103
|
+
[`.agents/roadmap.md`](https://github.com/pedrobtz/py-dazapiz/blob/main/.agents/roadmap.md).
|
|
104
|
+
|
|
105
|
+
## License
|
|
106
|
+
|
|
107
|
+
MIT
|
dazapiz-0.1.0/README.md
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# dazapiz
|
|
2
|
+
|
|
3
|
+
[](https://github.com/pedrobtz/py-dazapiz/actions/workflows/ci.yml)
|
|
4
|
+
[](https://pedrobtz.github.io/py-dazapiz/)
|
|
5
|
+
[](https://pypi.org/project/dazapiz/)
|
|
6
|
+
|
|
7
|
+
The Azure helpers `azure-identity` lacks: your `az login` in Python,
|
|
8
|
+
carried into Spark, DuckDB and any Azure REST API, with one small package
|
|
9
|
+
on top of the official SDK. Documentation:
|
|
10
|
+
<https://pedrobtz.github.io/py-dazapiz/>.
|
|
11
|
+
|
|
12
|
+
- **Spark from your `az login`.** Neither PySpark nor the Azure SDK turns
|
|
13
|
+
an `az login` into Spark's ABFS settings; `spark_storage_conf()` finds
|
|
14
|
+
the refresh token the Azure CLI keeps and writes the keys.
|
|
15
|
+
- **A REST client for one API.** `ApiClient` is a typed `httpx` client:
|
|
16
|
+
bearer token, retries, parsing, and errors that never show a secret.
|
|
17
|
+
- **DuckDB secrets** from any credential, scoped per storage account.
|
|
18
|
+
- **Sign-in that works in a browser-hosted IDE**: device code, browser,
|
|
19
|
+
and a pasted-code flow for code-server and cloud notebooks.
|
|
20
|
+
|
|
21
|
+
Where `azure-identity` or `msal` already does a job, `dazapiz` calls it.
|
|
22
|
+
|
|
23
|
+
## Installation
|
|
24
|
+
|
|
25
|
+
From [PyPI](https://pypi.org/project/dazapiz/):
|
|
26
|
+
|
|
27
|
+
```sh
|
|
28
|
+
pip install dazapiz
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
It needs Python 3.10 or later. The `duckdb` extra adds the DuckDB secrets:
|
|
32
|
+
|
|
33
|
+
```sh
|
|
34
|
+
pip install "dazapiz[duckdb]"
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
The development version installs from GitHub:
|
|
38
|
+
`pip install git+https://github.com/pedrobtz/py-dazapiz`.
|
|
39
|
+
|
|
40
|
+
## A first run
|
|
41
|
+
|
|
42
|
+
```python
|
|
43
|
+
from pyspark.sql import SparkSession
|
|
44
|
+
from dazapiz import az_login, spark_storage_conf, refresh_token_from_az_cli
|
|
45
|
+
|
|
46
|
+
az_login() # device code, once per machine
|
|
47
|
+
conf = spark_storage_conf(refresh_token=refresh_token_from_az_cli())
|
|
48
|
+
spark = SparkSession.builder.config(map=conf).getOrCreate()
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
- [Get started](https://pedrobtz.github.io/py-dazapiz/user-guide/get-started.html):
|
|
52
|
+
install, `az login`, Spark, and the other ways to authenticate.
|
|
53
|
+
- [REST client](https://pedrobtz.github.io/py-dazapiz/user-guide/rest-client.html):
|
|
54
|
+
a typed client for one Azure-protected API, with a Petstore example.
|
|
55
|
+
- [DuckDB](https://pedrobtz.github.io/py-dazapiz/user-guide/duckdb.html):
|
|
56
|
+
Azure secrets from any credential, scoped per account.
|
|
57
|
+
- [Browser-hosted sign-in](https://pedrobtz.github.io/py-dazapiz/user-guide/browser-sign-in.html):
|
|
58
|
+
device code, browser, and the pasted-code flow for code-server.
|
|
59
|
+
- [Testing your API client](https://pedrobtz.github.io/py-dazapiz/user-guide/testing.html):
|
|
60
|
+
an `ApiClient` subclass tested in CI without Azure.
|
|
61
|
+
- The [reference](https://pedrobtz.github.io/py-dazapiz/reference/) lists
|
|
62
|
+
every public name.
|
|
63
|
+
|
|
64
|
+
## Status
|
|
65
|
+
|
|
66
|
+
0.1.0 is the first release; the interface may still change before 1.0.
|
|
67
|
+
Changes are listed in
|
|
68
|
+
[`CHANGELOG.md`](https://github.com/pedrobtz/py-dazapiz/blob/main/CHANGELOG.md).
|
|
69
|
+
The design is in
|
|
70
|
+
[`.agents/design.md`](https://github.com/pedrobtz/py-dazapiz/blob/main/.agents/design.md)
|
|
71
|
+
and the order of work in
|
|
72
|
+
[`.agents/roadmap.md`](https://github.com/pedrobtz/py-dazapiz/blob/main/.agents/roadmap.md).
|
|
73
|
+
|
|
74
|
+
## License
|
|
75
|
+
|
|
76
|
+
MIT
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "dazapiz"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "The Azure helpers azure-identity lacks: your az login carried into Spark, DuckDB and any Azure REST API."
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
authors = [
|
|
7
|
+
{ name = "pedrobtz", email = "pedrobtz@gmail.com" }
|
|
8
|
+
]
|
|
9
|
+
license = "MIT"
|
|
10
|
+
license-files = ["LICENSE"]
|
|
11
|
+
requires-python = ">=3.10"
|
|
12
|
+
dependencies = [
|
|
13
|
+
"azure-identity>=1.27",
|
|
14
|
+
"httpx>=0.28",
|
|
15
|
+
"rich>=13",
|
|
16
|
+
]
|
|
17
|
+
keywords = ["azure", "azure-identity", "spark", "abfs", "duckdb", "oauth", "refresh-token"]
|
|
18
|
+
classifiers = [
|
|
19
|
+
"Development Status :: 3 - Alpha",
|
|
20
|
+
"Intended Audience :: Developers",
|
|
21
|
+
"Programming Language :: Python :: 3",
|
|
22
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
23
|
+
"Programming Language :: Python :: 3.10",
|
|
24
|
+
"Programming Language :: Python :: 3.11",
|
|
25
|
+
"Programming Language :: Python :: 3.12",
|
|
26
|
+
"Programming Language :: Python :: 3.13",
|
|
27
|
+
"Programming Language :: Python :: 3.14",
|
|
28
|
+
"Topic :: Software Development :: Libraries",
|
|
29
|
+
"Typing :: Typed",
|
|
30
|
+
]
|
|
31
|
+
|
|
32
|
+
[project.optional-dependencies]
|
|
33
|
+
duckdb = ["duckdb>=1.1"]
|
|
34
|
+
|
|
35
|
+
[project.urls]
|
|
36
|
+
Homepage = "https://github.com/pedrobtz/py-dazapiz"
|
|
37
|
+
Documentation = "https://pedrobtz.github.io/py-dazapiz/"
|
|
38
|
+
Issues = "https://github.com/pedrobtz/py-dazapiz/issues"
|
|
39
|
+
Changelog = "https://github.com/pedrobtz/py-dazapiz/blob/main/CHANGELOG.md"
|
|
40
|
+
|
|
41
|
+
[build-system]
|
|
42
|
+
requires = ["hatchling>=1.27"]
|
|
43
|
+
build-backend = "hatchling.build"
|
|
44
|
+
|
|
45
|
+
[tool.hatch.build.targets.sdist]
|
|
46
|
+
exclude = [
|
|
47
|
+
".agents", ".github", "CLAUDE.md", "uv.lock", ".python-version", "typings",
|
|
48
|
+
# The documentation site's sources (design §7), and the test that reads them.
|
|
49
|
+
"great-docs.yml", "user_guide", "tests/test_docs_snippets.py",
|
|
50
|
+
# The Petstore example, its OpenAPI fixture and their CI test: repository-only
|
|
51
|
+
# (design §7). The opt-in live test stays: it is collected and skipped.
|
|
52
|
+
"examples", "tests/fixtures/petstore-openapi.*", "tests/test_petstore_example.py",
|
|
53
|
+
]
|
|
54
|
+
|
|
55
|
+
[dependency-groups]
|
|
56
|
+
dev = [
|
|
57
|
+
"pydantic>=2.11",
|
|
58
|
+
"pyright>=1.1.414",
|
|
59
|
+
"pytest>=8.0",
|
|
60
|
+
"pytest-cov>=5.0",
|
|
61
|
+
"pytest-httpbin>=2.1.0",
|
|
62
|
+
"pytest-socket>=0.8.1",
|
|
63
|
+
"respx>=0.23.1",
|
|
64
|
+
"ruff>=0.6",
|
|
65
|
+
"typing-extensions>=4.12",
|
|
66
|
+
]
|
|
67
|
+
|
|
68
|
+
[tool.ruff]
|
|
69
|
+
line-length = 100
|
|
70
|
+
target-version = "py310"
|
|
71
|
+
# The design keeps its signatures aligned by hand; ruff formats Python files only.
|
|
72
|
+
extend-exclude = ["*.md"]
|
|
73
|
+
|
|
74
|
+
[tool.ruff.lint]
|
|
75
|
+
select = ["E", "F", "W", "I", "UP", "B", "SIM", "RUF"]
|
|
76
|
+
ignore = ["E501"] # line length is the formatter's job
|
|
77
|
+
|
|
78
|
+
[tool.pytest.ini_options]
|
|
79
|
+
testpaths = ["tests", "examples/tests"]
|
|
80
|
+
# The example tests import the example modules by name, as a user's tests import
|
|
81
|
+
# their installed package.
|
|
82
|
+
pythonpath = ["examples"]
|
|
83
|
+
addopts = ["-ra"]
|
|
84
|
+
filterwarnings = ["error"]
|
|
85
|
+
|
|
86
|
+
[tool.pyright]
|
|
87
|
+
# Strict over the package, the examples and the typing tests (design §8.1).
|
|
88
|
+
include = ["src", "examples", "tests/typing"]
|
|
89
|
+
# examples/tests import the example modules by name (pytest's `pythonpath`).
|
|
90
|
+
extraPaths = ["examples"]
|
|
91
|
+
typeCheckingMode = "strict"
|
|
92
|
+
pythonVersion = "3.10"
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"""The Azure helpers azure-identity lacks.
|
|
2
|
+
|
|
3
|
+
Your `az login` carried into Spark (`spark_storage_conf()`), DuckDB
|
|
4
|
+
(`dazapiz.duckdb`) and any Azure REST API (`ApiClient`), on top of
|
|
5
|
+
`azure-identity` and `msal`. The design is in `.agents/design.md` in the
|
|
6
|
+
repository.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from importlib.metadata import version
|
|
10
|
+
|
|
11
|
+
from ._api_client import ApiClient
|
|
12
|
+
from ._app_credential import app_credential
|
|
13
|
+
from ._az import az_account_show, az_is_login, az_login, az_logout
|
|
14
|
+
from ._az_cli_token import refresh_token_from_az_cli
|
|
15
|
+
from ._credential import RefreshTokenCredential
|
|
16
|
+
from ._interactive import DeviceCodeCredential, InteractiveBrowserCredential
|
|
17
|
+
from ._refresh_token import AZURE_CLI_CLIENT_ID, RefreshTokenInfo, SupportsRefreshToken
|
|
18
|
+
from ._spark_conf import SparkStorageConf, spark_storage_conf
|
|
19
|
+
from .errors import (
|
|
20
|
+
ApiError,
|
|
21
|
+
AzCliError,
|
|
22
|
+
AzCliNonInteractiveError,
|
|
23
|
+
AzCliNotFoundError,
|
|
24
|
+
AzCliNotLoggedInError,
|
|
25
|
+
AzCliTimeoutError,
|
|
26
|
+
DazapizError,
|
|
27
|
+
RefreshTokenNotFoundError,
|
|
28
|
+
ResponseParseError,
|
|
29
|
+
UnsupportedPlatformError,
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
__version__ = version("dazapiz")
|
|
33
|
+
"""The installed version of dazapiz, from the package metadata."""
|
|
34
|
+
|
|
35
|
+
__all__ = [
|
|
36
|
+
"AZURE_CLI_CLIENT_ID",
|
|
37
|
+
"ApiClient",
|
|
38
|
+
"ApiError",
|
|
39
|
+
"AzCliError",
|
|
40
|
+
"AzCliNonInteractiveError",
|
|
41
|
+
"AzCliNotFoundError",
|
|
42
|
+
"AzCliNotLoggedInError",
|
|
43
|
+
"AzCliTimeoutError",
|
|
44
|
+
"DazapizError",
|
|
45
|
+
"DeviceCodeCredential",
|
|
46
|
+
"InteractiveBrowserCredential",
|
|
47
|
+
"RefreshTokenCredential",
|
|
48
|
+
"RefreshTokenInfo",
|
|
49
|
+
"RefreshTokenNotFoundError",
|
|
50
|
+
"ResponseParseError",
|
|
51
|
+
"SparkStorageConf",
|
|
52
|
+
"SupportsRefreshToken",
|
|
53
|
+
"UnsupportedPlatformError",
|
|
54
|
+
"__version__",
|
|
55
|
+
"app_credential",
|
|
56
|
+
"az_account_show",
|
|
57
|
+
"az_is_login",
|
|
58
|
+
"az_login",
|
|
59
|
+
"az_logout",
|
|
60
|
+
"refresh_token_from_az_cli",
|
|
61
|
+
"spark_storage_conf",
|
|
62
|
+
]
|