API Reference¶
This page documents the Python API surface for azure-functions-scaffold.
Use it when embedding scaffold behavior in tests, custom automation, or other
developer tooling.
CLI-first project
The primary public interface is the command line (afs /
azure-functions-scaffold). Python imports are useful for advanced flows,
but CLI compatibility is the main stability target.
Module Overview¶
Core modules in the package:
azure_functions_scaffold.cli: Typer application and command handlers.azure_functions_scaffold.scaffolder: project scaffolding orchestration.azure_functions_scaffold.models: shared dataclasses for options and context.azure_functions_scaffold.generator: add-function workflow and code updates.azure_functions_scaffold.template_registry: template and preset discovery.azure_functions_scaffold.errors: domain-specific exception types.
Import Patterns¶
from pathlib import Path
from azure_functions_scaffold.models import ProjectOptions
from azure_functions_scaffold.scaffolder import (
describe_scaffold_project,
scaffold_project,
)
from azure_functions_scaffold.template_registry import build_project_options
options = build_project_options(
preset_name="strict",
python_version="3.12",
include_github_actions=True,
initialize_git=False,
include_openapi=True,
include_validation=True,
include_doctor=True,
)
preview = describe_scaffold_project(
project_name="my-api",
destination=Path("."),
template_name="http",
options=options,
)
for line in preview:
print(line)
project_path = scaffold_project(
project_name="my-api",
destination=Path("."),
template_name="http",
options=options,
)
print(project_path)
Error Handling¶
Most failures raise ScaffoldError with actionable messages.
from pathlib import Path
from azure_functions_scaffold.errors import ScaffoldError
from azure_functions_scaffold.scaffolder import scaffold_project
try:
scaffold_project(project_name="bad name", destination=Path("."))
except ScaffoldError as exc:
print(f"Scaffold failed: {exc}")
Common failure classes include:
- invalid project names
- unknown templates or presets
- unsupported Python versions
- target directory collisions without overwrite
- invalid
addproject roots
Stability Notes¶
Treat the following as stable integration points:
- CLI commands and flags in CLI Reference
- dataclasses in
azure_functions_scaffold.models - high-level orchestration functions in
azure_functions_scaffold.scaffolder
Treat internals as implementation details:
- private helpers prefixed with
_ - direct template file internals under
templates/ - insertion-marker implementation details in generator internals
Programmatic dry-run
Use describe_scaffold_project and describe_add_function to integrate
preview behavior in automation without touching the filesystem.
mkdocstrings Reference¶
The sections below are rendered directly from source using mkdocstrings.
CLI Module¶
callback(ctx, version=False)
¶
Azure Functions scaffold CLI.
Source code in src/azure_functions_scaffold/cli.py
legacy_add(ctx, trigger=typer.Argument(..., help='Trigger type (e.g. http, timer, queue).'), function_name=typer.Argument(..., help='Function name.'), project_root=typer.Option(Path('.'), '--project-root', '-p', help='Project root.'), dry_run=typer.Option(False, '--dry-run', help='Preview without writing files.'))
¶
DEPRECATED shim. Forwards to the modern command.
Source code in src/azure_functions_scaffold/cli.py
legacy_profiles()
¶
DEPRECATED shim. Forwards to 'afs presets'.
Source code in src/azure_functions_scaffold/cli.py
new(project_name=typer.Argument(..., help='Directory name for the new project.'), destination=Path('.'), python_version='3.10', include_github_actions=False, initialize_git=False, include_azd=False, dry_run=False, overwrite=False, yes=False)
¶
Create a new API project (shortcut for 'afs api new').
Source code in src/azure_functions_scaffold/cli.py
show_presets()
¶
List available project presets.
Source code in src/azure_functions_scaffold/cli.py
show_templates()
¶
Scaffolder Module¶
Models Module¶
IntentSpec(template, preset, features=frozenset())
dataclass
¶
Maps a CLI intent (e.g. 'api/new') to its template, preset, and features.
Additional Useful Modules¶
These modules are often imported by advanced users even though they are not the primary API entry points.
azure_functions_scaffold.generator¶
Use for adding triggers to existing projects:
add_function(...)describe_add_function(...)SUPPORTED_TRIGGERSADDABLE_TRIGGERS- Tuple of trigger names that can be added to an existing project via 'afs advanced add'. Excludes templates (e.g. langgraph) that only support full project creation.
azure_functions_scaffold.template_registry¶
Use for template/preset discovery and input validation:
list_templates()list_presets()build_project_options(...)validate_python_version(...)
azure_functions_scaffold.errors¶
Domain exception:
ScaffoldError