Changelog
This changelog is generated automatically from GitHub Releases.
dazapiz 0.1.0
2026-11-26 · GitHub
The first release. dazapiz adds what azure-identity lacks: your az login carried into Spark, DuckDB and any Azure REST API. Where azure-identity or msal already does a job, dazapiz calls it. It needs Python 3.10 or later.
Refresh tokens and credentials
- refresh_token_from_az_cli() returns the refresh token of the account the Azure CLI is signed in as, read from
azureProfile.jsonandmsal_token_cache.jsonwithout runningaz(macOS and Linux; Windows raises UnsupportedPlatformError). - When one username is several accounts in the Azure CLI’s cache (the same name in two clouds, or two home accounts), refresh_token_from_az_cli() takes the one in the profile’s cloud and tenant, not the newest (#47).
- RefreshTokenCredential redeems a refresh token for access tokens as a
TokenCredential, caching them until five minutes before expiry and keeping the rotated refresh token. - RefreshTokenInfo, SupportsRefreshToken and AZURE_CLI_CLIENT_ID: a refresh token always travels with its client ID and tenant; a plain string or
$AZURE_REFRESH_TOKENtakes$AZURE_CLIENT_ID(else the CLI’s client ID) and$AZURE_TENANT_ID(else"common"). - DeviceCodeCredential and InteractiveBrowserCredential subclass the
azure-identityclasses, keep their token cache in the platform store under the name"dazapiz"(allow_unencrypted_storage=Truefalls back to a plain file), and add get_refresh_token(), which signs in if needed and returns the refresh token from that cache. - InteractiveBrowserCredential with a redirect URI that is not on localhost signs in as
httr2::req_oauth_auth_code()does: it prints the sign-in URL and reads back the callback URL, base64 JSON, or the code and state shown by the callback page, so it works from code-server and notebooks in the cloud. - app_credential() chooses an API’s credential from its own service principal variables (
client_id_env,client_secret_env,tenant_id_env) and the mode (prod,dev, a single credential name, or automatic), from the argument or$AZURE_TOKEN_CREDENTIALS; a partly set service principal raisesValueErrornaming the missing variable. Indevmode the device code has no persisted cache, so it prompts on headless Linux too (#39). A$AZURE_TOKEN_CREDENTIALSvalue thatDefaultAzureCredentialtakes but dazapiz does not build (AzureDeveloperCliCredential, …) means automatic, with a warning (#44).
Spark
- spark_storage_conf() builds the Hadoop
fs.azure.*keys for Spark to read ADLS Gen2 with a refresh token, a service principal, workload or managed identity, or an account key, key for key asazr::azure_spark_storage_conf()when arguments are explicit. Its defaults differ fromazr’s: a service principal or workload identity needs$AZURE_CLIENT_IDand$AZURE_TENANT_IDrather than falling back to the CLI client ID, and managed identity without a client ID is the system-assigned identity. It returns a SparkStorageConf, adict[str, str]whosereprandstrredact the secret, refresh token and account key.
Azure CLI
- az_account_show(), az_is_login(), az_login() and az_logout() run the
azfound onPATH, with--only-show-errorsand a 10-second timeout (none for az_login()). az_login() reuses an existing login (intotenant_id, if given) unlessforce=True; otherwise it runsaz login --use-device-code, prints the device code and URL asazstreams them, copies the code to the clipboard when a clipboard tool is found, and returns the account. Itstimeoutcovers the whole login, theaz account showchecks included (#37), and atenant_iddomain matches the account’s default domain (#38). Errors: AzCliError and its subclasses AzCliNotFoundError, AzCliNotLoggedInError, AzCliNonInteractiveError (no TTY or notebook kernel) and AzCliTimeoutError.
REST client
- ApiClient, a small
httpxclient for one REST API, meant to be subclassed: fetch() fills{name}path placeholders (URL-encoded; a conversion or format spec is refused, #45), refuses an absolute URL so the bearer token never leaves the client’s host (#36), leavesNonequery values out (#40), retries 429, 503 and connection failures up tomax_trieswithRetry-After(an invalid or infinite one falls back, #41) orazr’s backoff, parses JSON (application/json,text/json,+json), XML (application/xml,text/xml,+xml) or text by content type (#43), and raises ApiError (anhttpx.HTTPStatusError) with the method, URL, status and body. The bearer token is fetched from the credential once and renewed five minutes before expiry. Subclasses that setclient_id_envandclient_secret_envget their credential from app_credential();with SomeApiClient() as client:typesclientas the subclass. fetch(..., parse=f)returnsf(body), typed asf’s result, soparse=Model.model_validateorTypeAdapter(list[Model]).validate_pythonvalidates the body. A body that does not parse, or an exception fromf, raises ResponseParseError, which names the method and URL but not the body.fetch(json=...)sends a pydantic model asmodel_dump(mode="json", by_alias=True, exclude_unset=True)and a dataclass asdataclasses.asdict(), also when nested;dazapizdoes not depend on pydantic.verbose=Truelogs requests and responses inazr’s format on thedazapiz.httplogger, throughrich, with long JSON bodies abbreviated asazr’sformat_json_body(); headers are never logged. Log messages are plain text, so other handlers print norichmarkup (#42).- For tests: ApiClient takes keyword-only
transport=(such ashttpx.MockTransport) andsleep=(the function retries wait with), and has a read-onlycredentialproperty. dazapiz.testing.StaticTokenCredential is a fakeTokenCredentialthat returns a fixed token and records the scopes it was asked for.
DuckDB
dazapiz.duckdb(extraduckdb) registers DuckDB Azure secrets asquakdoes, nameddazapiz_defaultordazapiz_<account>and, withaccount, scoped to the account’sabfss://,abfs://,az://andazure://hosts: set_token_secret(), set_sp_secret(), set_chain_secret(), and set_credential_secret(), which registers an access token from anyTokenCredentialand returns itsexpires_on. list_secrets() and azure_settings() return DuckDB relations; tune() sets the six Azure read and cache settings. Theazureextension is installed and loaded when needed.import dazapiznever importsduckdb; without it,dazapiz.duckdbraisesImportErrornamingpip install 'dazapiz[duckdb]'.
Errors and secrets
dazapiz.errors: DazapizError, RefreshTokenNotFoundError, UnsupportedPlatformError, ApiError, ResponseParseError, and the AzCliError family. No refresh token, client secret, account key or bearer token appears in arepr,str, log record or error message.
Documentation
- A site, https://pedrobtz.github.io/py-dazapiz/: a guide (get started, REST client with the Petstore example, DuckDB, browser-hosted sign-in, testing your API client) and an API reference.
Install: pip install dazapiz==0.1.0. On PyPI: https://pypi.org/project/dazapiz/0.1.0/ · Documentation: https://pedrobtz.github.io/py-dazapiz/