fleet-python 0.2.4__tar.gz → 0.2.7__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of fleet-python might be problematic. Click here for more details.
- {fleet_python-0.2.4/fleet_python.egg-info → fleet_python-0.2.7}/PKG-INFO +53 -11
- fleet_python-0.2.7/README.md +117 -0
- {fleet_python-0.2.4 → fleet_python-0.2.7}/examples/dsl_example.py +3 -0
- {fleet_python-0.2.4 → fleet_python-0.2.7}/examples/example.py +4 -1
- fleet_python-0.2.7/examples/example_client.py +43 -0
- fleet_python-0.2.7/examples/example_sync.py +40 -0
- {fleet_python-0.2.4 → fleet_python-0.2.7}/examples/json_tasks_example.py +3 -0
- {fleet_python-0.2.4 → fleet_python-0.2.7}/examples/nova_act_example.py +3 -0
- {fleet_python-0.2.4 → fleet_python-0.2.7}/examples/openai_example.py +3 -0
- {fleet_python-0.2.4 → fleet_python-0.2.7}/examples/openai_simple_example.py +3 -0
- {fleet_python-0.2.4 → fleet_python-0.2.7}/examples/quickstart.py +30 -48
- {fleet_python-0.2.4 → fleet_python-0.2.7}/fleet/__init__.py +1 -1
- fleet_python-0.2.7/fleet/_async/__init__.py +1 -0
- {fleet_python-0.2.4 → fleet_python-0.2.7}/fleet/_async/client.py +7 -3
- {fleet_python-0.2.4 → fleet_python-0.2.7}/fleet/_async/env/client.py +6 -2
- {fleet_python-0.2.4 → fleet_python-0.2.7}/fleet/_async/instance/client.py +16 -118
- {fleet_python-0.2.4 → fleet_python-0.2.7}/fleet/_async/playwright.py +2 -2
- {fleet_python-0.2.4 → fleet_python-0.2.7}/fleet/client.py +7 -3
- {fleet_python-0.2.4 → fleet_python-0.2.7}/fleet/env/client.py +6 -2
- {fleet_python-0.2.4 → fleet_python-0.2.7}/fleet/instance/__init__.py +1 -3
- {fleet_python-0.2.4 → fleet_python-0.2.7}/fleet/instance/client.py +15 -118
- {fleet_python-0.2.4 → fleet_python-0.2.7}/fleet/playwright.py +9 -8
- {fleet_python-0.2.4 → fleet_python-0.2.7/fleet_python.egg-info}/PKG-INFO +53 -11
- {fleet_python-0.2.4 → fleet_python-0.2.7}/fleet_python.egg-info/SOURCES.txt +4 -0
- {fleet_python-0.2.4 → fleet_python-0.2.7}/fleet_python.egg-info/requires.txt +1 -0
- {fleet_python-0.2.4 → fleet_python-0.2.7}/pyproject.toml +15 -2
- fleet_python-0.2.7/scripts/fix_sync_imports.py +69 -0
- fleet_python-0.2.4/README.md +0 -76
- {fleet_python-0.2.4 → fleet_python-0.2.7}/LICENSE +0 -0
- {fleet_python-0.2.4 → fleet_python-0.2.7}/fleet/_async/base.py +0 -0
- {fleet_python-0.2.4 → fleet_python-0.2.7}/fleet/_async/env/__init__.py +0 -0
- {fleet_python-0.2.4 → fleet_python-0.2.7}/fleet/_async/exceptions.py +0 -0
- {fleet_python-0.2.4 → fleet_python-0.2.7}/fleet/_async/instance/__init__.py +0 -0
- {fleet_python-0.2.4 → fleet_python-0.2.7}/fleet/_async/instance/base.py +0 -0
- {fleet_python-0.2.4 → fleet_python-0.2.7}/fleet/_async/instance/models.py +0 -0
- {fleet_python-0.2.4 → fleet_python-0.2.7}/fleet/_async/models.py +0 -0
- {fleet_python-0.2.4 → fleet_python-0.2.7}/fleet/_async/resources/__init__.py +0 -0
- {fleet_python-0.2.4 → fleet_python-0.2.7}/fleet/_async/resources/base.py +0 -0
- {fleet_python-0.2.4 → fleet_python-0.2.7}/fleet/_async/resources/browser.py +0 -0
- {fleet_python-0.2.4 → fleet_python-0.2.7}/fleet/_async/resources/sqlite.py +0 -0
- {fleet_python-0.2.4 → fleet_python-0.2.7}/fleet/base.py +0 -0
- {fleet_python-0.2.4 → fleet_python-0.2.7}/fleet/env/__init__.py +0 -0
- {fleet_python-0.2.4 → fleet_python-0.2.7}/fleet/exceptions.py +0 -0
- {fleet_python-0.2.4 → fleet_python-0.2.7}/fleet/instance/base.py +0 -0
- {fleet_python-0.2.4 → fleet_python-0.2.7}/fleet/instance/models.py +0 -0
- {fleet_python-0.2.4 → fleet_python-0.2.7}/fleet/models.py +0 -0
- {fleet_python-0.2.4 → fleet_python-0.2.7}/fleet/resources/__init__.py +0 -0
- {fleet_python-0.2.4 → fleet_python-0.2.7}/fleet/resources/base.py +0 -0
- {fleet_python-0.2.4 → fleet_python-0.2.7}/fleet/resources/browser.py +0 -0
- {fleet_python-0.2.4 → fleet_python-0.2.7}/fleet/resources/sqlite.py +0 -0
- {fleet_python-0.2.4 → fleet_python-0.2.7}/fleet/verifiers/__init__.py +0 -0
- {fleet_python-0.2.4 → fleet_python-0.2.7}/fleet/verifiers/code.py +0 -0
- {fleet_python-0.2.4 → fleet_python-0.2.7}/fleet/verifiers/db.py +0 -0
- {fleet_python-0.2.4 → fleet_python-0.2.7}/fleet/verifiers/sql_differ.py +0 -0
- {fleet_python-0.2.4 → fleet_python-0.2.7}/fleet_python.egg-info/dependency_links.txt +0 -0
- {fleet_python-0.2.4 → fleet_python-0.2.7}/fleet_python.egg-info/top_level.txt +0 -0
- {fleet_python-0.2.4 → fleet_python-0.2.7}/scripts/unasync.py +0 -0
- {fleet_python-0.2.4 → fleet_python-0.2.7}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: fleet-python
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.7
|
|
4
4
|
Summary: Python SDK for Fleet environments
|
|
5
5
|
Author-email: Fleet AI <nic@fleet.so>
|
|
6
6
|
License: Apache-2.0
|
|
@@ -32,6 +32,7 @@ Requires-Dist: isort>=5.0.0; extra == "dev"
|
|
|
32
32
|
Requires-Dist: mypy>=1.0.0; extra == "dev"
|
|
33
33
|
Requires-Dist: ruff>=0.1.0; extra == "dev"
|
|
34
34
|
Requires-Dist: unasync>=0.6.0; extra == "dev"
|
|
35
|
+
Requires-Dist: python-dotenv>=1.1.1; extra == "dev"
|
|
35
36
|
Provides-Extra: playwright
|
|
36
37
|
Requires-Dist: playwright>=1.40.0; extra == "playwright"
|
|
37
38
|
Dynamic: license-file
|
|
@@ -64,20 +65,20 @@ export FLEET_API_KEY="sk_your_key_here"
|
|
|
64
65
|
import fleet as flt
|
|
65
66
|
|
|
66
67
|
# Create environment by key
|
|
67
|
-
env =
|
|
68
|
+
env = flt.env.make("fira")
|
|
68
69
|
|
|
69
70
|
# Reset environment with seed and options
|
|
70
|
-
|
|
71
|
+
env.reset(
|
|
71
72
|
seed=42,
|
|
72
73
|
timestamp=datetime.now()
|
|
73
74
|
)
|
|
74
75
|
|
|
75
76
|
# Access environment state ('crm' is the resource id for a sqlite database)
|
|
76
77
|
sql = env.state("sqlite://crm")
|
|
77
|
-
|
|
78
|
+
sql.exec("UPDATE customers SET status = 'active' WHERE id = 123")
|
|
78
79
|
|
|
79
80
|
# Clean up
|
|
80
|
-
|
|
81
|
+
env.close()
|
|
81
82
|
```
|
|
82
83
|
|
|
83
84
|
## Environment Management
|
|
@@ -86,10 +87,10 @@ await env.close()
|
|
|
86
87
|
|
|
87
88
|
```python
|
|
88
89
|
# Create environment instance with explicit version
|
|
89
|
-
env =
|
|
90
|
+
env = flt.env.make("fira:v1.2.5")
|
|
90
91
|
|
|
91
92
|
# Create environment instance with default (latest) version
|
|
92
|
-
env =
|
|
93
|
+
env = flt.env.make("fira")
|
|
93
94
|
|
|
94
95
|
```
|
|
95
96
|
|
|
@@ -97,18 +98,59 @@ env = await flt.env.make("fira")
|
|
|
97
98
|
|
|
98
99
|
```python
|
|
99
100
|
# Connect to a running instance
|
|
100
|
-
env =
|
|
101
|
+
env = flt.env.get("env_instance_id")
|
|
101
102
|
|
|
102
103
|
# List all running instances
|
|
103
|
-
instances =
|
|
104
|
+
instances = flt.env.list_instances()
|
|
104
105
|
for instance in instances:
|
|
105
106
|
print(f"Instance: {instance.instance_id}")
|
|
106
107
|
print(f"Type: {instance.environment_type}")
|
|
107
108
|
print(f"Status: {instance.status}")
|
|
108
109
|
|
|
109
110
|
# Filter instances by status (running, pending, stopped, error)
|
|
110
|
-
running_instances =
|
|
111
|
+
running_instances = flt.env.list_instances(status_filter="running")
|
|
111
112
|
|
|
112
113
|
# List available environment types
|
|
113
|
-
available_envs =
|
|
114
|
+
available_envs = flt.env.list_envs()
|
|
114
115
|
```
|
|
116
|
+
|
|
117
|
+
## Development
|
|
118
|
+
|
|
119
|
+
### Code Structure
|
|
120
|
+
|
|
121
|
+
This SDK uses `unasync` to maintain both async and sync versions of the code from a single source:
|
|
122
|
+
|
|
123
|
+
- **`fleet/_async/`** - The source code (async version) - **EDIT THIS**
|
|
124
|
+
- **`fleet/`** - The generated sync version - **DO NOT EDIT** (auto-generated)
|
|
125
|
+
|
|
126
|
+
### Making Changes
|
|
127
|
+
|
|
128
|
+
⚠️ **Important**: All code modifications should be made in the `fleet/_async/` directory. The synchronous versions in `fleet/` are automatically generated.
|
|
129
|
+
|
|
130
|
+
1. Make your changes in `fleet/_async/`
|
|
131
|
+
2. Run `make unasync` to generate the sync versions
|
|
132
|
+
3. Test both async and sync versions
|
|
133
|
+
4. Commit all changes (both async source and generated sync files)
|
|
134
|
+
|
|
135
|
+
Example workflow:
|
|
136
|
+
```bash
|
|
137
|
+
# Edit the async source files
|
|
138
|
+
vim fleet/_async/client.py
|
|
139
|
+
|
|
140
|
+
# Generate sync versions
|
|
141
|
+
make unasync
|
|
142
|
+
|
|
143
|
+
# Run tests
|
|
144
|
+
python examples/examle.py
|
|
145
|
+
|
|
146
|
+
# Commit both source and generated files
|
|
147
|
+
git add fleet/_async/ fleet/
|
|
148
|
+
git commit -m "Add new feature"
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
### Why This Structure?
|
|
152
|
+
|
|
153
|
+
- Single source of truth for business logic
|
|
154
|
+
- Automatic sync/async API generation
|
|
155
|
+
- Consistent behavior between sync and async versions
|
|
156
|
+
- Easier maintenance and testing
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
# Fleet SDK
|
|
2
|
+
|
|
3
|
+
The Fleet Python SDK provides programmatic access to Fleet's environment infrastructure.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Install the Fleet SDK using pip:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pip install fleet-python
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## API Key Setup
|
|
14
|
+
|
|
15
|
+
Fleet requires an API key for authentication. You can obtain one from the [Fleet Platform](https://fleetai.com/dashboard/api-keys).
|
|
16
|
+
|
|
17
|
+
Set your API key as an environment variable:
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
export FLEET_API_KEY="sk_your_key_here"
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Basic Usage
|
|
24
|
+
|
|
25
|
+
```python
|
|
26
|
+
import fleet as flt
|
|
27
|
+
|
|
28
|
+
# Create environment by key
|
|
29
|
+
env = flt.env.make("fira")
|
|
30
|
+
|
|
31
|
+
# Reset environment with seed and options
|
|
32
|
+
env.reset(
|
|
33
|
+
seed=42,
|
|
34
|
+
timestamp=datetime.now()
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
# Access environment state ('crm' is the resource id for a sqlite database)
|
|
38
|
+
sql = env.state("sqlite://crm")
|
|
39
|
+
sql.exec("UPDATE customers SET status = 'active' WHERE id = 123")
|
|
40
|
+
|
|
41
|
+
# Clean up
|
|
42
|
+
env.close()
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Environment Management
|
|
46
|
+
|
|
47
|
+
### Creating Instances
|
|
48
|
+
|
|
49
|
+
```python
|
|
50
|
+
# Create environment instance with explicit version
|
|
51
|
+
env = flt.env.make("fira:v1.2.5")
|
|
52
|
+
|
|
53
|
+
# Create environment instance with default (latest) version
|
|
54
|
+
env = flt.env.make("fira")
|
|
55
|
+
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### Connecting to Existing Instances
|
|
59
|
+
|
|
60
|
+
```python
|
|
61
|
+
# Connect to a running instance
|
|
62
|
+
env = flt.env.get("env_instance_id")
|
|
63
|
+
|
|
64
|
+
# List all running instances
|
|
65
|
+
instances = flt.env.list_instances()
|
|
66
|
+
for instance in instances:
|
|
67
|
+
print(f"Instance: {instance.instance_id}")
|
|
68
|
+
print(f"Type: {instance.environment_type}")
|
|
69
|
+
print(f"Status: {instance.status}")
|
|
70
|
+
|
|
71
|
+
# Filter instances by status (running, pending, stopped, error)
|
|
72
|
+
running_instances = flt.env.list_instances(status_filter="running")
|
|
73
|
+
|
|
74
|
+
# List available environment types
|
|
75
|
+
available_envs = flt.env.list_envs()
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## Development
|
|
79
|
+
|
|
80
|
+
### Code Structure
|
|
81
|
+
|
|
82
|
+
This SDK uses `unasync` to maintain both async and sync versions of the code from a single source:
|
|
83
|
+
|
|
84
|
+
- **`fleet/_async/`** - The source code (async version) - **EDIT THIS**
|
|
85
|
+
- **`fleet/`** - The generated sync version - **DO NOT EDIT** (auto-generated)
|
|
86
|
+
|
|
87
|
+
### Making Changes
|
|
88
|
+
|
|
89
|
+
⚠️ **Important**: All code modifications should be made in the `fleet/_async/` directory. The synchronous versions in `fleet/` are automatically generated.
|
|
90
|
+
|
|
91
|
+
1. Make your changes in `fleet/_async/`
|
|
92
|
+
2. Run `make unasync` to generate the sync versions
|
|
93
|
+
3. Test both async and sync versions
|
|
94
|
+
4. Commit all changes (both async source and generated sync files)
|
|
95
|
+
|
|
96
|
+
Example workflow:
|
|
97
|
+
```bash
|
|
98
|
+
# Edit the async source files
|
|
99
|
+
vim fleet/_async/client.py
|
|
100
|
+
|
|
101
|
+
# Generate sync versions
|
|
102
|
+
make unasync
|
|
103
|
+
|
|
104
|
+
# Run tests
|
|
105
|
+
python examples/examle.py
|
|
106
|
+
|
|
107
|
+
# Commit both source and generated files
|
|
108
|
+
git add fleet/_async/ fleet/
|
|
109
|
+
git commit -m "Add new feature"
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### Why This Structure?
|
|
113
|
+
|
|
114
|
+
- Single source of truth for business logic
|
|
115
|
+
- Automatic sync/async API generation
|
|
116
|
+
- Consistent behavior between sync and async versions
|
|
117
|
+
- Easier maintenance and testing
|
|
@@ -3,6 +3,9 @@
|
|
|
3
3
|
|
|
4
4
|
import asyncio
|
|
5
5
|
import fleet as flt
|
|
6
|
+
from dotenv import load_dotenv
|
|
7
|
+
|
|
8
|
+
load_dotenv()
|
|
6
9
|
|
|
7
10
|
|
|
8
11
|
async def main():
|
|
@@ -11,7 +14,7 @@ async def main():
|
|
|
11
14
|
|
|
12
15
|
# Create a new instance
|
|
13
16
|
env = await flt.env.make_async("hubspot:v1.2.7")
|
|
14
|
-
print("New Instance:
|
|
17
|
+
print(f"New Instance: {env.instance_id} ({env.region})")
|
|
15
18
|
|
|
16
19
|
response = await env.reset(seed=42)
|
|
17
20
|
print("Reset response:", response)
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Example demonstrating browser control with Fleet Manager Client."""
|
|
3
|
+
|
|
4
|
+
import asyncio
|
|
5
|
+
import fleet as flt
|
|
6
|
+
from dotenv import load_dotenv
|
|
7
|
+
|
|
8
|
+
load_dotenv()
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
async def main():
|
|
12
|
+
fleet = flt.AsyncFleet()
|
|
13
|
+
|
|
14
|
+
environments = await fleet.list_envs()
|
|
15
|
+
print("Environments:", len(environments))
|
|
16
|
+
|
|
17
|
+
# Create a new instance
|
|
18
|
+
env = await fleet.make("fira")
|
|
19
|
+
print(f"New Instance: {env.instance_id} ({env.region})")
|
|
20
|
+
|
|
21
|
+
response = await env.reset(seed=42)
|
|
22
|
+
print("Reset response:", response)
|
|
23
|
+
|
|
24
|
+
print(await env.resources())
|
|
25
|
+
|
|
26
|
+
sqlite = env.db()
|
|
27
|
+
print("SQLite:", await sqlite.describe())
|
|
28
|
+
|
|
29
|
+
print("Query:", await sqlite.query("SELECT * FROM users"))
|
|
30
|
+
|
|
31
|
+
sqlite = await env.state("sqlite://current").describe()
|
|
32
|
+
print("SQLite:", sqlite)
|
|
33
|
+
|
|
34
|
+
browser = env.browser()
|
|
35
|
+
print("CDP URL:", await browser.cdp_url())
|
|
36
|
+
print("Devtools URL:", await browser.devtools_url())
|
|
37
|
+
|
|
38
|
+
# Delete the instance
|
|
39
|
+
await fleet.delete(env.instance_id)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
if __name__ == "__main__":
|
|
43
|
+
asyncio.run(main())
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Example demonstrating browser control with Fleet Manager Client."""
|
|
3
|
+
|
|
4
|
+
import fleet as flt
|
|
5
|
+
from dotenv import load_dotenv
|
|
6
|
+
|
|
7
|
+
load_dotenv()
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def main():
|
|
11
|
+
environments = flt.env.list_envs()
|
|
12
|
+
print("Environments:", len(environments))
|
|
13
|
+
|
|
14
|
+
# Create a new instance
|
|
15
|
+
env = flt.env.make("hubspot:v1.2.7")
|
|
16
|
+
print("New Instance:", env.instance_id)
|
|
17
|
+
|
|
18
|
+
response = env.reset(seed=42)
|
|
19
|
+
print("Reset response:", response)
|
|
20
|
+
|
|
21
|
+
print(env.resources())
|
|
22
|
+
|
|
23
|
+
sqlite = env.db()
|
|
24
|
+
print("SQLite:", sqlite.describe())
|
|
25
|
+
|
|
26
|
+
print("Query:", sqlite.query("SELECT * FROM users"))
|
|
27
|
+
|
|
28
|
+
sqlite = env.state("sqlite://current").describe()
|
|
29
|
+
print("SQLite:", sqlite)
|
|
30
|
+
|
|
31
|
+
browser = env.browser()
|
|
32
|
+
print("CDP URL:", browser.cdp_url())
|
|
33
|
+
print("Devtools URL:", browser.devtools_url())
|
|
34
|
+
|
|
35
|
+
# Delete the instance
|
|
36
|
+
env.close()
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
if __name__ == "__main__":
|
|
40
|
+
main()
|
|
@@ -7,9 +7,11 @@ This example demonstrates basic usage of the Fleet SDK for environment managemen
|
|
|
7
7
|
|
|
8
8
|
import asyncio
|
|
9
9
|
import logging
|
|
10
|
-
from
|
|
10
|
+
from dotenv import load_dotenv
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
load_dotenv()
|
|
13
|
+
|
|
14
|
+
from fleet import AsyncFleet
|
|
13
15
|
|
|
14
16
|
|
|
15
17
|
# Configure logging
|
|
@@ -19,23 +21,14 @@ logger = logging.getLogger(__name__)
|
|
|
19
21
|
|
|
20
22
|
async def main():
|
|
21
23
|
"""Main example function."""
|
|
22
|
-
|
|
23
|
-
#
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
config = fleet.get_config()
|
|
27
|
-
client = fleet.FleetAPIClient(config)
|
|
28
|
-
health = await client.health_check()
|
|
29
|
-
print(f"✅ API Status: {health.status}")
|
|
30
|
-
await client.close()
|
|
31
|
-
except Exception as e:
|
|
32
|
-
print(f"❌ API Health Check failed: {e}")
|
|
33
|
-
return
|
|
34
|
-
|
|
24
|
+
|
|
25
|
+
# Initialize the Fleet client
|
|
26
|
+
fleet_client = AsyncFleet()
|
|
27
|
+
|
|
35
28
|
# 1. List available environments
|
|
36
29
|
print("\n📋 Available environments:")
|
|
37
30
|
try:
|
|
38
|
-
environments = await
|
|
31
|
+
environments = await fleet_client.list_envs()
|
|
39
32
|
for env in environments:
|
|
40
33
|
print(f" - {env.env_key}: {env.name}")
|
|
41
34
|
print(f" Description: {env.description}")
|
|
@@ -44,77 +37,66 @@ async def main():
|
|
|
44
37
|
except Exception as e:
|
|
45
38
|
print(f"❌ Failed to list environments: {e}")
|
|
46
39
|
return
|
|
47
|
-
|
|
40
|
+
|
|
48
41
|
# 2. Create a new environment instance
|
|
49
42
|
print("\n🚀 Creating new environment...")
|
|
50
43
|
try:
|
|
51
|
-
env = await
|
|
44
|
+
env = await fleet_client.make("fira:v1.3.1")
|
|
52
45
|
print(f"✅ Environment created with instance ID: {env.instance_id}")
|
|
53
|
-
|
|
54
|
-
# Execute a simple action
|
|
46
|
+
|
|
47
|
+
# TODO: Execute a simple action
|
|
55
48
|
print("\n⚡ Executing a simple action...")
|
|
56
49
|
action = {"type": "test", "data": {"message": "Hello Fleet!"}}
|
|
57
|
-
state, reward, done = await env.step(action)
|
|
50
|
+
state, reward, done = await env.instance.step(action)
|
|
58
51
|
print(f"✅ Action executed successfully!")
|
|
59
52
|
print(f" Reward: {reward}")
|
|
60
53
|
print(f" Done: {done}")
|
|
61
54
|
print(f" State keys: {list(state.keys())}")
|
|
62
|
-
|
|
63
|
-
# Check manager API health
|
|
64
|
-
print("\n🏥 Checking manager API health...")
|
|
65
|
-
try:
|
|
66
|
-
manager_health = await env.manager_health_check()
|
|
67
|
-
if manager_health:
|
|
68
|
-
print(f"✅ Manager API Status: {manager_health.status}")
|
|
69
|
-
print(f" Service: {manager_health.service}")
|
|
70
|
-
print(f" Timestamp: {manager_health.timestamp}")
|
|
71
|
-
else:
|
|
72
|
-
print("❌ Manager API not available")
|
|
73
|
-
except Exception as e:
|
|
74
|
-
print(f"❌ Manager health check failed: {e}")
|
|
75
|
-
|
|
55
|
+
|
|
76
56
|
# Clean up
|
|
77
57
|
print("\n🧹 Cleaning up...")
|
|
78
58
|
await env.close()
|
|
79
59
|
print("✅ Environment closed")
|
|
80
|
-
|
|
60
|
+
|
|
81
61
|
except Exception as e:
|
|
82
62
|
print(f"❌ Environment creation failed: {e}")
|
|
83
63
|
return
|
|
84
|
-
|
|
64
|
+
|
|
85
65
|
# 3. List running instances
|
|
86
66
|
print("\n🏃 Listing running instances...")
|
|
87
67
|
try:
|
|
88
|
-
instances = await
|
|
68
|
+
instances = await fleet_client.instances(status="running")
|
|
89
69
|
if instances:
|
|
90
70
|
print(f"Found {len(instances)} running instances:")
|
|
91
71
|
for instance in instances:
|
|
92
|
-
print(
|
|
72
|
+
print(
|
|
73
|
+
f" - {instance.instance_id}: {instance.env_key} ({instance.status})"
|
|
74
|
+
)
|
|
93
75
|
else:
|
|
94
76
|
print("No running instances found")
|
|
95
77
|
except Exception as e:
|
|
96
78
|
print(f"❌ Failed to list instances: {e}")
|
|
97
|
-
|
|
79
|
+
|
|
98
80
|
# 4. Connect to an existing instance (if any)
|
|
99
81
|
print("\n🔗 Connecting to existing instance...")
|
|
100
82
|
try:
|
|
101
83
|
# Only get running instances
|
|
102
|
-
running_instances = await
|
|
84
|
+
running_instances = await fleet_client.instances(status="running")
|
|
103
85
|
if running_instances:
|
|
104
86
|
# Find a running instance that's not the one we just created/deleted
|
|
105
87
|
target_instance = running_instances[0]
|
|
106
88
|
print(f"Connecting to running instance: {target_instance.instance_id}")
|
|
107
|
-
|
|
108
|
-
env = await
|
|
89
|
+
|
|
90
|
+
env = await fleet_client.instance(target_instance.instance_id)
|
|
109
91
|
print(f"✅ Connected to instance: {env.instance_id}")
|
|
110
|
-
|
|
92
|
+
|
|
111
93
|
# Execute an action on the existing instance
|
|
112
94
|
action = {"type": "ping", "data": {"timestamp": "2024-01-01T00:00:00Z"}}
|
|
113
|
-
state, reward, done = await env.step(action)
|
|
95
|
+
state, reward, done = await env.instance.step(action)
|
|
114
96
|
print(f"✅ Action executed on existing instance!")
|
|
115
97
|
print(f" Reward: {reward}")
|
|
116
98
|
print(f" Done: {done}")
|
|
117
|
-
|
|
99
|
+
|
|
118
100
|
# Clean up (this will delete the instance)
|
|
119
101
|
await env.close()
|
|
120
102
|
print("✅ Connection closed (instance deleted)")
|
|
@@ -122,9 +104,9 @@ async def main():
|
|
|
122
104
|
print("No running instances to connect to")
|
|
123
105
|
except Exception as e:
|
|
124
106
|
print(f"❌ Failed to connect to existing instance: {e}")
|
|
125
|
-
|
|
107
|
+
|
|
126
108
|
print("\n🎉 Quickstart complete!")
|
|
127
109
|
|
|
128
110
|
|
|
129
111
|
if __name__ == "__main__":
|
|
130
|
-
asyncio.run(main())
|
|
112
|
+
asyncio.run(main())
|
|
@@ -25,7 +25,6 @@ from ._async.client import AsyncFleet, AsyncEnvironment
|
|
|
25
25
|
from .models import InstanceRequest
|
|
26
26
|
from .instance import (
|
|
27
27
|
InstanceClient,
|
|
28
|
-
AsyncInstanceClient,
|
|
29
28
|
ResetRequest,
|
|
30
29
|
ResetResponse,
|
|
31
30
|
CDPDescribeResponse,
|
|
@@ -33,6 +32,7 @@ from .instance import (
|
|
|
33
32
|
ChromeStartResponse,
|
|
34
33
|
ChromeStatusResponse,
|
|
35
34
|
)
|
|
35
|
+
from ._async.instance import AsyncInstanceClient
|
|
36
36
|
from .verifiers import (
|
|
37
37
|
DatabaseSnapshot,
|
|
38
38
|
IgnoreConfig,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# This file makes the _async directory a proper Python package
|
|
@@ -126,8 +126,12 @@ class AsyncFleet:
|
|
|
126
126
|
|
|
127
127
|
async def instance(self, instance_id: str) -> AsyncEnvironment:
|
|
128
128
|
response = await self.client.request("GET", f"/v1/env/instances/{instance_id}")
|
|
129
|
-
|
|
129
|
+
instance = AsyncEnvironment(**response.json())
|
|
130
|
+
await instance.instance.load()
|
|
131
|
+
return instance
|
|
130
132
|
|
|
131
133
|
async def delete(self, instance_id: str) -> InstanceRecord:
|
|
132
|
-
response = await self.client.request(
|
|
133
|
-
|
|
134
|
+
response = await self.client.request(
|
|
135
|
+
"DELETE", f"/v1/env/instances/{instance_id}"
|
|
136
|
+
)
|
|
137
|
+
return InstanceRecord(**response.json())
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
from ..client import AsyncFleet, AsyncEnvironment
|
|
2
2
|
from ..models import Environment as EnvironmentModel
|
|
3
|
-
from typing import List
|
|
3
|
+
from typing import List, Optional
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
async def make_async(env_key: str) -> AsyncEnvironment:
|
|
@@ -11,5 +11,9 @@ async def list_envs_async() -> List[EnvironmentModel]:
|
|
|
11
11
|
return await AsyncFleet().list_envs()
|
|
12
12
|
|
|
13
13
|
|
|
14
|
+
async def list_instances_async(status: Optional[str] = None) -> List[AsyncEnvironment]:
|
|
15
|
+
return await AsyncFleet().instances(status=status)
|
|
16
|
+
|
|
17
|
+
|
|
14
18
|
async def get_async(instance_id: str) -> AsyncEnvironment:
|
|
15
|
-
return await AsyncFleet().instance(instance_id)
|
|
19
|
+
return await AsyncFleet().instance(instance_id)
|