API Reference¶
The public entry point for programmatic usage is
azure_functions_doctor.api.run_diagnostics(path, profile, rules_path).
It uses the same diagnostics engine as azure-functions 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) |
Run all checks and return section-level results. | CI validation, custom wrappers, pre-commit hooks. |
Doctor(path, profile, rules_path) |
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. |
Config |
Environment-backed runtime configuration container. | Internal integration and test overrides. |
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 | "full" (default behavior) or "minimal" (required checks only). |
rules_path |
pathlib.Path | None |
No | Optional path to a custom rules file matching the rules schema. |
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)
Configuration API (Config)¶
Config reads defaults and environment variables prefixed with FUNC_DOCTOR_.
Common keys include:
FUNC_DOCTOR_LOG_LEVELFUNC_DOCTOR_LOG_FORMATFUNC_DOCTOR_MAX_FILE_SIZE_MBFUNC_DOCTOR_SEARCH_TIMEOUT_SECONDSFUNC_DOCTOR_OUTPUT_WIDTHFUNC_DOCTOR_ENABLE_COLORSFUNC_DOCTOR_PARALLEL_EXECUTION
from azure_functions_doctor.config import get_config, override_config
def configure_for_tests() -> dict:
override_config(log_level="DEBUG", output_width=100, enable_colors=False)
cfg = get_config()
return cfg.to_dict()
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¶
doctor(path='.', verbose=False, debug=False, format='table', output=None, profile=None, rules=None, summary_json=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' or 'full'")]
|
Optional rule profile ('minimal' 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
|
Source code in src/azure_functions_doctor/cli.py
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 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 | |
Doctor¶
Doctor(path='.', profile=None, rules_path=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
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
Handlers¶
HandlerRegistry()
¶
Registry for diagnostic check handlers with individual handler methods.
Source code in src/azure_functions_doctor/handlers.py
handle(rule, path)
¶
Route rule execution to appropriate handler.
Source code in src/azure_functions_doctor/handlers.py
generic_handler(rule, path)
¶
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 |
|---|---|
dict[str, str]
|
A dictionary with the status and detail of the check. |
Source code in src/azure_functions_doctor/handlers.py
Configuration¶
Configuration management for Azure Functions Doctor.
Environment variables with FUNC_DOCTOR_ prefix (e.g. FUNC_DOCTOR_LOG_LEVEL) are loaded into Config. These options are reserved for future use; the CLI currently configures logging via logging_config.setup_logging() and does not read from Config. When wiring Config into the CLI/Doctor (e.g. max_file_size_mb, search_timeout_seconds), update this module and the CLI entry point.
Config()
¶
Centralized configuration management with environment variable support.
Options (max_file_size_mb, search_timeout_seconds, etc.) are for future use; not yet wired into the CLI or Doctor. Use get_config() to access the global instance.
Source code in src/azure_functions_doctor/config.py
get(key, default=None)
¶
get_custom_rules_path()
¶
Get custom rules file path from environment.
Source code in src/azure_functions_doctor/config.py
get_log_format()
¶
get_log_level()
¶
get_max_file_size_mb()
¶
get_output_width()
¶
get_rules_file()
¶
get_search_timeout_seconds()
¶
is_colors_enabled()
¶
is_parallel_execution_enabled()
¶
set(key, value)
¶
get_config()
¶
override_config(**kwargs)
¶
Target Resolver¶
resolve_target_value(target)
¶
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"). |
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_result(status)
¶
Return a styled icon Text element based on status.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
status
|
str
|
Diagnostic status ("pass", "fail", "warn"). |
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"). |
required |
Returns: A string icon such as ✓, !, or ✗.