flaxcloud 0.3.0__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.
@@ -0,0 +1,30 @@
1
+ # Python
2
+ __pycache__/
3
+ *.py[cod]
4
+ .venv/
5
+ venv/
6
+ *.egg-info/
7
+ .pytest_cache/
8
+ .mypy_cache/
9
+ .ruff_cache/
10
+
11
+ # Environment
12
+ .env
13
+ # Local secret overrides synced to the server (never committed)
14
+ infra/secrets.env
15
+ secrets.env
16
+
17
+ # Local databases
18
+ *.db
19
+ *.sqlite
20
+ *.sqlite3
21
+
22
+ # Node
23
+ node_modules/
24
+ .next/
25
+ dist/
26
+ build/
27
+
28
+ # OS / editor
29
+ .DS_Store
30
+ *.log
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Flax Cloud
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,164 @@
1
+ Metadata-Version: 2.4
2
+ Name: flaxcloud
3
+ Version: 0.3.0
4
+ Summary: Python SDK and CLI for Flax Cloud — isolated cloud sandboxes.
5
+ Project-URL: Homepage, https://flaxcloud.com
6
+ Project-URL: Documentation, https://github.com/tomitokko/flax-cloud/blob/main/docs/user/sdk.md
7
+ Project-URL: Source, https://github.com/tomitokko/flax-cloud
8
+ Project-URL: Issues, https://github.com/tomitokko/flax-cloud/issues
9
+ Author: Flax Cloud
10
+ License: MIT License
11
+
12
+ Copyright (c) 2026 Flax Cloud
13
+
14
+ Permission is hereby granted, free of charge, to any person obtaining a copy
15
+ of this software and associated documentation files (the "Software"), to deal
16
+ in the Software without restriction, including without limitation the rights
17
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
18
+ copies of the Software, and to permit persons to whom the Software is
19
+ furnished to do so, subject to the following conditions:
20
+
21
+ The above copyright notice and this permission notice shall be included in all
22
+ copies or substantial portions of the Software.
23
+
24
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
27
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
29
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30
+ SOFTWARE.
31
+ License-File: LICENSE
32
+ Keywords: agents,cloud,code execution,flax,sandbox
33
+ Classifier: Development Status :: 4 - Beta
34
+ Classifier: Intended Audience :: Developers
35
+ Classifier: License :: OSI Approved :: MIT License
36
+ Classifier: Operating System :: OS Independent
37
+ Classifier: Programming Language :: Python :: 3
38
+ Classifier: Programming Language :: Python :: 3 :: Only
39
+ Classifier: Programming Language :: Python :: 3.9
40
+ Classifier: Programming Language :: Python :: 3.10
41
+ Classifier: Programming Language :: Python :: 3.11
42
+ Classifier: Programming Language :: Python :: 3.12
43
+ Classifier: Programming Language :: Python :: 3.13
44
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
45
+ Classifier: Typing :: Typed
46
+ Requires-Python: >=3.9
47
+ Requires-Dist: httpx>=0.24
48
+ Description-Content-Type: text/markdown
49
+
50
+ # flaxcloud — Python SDK & CLI for Flax Cloud
51
+
52
+ Programmatic access to [Flax Cloud](https://flaxcloud.com) isolated sandboxes: create them,
53
+ run commands, move files, preview servers, and wire them into agents/automation.
54
+
55
+ ## Install
56
+
57
+ ```bash
58
+ pip install flaxcloud
59
+ ```
60
+
61
+ ## Authenticate
62
+
63
+ Get an API key from the dashboard, then either set an environment variable or log in with the
64
+ CLI (which stores it in `~/.config/flax/config.json`):
65
+
66
+ ```bash
67
+ export FLAX_API_KEY=flax_live_...
68
+ # or
69
+ flax login
70
+ ```
71
+
72
+ ## SDK
73
+
74
+ ```python
75
+ from flaxcloud import FlaxClient
76
+
77
+ flax = FlaxClient() # reads FLAX_API_KEY
78
+
79
+ # create_sandbox returns a handle with methods; use it as a context manager to auto-destroy
80
+ with flax.create_sandbox(template="python") as sb:
81
+ out = sb.run("python3 -c 'print(6*7)'")
82
+ print(out.stdout) # "42\n"
83
+
84
+ sb.upload("/workspace/app.py", "print('hello')\n")
85
+ print(sb.run("python3 app.py").stdout)
86
+
87
+ # long-running server + a shareable preview link
88
+ sb.set_startup("python3 -m http.server 8000 --bind 0.0.0.0")
89
+ sb.run_startup()
90
+ print(sb.create_preview_link(8000).url)
91
+ ```
92
+
93
+ Background commands:
94
+
95
+ ```python
96
+ sb = flax.create_sandbox(template="node")
97
+ job = sb.run("npm install", background=True)
98
+ done = sb.wait(job, timeout=600)
99
+ print(done.status, done.exit_code)
100
+ ```
101
+
102
+ Environment variables, code execution, git, and filesystem helpers:
103
+
104
+ ```python
105
+ sb = flax.create_sandbox(template="python", env={"API_BASE": "https://example.com"})
106
+ sb.run("printenv TOKEN", env={"TOKEN": "secret"}) # per-command override
107
+ sb.code_run("print(6*7)", language="python") # also node/bash/ruby
108
+ sb.git.clone("https://github.com/me/repo.git", "/workspace/repo")
109
+ sb.mkdir("/workspace/out"); sb.find("/workspace", name="*.py")
110
+ ```
111
+
112
+ Stateful sessions — working directory and exported env persist across commands:
113
+
114
+ ```python
115
+ with sb.create_session() as s: # auto-deletes on exit
116
+ s.run("cd /workspace && export TOKEN=abc")
117
+ print(s.run("pwd").stdout) # /workspace
118
+ print(s.run("echo $TOKEN").stdout) # abc
119
+ ```
120
+
121
+ Streaming — live combined stdout/stderr as the command runs:
122
+
123
+ ```python
124
+ stream = sb.run_stream("for i in 1 2 3; do echo $i; sleep 1; done")
125
+ for chunk in stream:
126
+ print(chunk, end="", flush=True)
127
+ print("exit:", stream.exit_code)
128
+ ```
129
+
130
+ Async client:
131
+
132
+ ```python
133
+ import asyncio
134
+ from flaxcloud import AsyncFlaxClient
135
+
136
+ async def main():
137
+ async with AsyncFlaxClient() as flax:
138
+ async with await flax.create_sandbox(template="python") as sb:
139
+ print((await sb.run("echo hi")).stdout)
140
+
141
+ asyncio.run(main())
142
+ ```
143
+
144
+ Errors are typed (`FlaxAuthError`, `FlaxNotFoundError`, `FlaxQuotaError`, …), all subclasses of
145
+ `FlaxError`. The client retries transient failures, sends a versioned `User-Agent`, and ships
146
+ type hints (`py.typed`).
147
+
148
+ ## CLI
149
+
150
+ ```bash
151
+ flax login
152
+ flax sandbox create --template python --startup "python3 -m http.server 8000 --bind 0.0.0.0"
153
+ flax sandbox ls
154
+ flax run sbx_abc123 "python3 -c 'print(6*7)'"
155
+ flax run sbx_abc123 "make build" --stream # stream output live
156
+ flax session create sbx_abc123 # cwd/env persist across exec
157
+ flax session exec ses_xyz "cd src && export E=1"
158
+ flax cp ./app.py sbx_abc123:/workspace/app.py
159
+ flax ls sbx_abc123 /workspace
160
+ flax preview sbx_abc123 8000
161
+ flax sandbox rm sbx_abc123
162
+ ```
163
+
164
+ `flax --help` lists every command.
@@ -0,0 +1,115 @@
1
+ # flaxcloud — Python SDK & CLI for Flax Cloud
2
+
3
+ Programmatic access to [Flax Cloud](https://flaxcloud.com) isolated sandboxes: create them,
4
+ run commands, move files, preview servers, and wire them into agents/automation.
5
+
6
+ ## Install
7
+
8
+ ```bash
9
+ pip install flaxcloud
10
+ ```
11
+
12
+ ## Authenticate
13
+
14
+ Get an API key from the dashboard, then either set an environment variable or log in with the
15
+ CLI (which stores it in `~/.config/flax/config.json`):
16
+
17
+ ```bash
18
+ export FLAX_API_KEY=flax_live_...
19
+ # or
20
+ flax login
21
+ ```
22
+
23
+ ## SDK
24
+
25
+ ```python
26
+ from flaxcloud import FlaxClient
27
+
28
+ flax = FlaxClient() # reads FLAX_API_KEY
29
+
30
+ # create_sandbox returns a handle with methods; use it as a context manager to auto-destroy
31
+ with flax.create_sandbox(template="python") as sb:
32
+ out = sb.run("python3 -c 'print(6*7)'")
33
+ print(out.stdout) # "42\n"
34
+
35
+ sb.upload("/workspace/app.py", "print('hello')\n")
36
+ print(sb.run("python3 app.py").stdout)
37
+
38
+ # long-running server + a shareable preview link
39
+ sb.set_startup("python3 -m http.server 8000 --bind 0.0.0.0")
40
+ sb.run_startup()
41
+ print(sb.create_preview_link(8000).url)
42
+ ```
43
+
44
+ Background commands:
45
+
46
+ ```python
47
+ sb = flax.create_sandbox(template="node")
48
+ job = sb.run("npm install", background=True)
49
+ done = sb.wait(job, timeout=600)
50
+ print(done.status, done.exit_code)
51
+ ```
52
+
53
+ Environment variables, code execution, git, and filesystem helpers:
54
+
55
+ ```python
56
+ sb = flax.create_sandbox(template="python", env={"API_BASE": "https://example.com"})
57
+ sb.run("printenv TOKEN", env={"TOKEN": "secret"}) # per-command override
58
+ sb.code_run("print(6*7)", language="python") # also node/bash/ruby
59
+ sb.git.clone("https://github.com/me/repo.git", "/workspace/repo")
60
+ sb.mkdir("/workspace/out"); sb.find("/workspace", name="*.py")
61
+ ```
62
+
63
+ Stateful sessions — working directory and exported env persist across commands:
64
+
65
+ ```python
66
+ with sb.create_session() as s: # auto-deletes on exit
67
+ s.run("cd /workspace && export TOKEN=abc")
68
+ print(s.run("pwd").stdout) # /workspace
69
+ print(s.run("echo $TOKEN").stdout) # abc
70
+ ```
71
+
72
+ Streaming — live combined stdout/stderr as the command runs:
73
+
74
+ ```python
75
+ stream = sb.run_stream("for i in 1 2 3; do echo $i; sleep 1; done")
76
+ for chunk in stream:
77
+ print(chunk, end="", flush=True)
78
+ print("exit:", stream.exit_code)
79
+ ```
80
+
81
+ Async client:
82
+
83
+ ```python
84
+ import asyncio
85
+ from flaxcloud import AsyncFlaxClient
86
+
87
+ async def main():
88
+ async with AsyncFlaxClient() as flax:
89
+ async with await flax.create_sandbox(template="python") as sb:
90
+ print((await sb.run("echo hi")).stdout)
91
+
92
+ asyncio.run(main())
93
+ ```
94
+
95
+ Errors are typed (`FlaxAuthError`, `FlaxNotFoundError`, `FlaxQuotaError`, …), all subclasses of
96
+ `FlaxError`. The client retries transient failures, sends a versioned `User-Agent`, and ships
97
+ type hints (`py.typed`).
98
+
99
+ ## CLI
100
+
101
+ ```bash
102
+ flax login
103
+ flax sandbox create --template python --startup "python3 -m http.server 8000 --bind 0.0.0.0"
104
+ flax sandbox ls
105
+ flax run sbx_abc123 "python3 -c 'print(6*7)'"
106
+ flax run sbx_abc123 "make build" --stream # stream output live
107
+ flax session create sbx_abc123 # cwd/env persist across exec
108
+ flax session exec ses_xyz "cd src && export E=1"
109
+ flax cp ./app.py sbx_abc123:/workspace/app.py
110
+ flax ls sbx_abc123 /workspace
111
+ flax preview sbx_abc123 8000
112
+ flax sandbox rm sbx_abc123
113
+ ```
114
+
115
+ `flax --help` lists every command.
@@ -0,0 +1,41 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "flaxcloud"
7
+ version = "0.3.0"
8
+ description = "Python SDK and CLI for Flax Cloud — isolated cloud sandboxes."
9
+ readme = "README.md"
10
+ requires-python = ">=3.9"
11
+ license = { file = "LICENSE" }
12
+ authors = [{ name = "Flax Cloud" }]
13
+ keywords = ["flax", "sandbox", "cloud", "agents", "code execution"]
14
+ dependencies = ["httpx>=0.24"]
15
+ classifiers = [
16
+ "Development Status :: 4 - Beta",
17
+ "Intended Audience :: Developers",
18
+ "License :: OSI Approved :: MIT License",
19
+ "Operating System :: OS Independent",
20
+ "Programming Language :: Python :: 3",
21
+ "Programming Language :: Python :: 3 :: Only",
22
+ "Programming Language :: Python :: 3.9",
23
+ "Programming Language :: Python :: 3.10",
24
+ "Programming Language :: Python :: 3.11",
25
+ "Programming Language :: Python :: 3.12",
26
+ "Programming Language :: Python :: 3.13",
27
+ "Topic :: Software Development :: Libraries :: Python Modules",
28
+ "Typing :: Typed",
29
+ ]
30
+
31
+ [project.urls]
32
+ Homepage = "https://flaxcloud.com"
33
+ Documentation = "https://github.com/tomitokko/flax-cloud/blob/main/docs/user/sdk.md"
34
+ Source = "https://github.com/tomitokko/flax-cloud"
35
+ Issues = "https://github.com/tomitokko/flax-cloud/issues"
36
+
37
+ [project.scripts]
38
+ flax = "flaxcloud.cli:main"
39
+
40
+ [tool.hatch.build.targets.wheel]
41
+ packages = ["src/flaxcloud"]
@@ -0,0 +1,59 @@
1
+ """Flax Cloud — Python SDK and CLI for isolated cloud sandboxes.
2
+
3
+ ```python
4
+ from flaxcloud import FlaxClient
5
+
6
+ flax = FlaxClient() # reads FLAX_API_KEY
7
+ with flax.create_sandbox(template="python") as sb:
8
+ print(sb.run("python3 -c 'print(6*7)'").stdout)
9
+ ```
10
+ """
11
+
12
+ from __future__ import annotations
13
+
14
+ from .client import FlaxClient
15
+ from .errors import (
16
+ FlaxAuthError,
17
+ FlaxBadRequestError,
18
+ FlaxConflictError,
19
+ FlaxConnectionError,
20
+ FlaxError,
21
+ FlaxNotFoundError,
22
+ FlaxQuotaError,
23
+ FlaxServerError,
24
+ )
25
+ from .models import Command, FileEntry, PreviewLink, SessionResult, StartupStatus
26
+ from .sandbox import Sandbox, Session
27
+
28
+ __version__ = "0.3.0"
29
+
30
+
31
+ def __getattr__(name: str):
32
+ # Lazily expose the async client so importing the package doesn't require asyncio setup.
33
+ if name in ("AsyncFlaxClient", "AsyncSandbox"):
34
+ from . import aio
35
+
36
+ return getattr(aio, name)
37
+ raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
38
+
39
+
40
+ __all__ = [
41
+ "FlaxClient",
42
+ "Sandbox",
43
+ "Session",
44
+ "SessionResult",
45
+ "AsyncFlaxClient",
46
+ "AsyncSandbox",
47
+ "Command",
48
+ "FileEntry",
49
+ "PreviewLink",
50
+ "StartupStatus",
51
+ "FlaxError",
52
+ "FlaxAuthError",
53
+ "FlaxNotFoundError",
54
+ "FlaxQuotaError",
55
+ "FlaxConflictError",
56
+ "FlaxBadRequestError",
57
+ "FlaxServerError",
58
+ "FlaxConnectionError",
59
+ ]