---
name: dazapiz
description: >
  The Azure helpers azure-identity lacks: your az login carried into Spark, DuckDB and any Azure REST API. Use when writing Python code that uses the dazapiz package.
license: MIT
compatibility: Requires Python >=3.10.
---

# dazapiz

The Azure helpers azure-identity lacks: your az login carried into Spark, DuckDB and any Azure REST API.

## Installation

```bash
pip install dazapiz
```

## API overview

### Refresh tokens and credentials

Find the `az login` refresh token, or sign in for one, and redeem it.

- `refresh_token_from_az_cli`: The refresh token of the account the Azure CLI is signed in as
- `RefreshTokenInfo`: A refresh token with the client ID and tenant it belongs to
- `SupportsRefreshToken`: Anything that can hand over a refresh token with its client ID and tenant
- `AZURE_CLI_CLIENT_ID`: str(object='') -> str
- `RefreshTokenCredential`: A `TokenCredential` that redeems a refresh token for access tokens
- `DeviceCodeCredential`: `azure.identity.DeviceCodeCredential` with a persisted cache and `get_refresh_token()`
- `InteractiveBrowserCredential`: `azure.identity.InteractiveBrowserCredential` with a persisted cache and `get_refresh_token()`

### Spark

Hadoop ABFS configuration for PySpark.

- `spark_storage_conf`: Build the Hadoop `fs.azure.*` keys that let Spark read ADLS Gen2
- `SparkStorageConf`: The `fs.azure.*` keys of `spark_storage_conf()`, as a plain `dict[str, str]`

### REST client

A small httpx client for one Azure-protected REST API, and its credentials.

- `ApiClient`: A client for one REST API, meant to be subclassed once per API
- `app_credential`: The credential an API's client uses, chosen from the environment now

### az CLI

Log the Azure CLI in and out, and read its current account.

- `az_login`: Log the Azure CLI in with a device code, unless it already is
- `az_logout`: Log the Azure CLI out, by `az logout`
- `az_is_login`: Whether the Azure CLI is logged in, by `az account show`
- `az_account_show`: The Azure CLI's current account, from `az account show --output json`

### DuckDB

Azure secrets and settings for DuckDB, in `dazapiz.duckdb` (needs `dazapiz[duckdb]`).

- `duckdb.set_credential_secret`
- `duckdb.set_token_secret`
- `duckdb.set_sp_secret`
- `duckdb.set_chain_secret`
- `duckdb.list_secrets`
- `duckdb.azure_settings`
- `duckdb.tune`
- `duckdb.STORAGE_SCOPE`

### Testing

Test doubles for code built on dazapiz, in `dazapiz.testing`.

- `testing.StaticTokenCredential`

### Errors

Everything dazapiz raises derives from `DazapizError`.

- `DazapizError`: Base class of every error dazapiz raises
- `RefreshTokenNotFoundError`: No refresh token was found where one was looked for
- `UnsupportedPlatformError`: The operation is not available on this operating system
- `AzCliError`: An `az` command failed; the message carries what `az` wrote to stderr
- `AzCliNotFoundError`: No `az` on PATH
- `AzCliNotLoggedInError`: The Azure CLI is not logged in
- `AzCliNonInteractiveError`: `az_login()` was called where nobody can answer the device-code prompt
- `AzCliTimeoutError`: An `az` command did not finish within its timeout and was killed
- `ApiError`: An `ApiClient` request ended in a non-2xx response, after any retries
- `ResponseParseError`: A successful response's body could not be parsed or was rejected by `parse=`

## Resources

- [Full documentation](https://pedrobtz.github.io/py-dazapiz/)
- [llms.txt](llms.txt) — Indexed API reference for LLMs
- [llms-full.txt](llms-full.txt) — Comprehensive documentation for LLMs
