SAService Architect Back to designer
SAService ArchitectDocumentation
Python API reference ServiceArchitectClient.from_env().generate_code(project)

ServiceArchitectClient and archive API

Low-level reusable API for authenticated generation and validated ZIP handling.

When to use

Use Project.generate_code for one request; use ServiceArchitectClient directly when sharing configuration and an in-memory token.

Behavior

  • The client authenticates lazily on the first request when no explicit ID token is supplied.
  • Successful authentication is cached in memory for subsequent requests on the same client.
  • Responses support the designer API Gateway JSON/base64 envelope and direct application/zip responses.
  • GeneratedProjectArchive validates ZIP structure before it is returned.

ServiceArchitectClient() properties

Explicit client configuration.

PropertyTypeDescription
id_tokenstr | None

Existing Cognito ID token.

Default: None
username / passwordstr | None

Credentials used for SRP when id_token is absent.

Default: None
base_urlstr | None

Service Architect API root or environment override.

Default: configured API
timeoutfloat

Generation request timeout in seconds.

Default: 120
from_env(env_file=".env", **overrides)ServiceArchitectClient

Load standard SERVICE_ARCHITECT_* variables.

generate_code(project)GeneratedProjectArchive

Send the Project and decode the response.

GeneratedProjectArchive properties

Immutable returned artifact.

PropertyTypeDescription
filenamestr

SanSafe filename from Content-Disposition.

contentbytes

Validated ZIP bytes.

save(path)Path

Write content and return destination path.

Error classes properties

Structured failure information.

PropertyTypeDescription
AuthenticationErrorRuntimeError

Cognito rejection, unsupported challenge, invalid SRP values, or connectivity failure; details retains safe response context.

CodeGenerationErrorRuntimeError

HTTP, API payload, JSON, base64, or ZIP failure; status_code and details are available.

DslValidationErrorValueError

Invalid object ownership, references, duplicates, or graph operations.

Python example

client = ServiceArchitectClient.from_env()
try:
    archive = client.generate_code(project)
    archive.save(f"dist/{archive.filename}")
except AuthenticationError as error:
    handle_authentication_failure(error)
except CodeGenerationError as error:
    handle_generation_failure(error.status_code, error.details)