API Reference¶
The public entry point for programmatic usage is
azure_functions_doctor.api.run_diagnostics(path, profile, rules_path, target_python).
It uses the same diagnostics engine as azure-functions-doctor doctor, then returns
structured results that can be consumed in scripts, CI pipelines, or custom tooling.
Public API at a Glance¶
| API | Purpose | Typical usage |
|---|---|---|
run_diagnostics(path, profile, rules_path, target_python) |
Run all checks and return section-level results. | CI validation, custom wrappers, pre-commit hooks. |
Doctor(path, profile, rules_path, target_python) |
Lower-level runner with explicit lifecycle methods. | Advanced control over rule loading and execution. |
CheckResult |
Result object for one check item. | Output processing and custom reporting. |
SectionResult |
Result object for a group of checks. | Rendering grouped summaries by category. |
HandlerRegistry |
Maps rule type to execution handlers. |
Handler extension and internal diagnostics flow. |
Programmatic Usage with run_diagnostics¶
Use run_diagnostics when you want behavior that matches the CLI while staying
inside Python code.
from pathlib import Path
from azure_functions_doctor.api import run_diagnostics
def summarize_failures(project_path: str) -> int:
results = run_diagnostics(path=project_path, profile="full", rules_path=None)
failed_required = 0
for section in results:
for item in section["items"]:
if item["status"] == "fail":
failed_required += 1
return failed_required
if __name__ == "__main__":
target = str(Path(".").resolve())
failed = summarize_failures(target)
raise SystemExit(1 if failed else 0)
Parameters¶
| Parameter | Type | Required | Description |
|---|---|---|---|
path |
str |
Yes | File system path to the Azure Functions app root. |
profile |
str \| None |
No | Rule profile: "minimal" (required checks only), "deploy" (runtime/hosting/deployment correctness), "development" (dev-environment checks), or "full" (default behavior: all rules). |
rules_path |
pathlib.Path | None |
No | Optional path to a custom rules file matching the rules schema. |
target_python |
str | None |
No | Override target Python runtime version (e.g. "3.12"). Defaults to None (use tool runtime). |
Return Value¶
run_diagnostics returns list[SectionResult], where each section includes:
title: human-readable section titlecategory: machine-friendly section keystatus:passorfailat section levelitems: list ofCheckResultentries
Working with CheckResult and SectionResult¶
The following snippet shows safe access to optional fields (hint, hint_url)
while creating a report.
from azure_functions_doctor.api import run_diagnostics
def flatten_results(path: str) -> list[dict[str, str]]:
rows: list[dict[str, str]] = []
for section in run_diagnostics(path=path, profile=None, rules_path=None):
for item in section["items"]:
rows.append(
{
"section": section["category"],
"label": item["label"],
"status": item["status"],
"value": item["value"],
"hint": item.get("hint", ""),
"hint_url": item.get("hint_url", ""),
}
)
return rows
Using Doctor Directly¶
Use Doctor if you need to separate rule loading, validation, and execution.
from pathlib import Path
from azure_functions_doctor.doctor import Doctor
def run_with_custom_rules(project_dir: str, custom_rules_file: str) -> list[dict]:
doctor = Doctor(
path=project_dir,
profile="minimal",
rules_path=Path(custom_rules_file),
)
rules = doctor.load_rules()
return doctor.run_all_checks(rules=rules)
Handler Registry Integration¶
HandlerRegistry stores the mapping from rule type to concrete handler methods.
Most users do not need to call it directly, but it is useful in internal extensions.
from pathlib import Path
from azure_functions_doctor.handlers import HandlerRegistry
def run_single_rule(rule: dict, project_path: str) -> dict[str, str]:
registry = HandlerRegistry()
result = registry.handle(rule=rule, path=Path(project_path))
return result
CLI¶
azure_functions_alias()
¶
doctor(path='.', verbose=False, debug=False, format='table', output=None, profile=None, rules=None, summary_json=None, target_python=None, deployment_mode='remote-build', hosting_plan=None)
¶
Run diagnostics on an Azure Functions application.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Path to the Azure Functions app. Defaults to current directory. |
'.'
|
verbose
|
Annotated[bool, Option(-v, --verbose, help='Show detailed hints for failed checks')]
|
Show detailed hints for failed checks. |
False
|
debug
|
Annotated[bool, Option(help='Enable debug logging')]
|
Enable debug logging to stderr. |
False
|
format
|
Annotated[str, Option(help="Output format: 'table', 'json', 'sarif', or 'junit'")]
|
Output format: 'table', 'json', 'sarif', or 'junit'. |
'table'
|
output
|
Annotated[Optional[Path], Option(help='Optional path to save output result')]
|
Optional file path to save output result. |
None
|
profile
|
Annotated[Optional[str], Option(help="Rule profile: 'minimal' (required gating checks), 'deploy' (Azure runtime/hosting/deployment correctness), 'development' (local dev-environment checks), or 'full' (all rules).")]
|
Optional rule profile ('minimal', 'deploy', 'development', or 'full'). |
None
|
rules
|
Annotated[Optional[Path], Option(help='Optional path to a custom rules file')]
|
Optional path to a custom rules file. |
None
|
summary_json
|
Annotated[Optional[Path], Option(--summary - json, help='Write a JSON summary of counts (passed/warned/failed) to this path')]
|
Path to write a JSON summary with passed/warned/failed counts. |
None
|
target_python
|
Annotated[Optional[str], Option(--target - python, help='Override target Python runtime')]
|
Optional target Python runtime override. |
None
|
Source code in src/azure_functions_doctor/cli.py
166 167 168 169 170 171 172 173 174 175 176 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 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 | |
fdoctor_alias()
¶
main()
¶
Console-script entry point that tolerates the omitted subcommand.
normalize_argv(argv)
¶
Insert the implicit doctor subcommand when it is omitted (#399).
doctor is the only command, so the top level accepts the same options:
azure-functions-doctor --path . --format json behaves identically to
azure-functions-doctor doctor --path . --format json. Pure function so
the dispatch is unit-testable without spawning a process.
Source code in src/azure_functions_doctor/cli.py
Doctor¶
Doctor(path='.', profile=None, rules_path=None, target_python=None, deployment_mode='remote-build', hosting_plan=None)
¶
Diagnostic runner for Azure Functions apps.
Loads checks from the built-in Azure Functions Python v2 rule asset
located at azure_functions_doctor.assets.rules.v2.json.
Source code in src/azure_functions_doctor/doctor.py
get_report_properties()
¶
Return top-level report properties shared across output formats.
Source code in src/azure_functions_doctor/doctor.py
load_rules()
¶
Load and validate rules from a custom path or the built-in v2 ruleset.
Source code in src/azure_functions_doctor/doctor.py
profiles_for_rule(rule)
¶
Return the profile names rule participates in, widest-last.
rule_matches_profile(rule, profile)
¶
Return whether rule runs under the given profile.
full: every rule.minimal: required (gating) rules only.deploy: core-group rules covering Azure runtime/hosting/deployment correctness; developer-environment and integration rules are excluded.development: developer-environment checks (virtual environment, Python executable, Core Tools, local.settings existence).
Source code in src/azure_functions_doctor/profiles.py
Handlers¶
Diagnostic check handlers for Azure Functions Doctor.
This package was split from a single handlers.py module. The public API
is preserved: import from azure_functions_doctor.handlers exactly as
before. Implementation lives in :mod:._helpers (pure helpers and types) and
:mod:.registry (the HandlerRegistry dispatch class).
DoctorConfig
¶
Bases: TypedDict
Resolved [tool.azure-functions-doctor] project configuration.
HandlerRegistry()
¶
Bases: GenericHandlers, DependencyHandlers, RuntimeHandlers, MonitoringHandlers, DeploymentHandlers, BindingHandlers, ProjectHandlers, DurableHandlers, IntegrationHandlers
Registry for diagnostic check handlers with individual handler methods.
Source code in src/azure_functions_doctor/handlers/registry.py
handle(rule, path, context=None)
¶
Route rule execution to appropriate handler.
Source code in src/azure_functions_doctor/handlers/registry.py
ResolvedField(value, source)
dataclass
¶
A resolved configuration value together with its provenance.
is_known
property
¶
Return True when a concrete value was resolved.
TargetConfig(hosting_plan, runtime_name, runtime_version, extension_version, deployment_storage, app_settings=dict(), app_settings_files=dict())
dataclass
¶
The resolved target Azure configuration, one source of truth for handlers.
unknown()
classmethod
¶
Return a fully-unknown config (used when nothing can be resolved).
Source code in src/azure_functions_doctor/deploy_config.py
generic_handler(rule, path, context=None)
¶
Execute a diagnostic rule based on its type and condition.
This function maintains backward compatibility while delegating to the registry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rule
|
Rule
|
The diagnostic rule to execute. |
required |
path
|
Path
|
Path to the Azure Functions project. |
required |
Returns:
| Type | Description |
|---|---|
HandlerResult
|
A dictionary with the status and detail of the check. |
Source code in src/azure_functions_doctor/handlers/registry.py
iter_project_files(project_path, patterns)
¶
Single entry point for project file traversal (issue #393).
Yields files under project_path matching patterns (rglob syntax),
honoring EXCLUDED_PROJECT_DIRS and the user's
[tool.azure-functions-doctor].exclude globs. Handlers must traverse
through this helper instead of calling Path.rglob directly so
virtualenvs, node_modules, caches, and user excludes are never scanned -
a regression test forbids raw rglob outside this module.
Source code in src/azure_functions_doctor/handlers/_helpers.py
load_doctor_config(path)
¶
Load [tool.azure-functions-doctor] settings from pyproject.toml.
Returns ignore (rule ids to suppress and report as skip) and
exclude (extra path globs layered on top of EXCLUDED_PROJECT_DIRS).
Missing files, tables, or keys yield empty lists. Only string list entries
are honored; malformed values are ignored rather than raising.
Source code in src/azure_functions_doctor/handlers/_helpers.py
reset_extra_excludes(token)
¶
resolve_target_config(project_path, overrides=None)
¶
Resolve the target Azure configuration for project_path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
project_path
|
Path
|
Root of the project under diagnosis. |
required |
overrides
|
Optional[Mapping[str, Optional[str]]]
|
Optional CLI overrides. Recognized keys are |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
A |
TargetConfig
|
class: |
TargetConfig
|
infrastructure or signal is found, all fields are |
Source code in src/azure_functions_doctor/deploy_config.py
resolve_target_value(target, override=None)
¶
Resolve the current value of a target used in version comparison or diagnostics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target
|
str
|
The name of the target to resolve. Examples include "python" or "func_core_tools". |
required |
Returns:
| Type | Description |
|---|---|
str
|
A string representing the resolved version or value. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the target is not recognized. |
Source code in src/azure_functions_doctor/target_resolver.py
set_extra_excludes(root, globs)
¶
Set the active extra-exclude globs and return a reset token.
Source code in src/azure_functions_doctor/handlers/_helpers.py
Target Resolver¶
is_supported_python_for_plan(version, plan)
¶
Return True when version is supported on the given hosting plan.
Only the major.minor components are considered. Unknown plans fall back to
the plan-agnostic :func:is_supported_python_target check so callers never
reject a version merely because the plan name is unrecognized.
Source code in src/azure_functions_doctor/target_resolver.py
is_supported_python_target(version)
¶
Return True when version's major.minor is a supported Azure target.
Only the major and minor components are considered, so patch releases such
as "3.14.2" are supported while "3.15.0" and "3.9.1" are not.
Source code in src/azure_functions_doctor/target_resolver.py
resolve_python_target(project_path=None, override=None)
¶
Resolve the Python version to diagnose against, with provenance.
Precedence (first match wins):
- Explicit
override(e.g.--target-python) -> source"override". .python-versionfile -> source".python-version".- The running interpreter -> source
"tool-runtime"(always resolves).
The [project] requires-python value in pyproject.toml is deliberately
NOT used as the target: it declares a compatibility floor, not the
interpreter the app will actually be deployed against, so treating it as the
target masks unsupported runtimes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
project_path
|
Optional[Path]
|
Root of the project under diagnosis. When |
None
|
override
|
Optional[str]
|
Explicit target that short-circuits project detection. |
None
|
Returns:
| Type | Description |
|---|---|
Tuple[str, str]
|
A |
Source code in src/azure_functions_doctor/target_resolver.py
resolve_target_value(target, override=None)
¶
Resolve the current value of a target used in version comparison or diagnostics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target
|
str
|
The name of the target to resolve. Examples include "python" or "func_core_tools". |
required |
Returns:
| Type | Description |
|---|---|
str
|
A string representing the resolved version or value. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the target is not recognized. |
Source code in src/azure_functions_doctor/target_resolver.py
Utility¶
format_detail(status, value)
¶
Return a colored Text element based on status and value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
status
|
str
|
Diagnostic status ("pass", "fail", "warn", "skip"). |
required |
value
|
str
|
Text to display, typically a description. |
required |
Returns:
| Type | Description |
|---|---|
Text
|
A Rich Text object styled with status color. |
Source code in src/azure_functions_doctor/utils.py
format_freshness_line(last_verified, source_url='')
¶
Render the Finding Contract v2 freshness line for date/compat findings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
last_verified
|
str
|
The |
required |
source_url
|
str
|
Optional authoritative source URL for the fact. |
''
|
Returns:
| Type | Description |
|---|---|
str
|
A human-readable |
str
|
URL appended when available. Returns an empty string when |
str
|
|
Source code in src/azure_functions_doctor/utils.py
format_result(status)
¶
Return a styled icon Text element based on status.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
status
|
str
|
Diagnostic status ("pass", "fail", "warn", "skip"). |
required |
Returns:
| Type | Description |
|---|---|
Text
|
A Rich Text object with icon and style for headers. |
Source code in src/azure_functions_doctor/utils.py
format_status_icon(status)
¶
Return a simple icon character based on status.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
status
|
str
|
Diagnostic status ("pass", "fail", "warn", "skip"). |
required |
Returns: A string icon such as ✓, !, or ✗.