-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenvironments.py
More file actions
61 lines (47 loc) · 1.82 KB
/
Copy pathenvironments.py
File metadata and controls
61 lines (47 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
"""Environment lifecycle example — Create/Get/List/Update/Delete.
An Environment is the sandbox (network + filesystem policy) an Agent runs
inside during a Session. This example uses the cloud environment with
unrestricted networking; production usage will typically restrict either.
export ARK_API_KEY=...
python examples/environments.py
"""
from __future__ import annotations
import os
import time
from arkruntime import Ark
from arkruntime.types.environment.env_config import EnvConfig
from arkruntime.types.environment.networking_config import NetworkingConfig
def main() -> None:
api_key = os.environ.get("ARK_API_KEY")
if not api_key:
raise SystemExit("set ARK_API_KEY")
client = Ark.byteplus(api_key=api_key)
# 1. Create — cloud + unrestricted network.
name = f"example-env-{time.time_ns()}"
created = client.environments.create(
name=name,
config=EnvConfig(
type="cloud",
networking=NetworkingConfig(type="unrestricted"),
),
)
print(f"created: id={created.id} name={created.name}")
try:
# 2. Get
got = client.environments.retrieve(created.id)
print(f"get: id={got.id} name={got.name} type={got.type}")
# 3. List
listed = client.environments.list(limit=5)
print(f"list: {len(listed.data)} items, next_page={listed.next_page!r}")
# 4. Update — attach a description.
updated = client.environments.update(
created.id,
description="updated by ark-runtime-python example",
)
print(f"updated: id={updated.id} description={updated.description!r}")
finally:
# 5. Delete
deleted = client.environments.delete(created.id)
print(f"deleted: id={deleted.id}")
if __name__ == "__main__":
main()