Press Apps
Import the press app module and Instantiate a press-app
client
[ ]:
from collections.abc import Iterator
from typing import Any
from peak.press import apps
client: apps.App = apps.get_client()
Possible field values
Scope
The scope of the app. The following scopes are supported: private
, public
, and shared
.
Spec status
The status of the app specs. The following statuses are supported: available
, unavailable
, and archived
.
Deployment status
The status of the app deployments. The following statuses are supported: deployed
, deploying
, failed
, redeploying
, deleting
, delete_failed
, platform_resource_error
, rollback
, rollback_complete
, rollback_failed
and warning
.
Prepare an app-spec
payload and create an app-spec
[ ]:
spec_body: dict[str, Any] = {
"version": "1",
"kind": "app",
"metadata": {
"name": "sdk",
"title": "New App Spec",
"summary": "Create new app spec",
"description": "Creating app spec from SDK",
"descriptionContentType": "text/markdown",
"imageUrl": "https://my-spec-pics.com/image-1.jpg",
"tags": [
{
"name": "sdk",
},
],
},
"release": {
"version": "1.0.0",
"notes": "This is the original release",
},
"config": [
{
"id": "0bddb4c6-40c5-45c3-b477-fceb2c051609",
"release": {
"version": "1.0.0",
},
"autoRunOnDeploy": True,
},
{
"id": "1jgf45hk-38h6-22h6-b460-aceb2c385790",
"release": {
"version": "1.0.0",
},
"autoRunOnDeploy": False,
},
],
}
created_app_spec: dict[str, str] = client.create_spec(
body=spec_body,
featured=True,
scope="shared",
tenants=["tenant1", "tenant2"],
)
List created app-spec
(s) and iterate over them
[ ]:
spec_iterator: Iterator[dict[str, Any]] = client.list_specs()
spec_iterated: dict[str, Any] = next(spec_iterator)
"""
The list of app specs will be returned in the following format:
{
"pageCount": 1,
"pageNumber": 1,
"pageSize": 25,
"specCount": 1,
"specs": [
{
"featured": false,
"id": "a3e77006-86f3-4829-8c43-f21ad462dbbd",
"kind": "app",
"latestRelease": {
"createdAt": "2020-01-01T18:00:00.000Z",
"createdBy": "jane.smith@peak.ai",
"id": "6a6b9e08-638e-4116-a29d-077086135062",
"notes": "This is the original release",
"version": "1.0.0"
},
"metadata": {
"createdAt": "2020-01-01T18:00:00.000Z",
"createdBy": "jane.smith@peak.ai",
"description": "This App loads Opportunities and Accounts tables from Salesforce into Peak-managed Snowflake. It then runs a modelling pipeline to predict account churn. Finally it sets up an analytics dashboard for tracking customer behaviours including churn propensity.",
"descriptionContentType": "text/markdown",
"imageUrl": "https://my-spec-pics.com/image-1.jpg",
"name": "salesforce-customer-analytics",
"status": "available",
"summary": "This app packages up Block specs to enable analyses on salesforce customers",
"tags": [
{
"name": "salesforce"
}
],
"title": "Salesforce Customer Analytics",
"updatedAt": "2020-01-01T18:00:00.000Z",
"updatedBy": "jane.smith@peak.ai"
},
"scope": "private",
"tenants": []
}
]
}
"""
Describe an already existing app-spec
[ ]:
existing_spec: dict[str, Any] = client.describe_spec(created_app_spec["id"])
"""
The app spec details will be returned in the following format:
{
"featured": false,
"id": "a3e77006-86f3-4829-8c43-f21ad462dbbd",
"kind": "app",
"latestRelease": {
"config": [
{
"id": "0bddb4c6-40c5-45c3-b477-fceb2c051609",
"release": {
"version": "1.0.0"
},
"autoRunOnDeploy": true
},
{
"id": "1jgf45hk-38h6-22h6-b460-aceb2c385790",
"release": {
"version": "1.0.0"
},
"autoRunOnDeploy": false
}
],
"createdAt": "2020-01-01T18:00:00.000Z",
"createdBy": "jane.smith@peak.ai",
"id": "6a6b9e08-638e-4116-a29d-077086135062",
"notes": "This is the original release",
"version": "1.0.0"
},
"metadata": {
"createdAt": "2020-01-01T18:00:00.000Z",
"createdBy": "jane.smith@peak.ai",
"description": "This App loads Opportunities and Accounts tables from Salesforce into Peak-managed Snowflake. It then runs a modelling pipeline to predict account churn. Finally it sets up an analytics dashboard for tracking customer behaviours including churn propensity.",
"descriptionContentType": "text/markdown",
"imageUrl": "https://my-spec-pics.com/image-1.jpg",
"name": "salesforce-customer-analytics",
"status": "available",
"summary": "This app packages up Block specs to enable analyses on salesforce customers",
"tags": [
{
"name": "salesforce"
}
],
"title": "Salesforce Customer Analytics",
"updatedAt": "2020-01-01T18:00:00.000Z",
"updatedBy": "jane.smith@peak.ai"
},
"scope": "private",
"tenants": []
}
"""
Update an app-spec
’s metadata
[ ]:
client.update_spec_metadata(
created_app_spec["id"],
body={
"metadata": {
"name": "sdk-update",
"description": "Update description from the SDK",
"status": "available",
},
"featured": True,
},
)
Create a new app-spec
release with updated config and release
[ ]:
body: dict[str, Any] = {
"config": [
{
"id": "0bddb4c6-40c5-45c3-b477-fceb2c051609",
"release": {
"version": "2.0.0",
},
"autoRunOnDeploy": True,
},
{
"id": "1jgf45hk-38h6-22h6-b460-aceb2c385790",
"release": {
"version": "2.0.0",
},
"autoRunOnDeploy": False,
},
],
"release": {
"version": "2.0.0",
"notes": "This is a revised release",
},
}
new_spec_release: dict[str, str] = client.create_spec_release(
spec_id=created_app_spec["id"],
body=body,
)
Describe the app-spec
release
[ ]:
app_spec_release_info: dict[str, Any] = client.describe_spec_release(new_spec_release["id"], "2.0.0")
"""
The app spec release details will be returned in the following format:
{
"config": [
{
"id": "0bddb4c6-40c5-45c3-b477-fceb2c051609",
"release": {
"version": "2.0.0"
},
"autoRunOnDeploy": true
},
{
"id": "1jgf45hk-38h6-22h6-b460-aceb2c385790",
"release": {
"version": "2.0.0"
},
"autoRunOnDeploy": false
}
],
"createdAt": "2020-01-01T18:00:00.000Z",
"createdBy": "jane.smith@peak.ai",
"id": "6a6b9e08-638e-4116-a29d-077086135062",
"notes": "This is the original release"
}
"""
List all app-spec
release(s) and iterate over them
[ ]:
releases_iterator: Iterator[dict[str, Any]] = client.list_spec_releases(
spec_id=created_app_spec["id"],
sort=["createdBy"],
)
releases_iterated: dict[str, Any] = next(releases_iterator)
"""
The list of app spec releases will be returned in the following format:
{
"pageCount": 1,
"pageNumber": 1,
"pageSize": 25,
"releaseCount": 1,
"releases": [
{
"createdAt": "2020-01-01T18:00:00.000Z",
"createdBy": "jane.smith@peak.ai",
"id": "6a6b9e08-638e-4116-a29d-077086135062",
"notes": "This is the original release",
"version": "1.0.0"
}
]
}
"""
Create a new deployment
from an existing app-spec
release
[ ]:
deployment: dict[str, str] = client.create_deployment(
body={
"metadata": {
"description": "Creating a new deployment.",
"descriptionContentType": "text/markdown",
"imageUrl": "https://my-spec-pics.com/image-1.jpg",
"name": "new-deployment",
"summary": "This creates a new deployment",
"tags": [
{
"name": "sdk",
},
],
"title": "New Deployment",
},
"parameters": {
"workflow-block-private": {
"run": {
"agg_type": "AVG",
"email_notifications": True,
"num_iterations": 50,
"file_names": ["input.csv", "output.csv"],
},
},
"webapp-block-private": {
"run": {
"agg_type": "MAX",
"email_notifications": False,
"num_iterations": 10,
"file_names": ["input.csv", "output.csv"],
},
},
},
"revision": {
"notes": "This is the initial revision",
},
"spec": {
"id": created_app_spec["id"],
"release": {
"version": "1.0.0",
},
},
},
)
List all existing deployment
(s) and iterate over them
[ ]:
deployments_iterator: Iterator[dict[str, Any]] = client.list_deployments()
deployments: dict[str, Any] = next(deployments_iterator)
"""
The list of app deployments will be returned in the following format:
{
"deploymentCount": 1,
"deployments": [
{
"id": "db283fc2-9164-4027-b09e-8c1ecedb122b",
"kind": "app",
"latestRevision": {
"createdAt": "2020-01-01T18:00:00.000Z",
"createdBy": "jane.smith@peak.ai",
"id": "2fa92990-3183-40fd-8c93-7ded5a99f705",
"notes": "This is the initial revision",
"revision": 1,
"status": "deploying"
},
"metadata": {
"createdAt": "2020-01-01T18:00:00.000Z",
"createdBy": "jane.smith@peak.ai",
"description": "This App loads Opportunities and Accounts tables from Salesforce into Peak-managed Snowflake. It then runs a modelling pipeline to predict account churn. Finally it sets up an analytics dashboard for tracking customer behaviours including churn propensity.",
"descriptionContentType": "text/markdown",
"imageUrl": "https://my-spec-pics.com/image-1.jpg",
"name": "sca-deployment",
"status": "deploying",
"summary": "This app packages up Block specs to enable analyses on salesforce customers",
"tags": [
{
"name": "salesforce"
}
],
"title": "SCA Deployment",
"updatedAt": "2020-01-01T18:00:00.000Z",
"updatedBy": "jane.smith@peak.ai"
},
"spec": {
"id": "a3e77006-86f3-4829-8c43-f21ad462dbbd",
"release": {
"currentVersion": "1.0.0",
"latestVersion": "1.0.0"
}
}
}
],
"pageCount": 1,
"pageNumber": 1,
"pageSize": 25
}
"""
Describe an existing deployment
[ ]:
existing_deployment: dict[str, Any] = client.describe_deployment(deployment["id"])
"""
The app deployment details will be returned in the following format:
{
"id": "a3e77006-86f3-4829-8c43-f21ad462dbbd",
"kind": "app",
"latestRevision": {
"artifact": {
"id": "721d738a-29f3-43b2-af52-c9055abe60b6",
"version": 1
},
"blocks": [
{
"deploymentId": "e04e308d-98dc-4443-bb02-c4ef990a3fdc",
"platformId": "9e1389f2-564c-4d60-80cf-5369d8a5a204",
"kind": "workflow",
"name": "lso-deployment",
"revision": 1,
"status": "deploying"
}
],
"createdAt": "2020-01-01T18:00:00.000Z",
"createdBy": "jane.smith@peak.ai",
"id": "2fa92990-3183-40fd-8c93-7ded5a99f705",
"notes": "This is the initial revision",
"revision": 1,
"status": "deploying"
},
"metadata": {
"createdAt": "2020-01-01T18:00:00.000Z",
"createdBy": "jane.smith@peak.ai",
"description": "This App loads Opportunities and Accounts tables from Salesforce into Peak-managed Snowflake. It then runs a modelling pipeline to predict account churn. Finally it sets up an analytics dashboard for tracking customer behaviours including churn propensity.",
"descriptionContentType": "text/markdown",
"imageUrl": "https://my-spec-pics.com/image-1.jpg",
"name": "sca-deployment",
"status": "deploying",
"summary": "This app packages up Block specs to enable analyses on salesforce customers",
"tags": [
{
"name": "salesforce"
}
],
"title": "SCA Deployment",
"updatedAt": "2020-01-01T18:00:00.000Z",
"updatedBy": "jane.smith@peak.ai"
},
"spec": {
"id": "a3e77006-86f3-4829-8c43-f21ad462dbbd",
"release": {
"currentVersion": "1.0.0",
"latestVersion": "1.0.0"
}
}
}
"""
Update an existing deployment
’s metadata
[ ]:
updated_deployment_body = {
"description": "Updated description",
"descriptionContentType": "text/markdown",
"imageUrl": "https://my-spec-pics.com/image-1.jpg",
"name": "updated-deployment",
"summary": "Updating the deployment metadata",
"tags": [
{
"name": "sdk",
},
],
"title": "Updated Deployment",
}
client.update_deployment_metadata(deployment["id"], body=updated_deployment_body)
Redeploy an existing app deployment
[ ]:
# This will redeploy the latest revision of an existing app deployment if the deployment is in `failed` or `warning` state and provided at least one of its block deployments is also in a `failed` or `warning` state.
client.redeploy(deployment_id="<deployment_id>")
"""
The app deployment details will be returned in the following format:
{
"deploymentId": "e04e308d-98dc-4443-bb02-c4ef990a3fdc",
"revision": 2,
"revisionId": "7092bd84-c35d-43c1-90ca-7510a1204dcc",
}
"""
Create app
deployment
revision
from a specific app-spec
’s release
[ ]:
body: dict[str, str] = {
"parameters": {
"workflow-block-private": {
"run": {
"agg_type": "AVG",
"email_notifications": True,
"num_iterations": 50,
"file_names": ["input.csv", "output.csv"],
},
},
"webapp-block-private": {
"run": {
"agg_type": "MAX",
"email_notifications": False,
"num_iterations": 10,
"file_names": ["input.csv", "output.csv"],
},
},
},
"revision": {
"notes": "This is the second revision",
},
"release": {
"version": "2.0.0", # Release version of the parent spec to be used
},
}
deployment_revision: dict[str, str] = client.create_deployment_revision(deployment["id"], body)
Describe an app
deployment
revision
[ ]:
client.describe_deployment_revision(deployment["id"], deployment_revision["revision"])
"""
The app deployment revision details will be returned in the following format:
{
"blocks": [
{
"deploymentId": "e04e308d-98dc-4443-bb02-c4ef990a3fdc",
"platformId": "9e1389f2-564c-4d60-80cf-5369d8a5a204",
"kind": "workflow",
"name": "lso-deployment",
"revision": 1,
"status": "deploying"
}
],
"createdAt": "2020-01-01T18:00:00.000Z",
"createdBy": "jane.smith@peak.ai",
"id": "2fa92990-3183-40fd-8c93-7ded5a99f705",
"notes": "This is the original release",
"revision": 1,
"spec": {
"id": "a3e77006-86f3-4829-8c43-f21ad462dbbd",
"release": {
"version": "1.0.0"
}
},
"status": "deploying"
}
"""
List all revision
(s) in an app
deployment
and iterate over them
[ ]:
deployment_revisions_iterator: Iterator[dict[str, Any]] = client.list_deployment_revisions(
deployment["id"],
)
deployment_revisions_iterated: dict[str, Any] = next(deployment_revisions_iterator)
"""
The list of app deployment revisions will be returned in the following format:
{
"pageCount": 1,
"pageNumber": 1,
"pageSize": 25,
"revisionCount": 1,
"revisions": [
{
"createdAt": "2020-01-01T18:00:00.000Z",
"createdBy": "jane.smith@peak.ai",
"id": "2fa92990-3183-40fd-8c93-7ded5a99f705",
"notes": "This is the initial revision",
"revision": 1,
"status": "deploying"
}
]
}
"""
Delete an existing deployment
[ ]:
client.delete_deployment(deployment["id"])
Delete an existing app-spec
with all its release(s)
[ ]:
client.delete_spec(created_app_spec["id"])