Skip to content

Governance Standards Application Python

Joshua Davis edited this page Apr 1, 2026 · 3 revisions

Python

Standards for generated Python application code, including project structure, dependency management, and Azure SDK patterns.

5 principles


ID Principle Rationale
STAN-PY-001 Use Azure SDK with DefaultAzureCredential Always use DefaultAzureCredential from azure-identity for authenticating to Azure services. This wo
STAN-PY-002 Project Structure Python projects must have a clear structure: src/ for application code, tests/ for tests, requiremen
STAN-PY-003 Configuration via Environment Variables Use environment variables for all configuration (loaded via os.environ or a settings class). Never
STAN-PY-004 Async for I/O-Bound Operations Use async/await for HTTP handlers, database queries, and external API calls. Synchronous I/O blocks
STAN-PY-005 Type Annotations Use type annotations on all function signatures and return types. This enables IDE support, document

STAN-PY-001: Use Azure SDK with DefaultAzureCredential

Always use DefaultAzureCredential from azure-identity for authenticating to Azure services. This works with managed identity in Azure and developer credentials locally.

Applies to: app-developer

Examples:

  • from azure.identity import DefaultAzureCredential
  • credential = DefaultAzureCredential()
  • Never pass connection strings when managed identity is available

STAN-PY-002: Project Structure

Python projects must have a clear structure: src/ for application code, tests/ for tests, requirements.txt or pyproject.toml for dependencies. Use packages (directories with init.py) for logical grouping.

Applies to: app-developer

Examples:

  • src/app/ — application package
  • src/app/main.py — entry point
  • src/app/routes/ — API route handlers
  • src/app/services/ — business logic
  • tests/ — test files

STAN-PY-003: Configuration via Environment Variables

Use environment variables for all configuration (loaded via os.environ or a settings class). Never hardcode service URLs, ports, or feature flags.

Applies to: app-developer

Examples:

  • import os; port = int(os.environ.get('PORT', 8080))
  • Use pydantic Settings class for type-safe config

STAN-PY-004: Async for I/O-Bound Operations

Use async/await for HTTP handlers, database queries, and external API calls. Synchronous I/O blocks the event loop and reduces throughput.

Applies to: app-developer

Examples:

  • async def get_items(db: AsyncSession) -> list[Item]:
  • Use aiohttp or httpx for async HTTP clients

STAN-PY-005: Type Annotations

Use type annotations on all function signatures and return types. This enables IDE support, documentation, and static analysis.

Applies to: app-developer

Examples:

  • def get_user(user_id: str) -> User | None:
  • async def create_order(order: OrderCreate) -> OrderResponse:

Home

Getting Started

Stages

Interfaces

Configuration

Agent System

Features

Quality

Help

Governance

Policies — Azure

AI Services

Compute

Data Services

Identity

Management

Messaging

Monitoring

Networking

Security

Storage

Web & App

Policies — Well-Architected

Reliability

Security

Cost Optimization

Operational Excellence

Performance Efficiency

Integration

Anti-Patterns
Standards

Application

IaC

Principles

Transforms

Clone this wiki locally