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.
id_tokenstr | NoneExisting Cognito ID token.
Default:Noneusername / passwordstr | NoneCredentials used for SRP when id_token is absent.
Default:Nonebase_urlstr | NoneService Architect API root or environment override.
Default:configured APItimeoutfloatGeneration request timeout in seconds.
Default:120from_env(env_file=".env", **overrides)ServiceArchitectClientLoad standard SERVICE_ARCHITECT_* variables.
generate_code(project)GeneratedProjectArchiveSend the Project and decode the response.
GeneratedProjectArchive properties
Immutable returned artifact.
filenamestrSanSafe filename from Content-Disposition.
contentbytesValidated ZIP bytes.
save(path)PathWrite content and return destination path.
Error classes properties
Structured failure information.
AuthenticationErrorRuntimeErrorCognito rejection, unsupported challenge, invalid SRP values, or connectivity failure; details retains safe response context.
CodeGenerationErrorRuntimeErrorHTTP, API payload, JSON, base64, or ZIP failure; status_code and details are available.
DslValidationErrorValueErrorInvalid 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)