Core API Reference¶
Core components available directly from fabias.
Authentication¶
fabias.ServicePrincipalAuth
¶
Bases: AuthProvider
OAuth2 client credentials authentication using service principal.
This provider authenticates using Azure AD client credentials flow, suitable for service-to-service authentication without user interaction.
Tokens are cached and automatically refreshed when expired.
Attributes:
| Name | Type | Description |
|---|---|---|
tenant_id |
str
|
Azure AD tenant ID |
client_id |
str
|
Application (client) ID |
client_secret |
str
|
Client secret value |
Examples:
>>> auth = ServicePrincipalAuth(
... tenant_id="your-tenant-id",
... client_id="your-client-id",
... client_secret="your-secret"
... )
>>> token = auth.getToken("https://api.fabric.microsoft.com/.default")
Source code in src/fabias/_shared/auth.py
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 | |
Functions¶
__init__(tenant_id, client_id, client_secret)
¶
Initialize the service principal authentication provider.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tenant_id
|
str
|
Azure AD tenant ID (GUID or domain) |
required |
client_id
|
str
|
Application (client) ID from Azure AD |
required |
client_secret
|
str
|
Client secret value |
required |
Source code in src/fabias/_shared/auth.py
getToken(scope)
¶
Get an access token for the specified scope.
Retrieves a cached token if still valid, otherwise acquires a new token using the OAuth2 client credentials flow.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scope
|
str
|
OAuth2 scope (e.g., "https://api.fabric.microsoft.com/.default") |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Access token (without "Bearer " prefix) |
Raises:
| Type | Description |
|---|---|
AuthenticationError
|
If token acquisition fails |
Source code in src/fabias/_shared/auth.py
fabias.RefreshTokenAuth
¶
Bases: AuthProvider
User-delegated authentication using refresh tokens.
This provider supports two modes:
Self-managed mode: You provide a refresh_token, and the provider
handles token rotation automatically. Use on_refresh callback to
persist the new refresh token (e.g., to Key Vault).
Delegated mode: You provide a token_provider callable that
handles all token acquisition externally (e.g., via an Azure Function
token broker). The provider just calls your function.
Tokens are cached and automatically refreshed when expired.
Attributes:
| Name | Type | Description |
|---|---|---|
tenant_id |
str
|
Azure AD tenant ID |
client_id |
str
|
Application (client) ID |
Examples:
Self-managed with Key Vault persistence:
>>> from fabias.integrations import keyvault
>>> auth = RefreshTokenAuth(
... tenant_id="your-tenant-id",
... client_id="your-client-id",
... refresh_token=keyvault.get("graph-refresh-token"),
... on_refresh=lambda token: keyvault.set("graph-refresh-token", token)
... )
>>> token = auth.getToken("https://graph.microsoft.com/.default")
Delegated mode with external token broker:
>>> def get_from_broker(scope: str) -> tuple[str, datetime]:
... response = requests.post("https://my-function/api/token", json={"scope": scope})
... data = response.json()
... return data["access_token"], datetime.fromisoformat(data["expires_at"])
...
>>> auth = RefreshTokenAuth(
... tenant_id="your-tenant-id",
... client_id="your-client-id",
... token_provider=get_from_broker
... )
Warning
Self-managed mode is NOT safe for concurrent use across multiple jobs that might refresh the token simultaneously. For production multi-job scenarios, use delegated mode with a token broker service.
Source code in src/fabias/_shared/auth.py
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 | |
Attributes¶
refresh_token
property
¶
Get the current refresh token (may have been rotated).
Functions¶
__init__(tenant_id, client_id, refresh_token=None, on_refresh=None, token_provider=None)
¶
Initialize the refresh token authentication provider.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tenant_id
|
str
|
Azure AD tenant ID (GUID or domain) |
required |
client_id
|
str
|
Application (client) ID from Azure AD |
required |
refresh_token
|
Optional[str]
|
Initial refresh token (for self-managed mode) |
None
|
on_refresh
|
Optional[Callable[[str], None]]
|
Callback to persist new refresh token (for self-managed mode). Called with the new refresh_token string after each refresh. |
None
|
token_provider
|
Optional[Callable[[str], Tuple[str, datetime]]]
|
External function that returns (access_token, expiry) for a given scope (for delegated mode). If provided, refresh_token and on_refresh are ignored. |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If neither refresh_token nor token_provider is provided |
Source code in src/fabias/_shared/auth.py
getToken(scope)
¶
Get an access token for the specified scope.
Retrieves a cached token if still valid, otherwise acquires a new token using either the token_provider or refresh token flow.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scope
|
str
|
OAuth2 scope (e.g., "https://graph.microsoft.com/.default") |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Access token (without "Bearer " prefix) |
Raises:
| Type | Description |
|---|---|
AuthenticationError
|
If token acquisition fails |
Source code in src/fabias/_shared/auth.py
fabias.FabricAuth
¶
Bases: AuthProvider
Authentication provider using Fabric's notebookutils.
This provider leverages the notebookutils.credentials module available in Microsoft Fabric notebooks to obtain tokens without requiring explicit credentials.
Only works when running inside a Fabric notebook environment.
Examples:
>>> from fabias import runtime
>>> if runtime.isFabric:
... auth = FabricAuth()
... token = auth.getToken("https://api.fabric.microsoft.com/.default")
Source code in src/fabias/_shared/auth.py
Functions¶
__init__()
¶
Initialize the Fabric authentication provider.
Raises:
| Type | Description |
|---|---|
AuthenticationError
|
If not running inside Fabric environment |
Source code in src/fabias/_shared/auth.py
getToken(scope)
¶
Get an access token using notebookutils.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scope
|
str
|
OAuth2 scope (e.g., "https://api.fabric.microsoft.com/.default") |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Access token |
Raises:
| Type | Description |
|---|---|
AuthenticationError
|
If token acquisition fails |
Source code in src/fabias/_shared/auth.py
fabias.AutoAuth
¶
Bases: AuthProvider
Automatic authentication provider that selects the best method.
This provider automatically chooses between FabricAuth (when inside Fabric) and ServicePrincipalAuth (when standalone) based on the detected runtime environment.
For standalone usage, credentials must be provided either directly or via environment variables/configuration.
Examples:
Inside Fabric:
Standalone with explicit credentials:
Source code in src/fabias/_shared/auth.py
Functions¶
__init__(tenant_id=None, client_id=None, client_secret=None)
¶
Initialize with optional service principal credentials.
If running in Fabric, credentials are ignored. If running standalone, credentials are required.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tenant_id
|
Optional[str]
|
Azure AD tenant ID (for standalone) |
None
|
client_id
|
Optional[str]
|
Application client ID (for standalone) |
None
|
client_secret
|
Optional[str]
|
Client secret (for standalone) |
None
|
Source code in src/fabias/_shared/auth.py
getToken(scope)
¶
Get an access token using the automatically selected provider.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scope
|
str
|
OAuth2 scope |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Access token |
Source code in src/fabias/_shared/auth.py
Exceptions¶
fabias.FabiasError
¶
Bases: Exception
Base exception for all fabias errors.
Provides exception chaining support similar to Java's exception chaining, allowing nested exceptions to preserve the full error context.
Attributes:
| Name | Type | Description |
|---|---|---|
message |
str
|
Human-readable error description |
cause |
Exception
|
Original exception that caused this error, if any |
Examples:
>>> try:
... risky_operation()
... except SomeError as e:
... raise FabiasError("Operation failed", cause=e)
Source code in src/fabias/_shared/exceptions.py
Functions¶
__init__(message, cause=None)
¶
Initialize the exception with a message and optional cause.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
Human-readable error description |
required |
cause
|
Optional[Exception]
|
Original exception that caused this error |
None
|
Source code in src/fabias/_shared/exceptions.py
fabias.AuthenticationError
¶
Bases: FabiasError
Exception raised when authentication fails.
This exception is raised when: - OAuth2 token acquisition fails - Credentials are invalid or expired - Service principal authentication fails - notebookutils credentials are unavailable
Examples:
>>> try:
... token = auth.getToken()
... except AuthenticationError as e:
... print(f"Auth failed: {e.message}")
Source code in src/fabias/_shared/exceptions.py
fabias.ApiError
¶
Bases: FabiasError
Exception raised when an API request fails.
This exception is raised when: - HTTP request returns an error status code (4xx, 5xx) - Response cannot be parsed - Request times out - Network errors occur
Attributes:
| Name | Type | Description |
|---|---|---|
status_code |
int
|
HTTP status code, if available |
response_body |
Any
|
Response body content, if available |
Examples:
>>> try:
... response = client.get("/workspaces")
... except ApiError as e:
... print(f"API error {e.status_code}: {e.message}")
Source code in src/fabias/_shared/exceptions.py
Functions¶
__init__(message, cause=None, status_code=None, response_body=None)
¶
Initialize the API error with details.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
Human-readable error description |
required |
cause
|
Optional[Exception]
|
Original exception that caused this error |
None
|
status_code
|
Optional[int]
|
HTTP status code from the response |
None
|
response_body
|
Any
|
Response body content for debugging |
None
|
Source code in src/fabias/_shared/exceptions.py
fabias.NotFoundError
¶
Bases: ApiError
Exception raised when a requested resource is not found.
This is a specific case of ApiError for 404 responses. It provides clearer semantics when handling "not found" scenarios separately from other API errors.
Attributes:
| Name | Type | Description |
|---|---|---|
resource_type |
str
|
Type of resource that wasn't found |
resource_id |
str
|
Identifier of the missing resource |
Examples:
>>> try:
... workspace = client.workspace("nonexistent")
... except NotFoundError as e:
... print(f"{e.resource_type} '{e.resource_id}' not found")
Source code in src/fabias/_shared/exceptions.py
Functions¶
__init__(message, resource_type=None, resource_id=None, cause=None)
¶
Initialize the not found error with resource details.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
Human-readable error description |
required |
resource_type
|
Optional[str]
|
Type of resource (e.g., "Workspace", "Pipeline") |
None
|
resource_id
|
Optional[str]
|
Identifier that was searched for |
None
|
cause
|
Optional[Exception]
|
Original exception that caused this error |
None
|