forktex-cloud 2.1.0__tar.gz → 3.0.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.
- forktex_cloud-3.0.0/PKG-INFO +291 -0
- forktex_cloud-3.0.0/README.md +258 -0
- {forktex_cloud-2.1.0 → forktex_cloud-3.0.0}/pyproject.toml +21 -15
- forktex_cloud-3.0.0/src/forktex_cloud/__init__.py +115 -0
- forktex_cloud-3.0.0/src/forktex_cloud/agent.py +51 -0
- forktex_cloud-3.0.0/src/forktex_cloud/bridge/__init__.py +9 -0
- forktex_cloud-3.0.0/src/forktex_cloud/bridge/local_compose.py +323 -0
- {forktex_cloud-2.1.0 → forktex_cloud-3.0.0}/src/forktex_cloud/client/__init__.py +14 -17
- forktex_cloud-3.0.0/src/forktex_cloud/client/client.py +1310 -0
- forktex_cloud-3.0.0/src/forktex_cloud/client/facade.py +296 -0
- forktex_cloud-3.0.0/src/forktex_cloud/client/generated/__init__.py +2752 -0
- forktex_cloud-3.0.0/src/forktex_cloud/client/oci.py +91 -0
- forktex_cloud-3.0.0/src/forktex_cloud/config.py +26 -0
- forktex_cloud-3.0.0/src/forktex_cloud/errors.py +48 -0
- forktex_cloud-3.0.0/src/forktex_cloud/local.py +144 -0
- {forktex_cloud-2.1.0 → forktex_cloud-3.0.0}/src/forktex_cloud/manifest/__init__.py +0 -7
- forktex_cloud-3.0.0/src/forktex_cloud/manifest/errors.py +7 -0
- {forktex_cloud-2.1.0 → forktex_cloud-3.0.0}/src/forktex_cloud/manifest/loader.py +21 -68
- {forktex_cloud-2.1.0 → forktex_cloud-3.0.0}/src/forktex_cloud/manifest/merge.py +2 -9
- {forktex_cloud-2.1.0 → forktex_cloud-3.0.0}/src/forktex_cloud/manifest/schema.py +5 -4
- forktex_cloud-3.0.0/src/forktex_cloud/manifest/semantics.py +113 -0
- forktex_cloud-3.0.0/src/forktex_cloud/platform.py +255 -0
- forktex_cloud-3.0.0/src/forktex_cloud/presets.py +249 -0
- forktex_cloud-3.0.0/src/forktex_cloud/py.typed +0 -0
- forktex_cloud-2.1.0/PKG-INFO +0 -200
- forktex_cloud-2.1.0/README.md +0 -165
- forktex_cloud-2.1.0/src/forktex_cloud/__init__.py +0 -148
- forktex_cloud-2.1.0/src/forktex_cloud/bridge/__init__.py +0 -1
- forktex_cloud-2.1.0/src/forktex_cloud/bridge/local_compose.py +0 -396
- forktex_cloud-2.1.0/src/forktex_cloud/bridge/log_formatter.py +0 -39
- forktex_cloud-2.1.0/src/forktex_cloud/bridge/loki.py +0 -86
- forktex_cloud-2.1.0/src/forktex_cloud/bridge/persistence_defaults.py +0 -97
- forktex_cloud-2.1.0/src/forktex_cloud/client/client.py +0 -1319
- forktex_cloud-2.1.0/src/forktex_cloud/client/generated/__init__.py +0 -1907
- forktex_cloud-2.1.0/src/forktex_cloud/config.py +0 -40
- forktex_cloud-2.1.0/src/forktex_cloud/manifest/errors.py +0 -11
- forktex_cloud-2.1.0/src/forktex_cloud/scaffold/__init__.py +0 -1
- forktex_cloud-2.1.0/src/forktex_cloud/scaffold/templates.py +0 -73
- forktex_cloud-2.1.0/src/forktex_cloud/secrets/__init__.py +0 -1
- forktex_cloud-2.1.0/src/forktex_cloud/secrets/base.py +0 -29
- forktex_cloud-2.1.0/src/forktex_cloud/secrets/factory.py +0 -31
- forktex_cloud-2.1.0/src/forktex_cloud/secrets/fernet.py +0 -73
- forktex_cloud-2.1.0/src/forktex_cloud/secrets/resolver.py +0 -36
- forktex_cloud-2.1.0/src/forktex_cloud/templates/observability/loki.yml +0 -32
- forktex_cloud-2.1.0/src/forktex_cloud/templates/observability/promtail.yml +0 -23
- forktex_cloud-2.1.0/src/forktex_cloud/vpn/__init__.py +0 -23
- forktex_cloud-2.1.0/src/forktex_cloud/vpn/local.py +0 -86
- {forktex_cloud-2.1.0 → forktex_cloud-3.0.0}/LICENSE +0 -0
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: forktex-cloud
|
|
3
|
+
Version: 3.0.0
|
|
4
|
+
Summary: Typed Python SDK for the ForkTex Cloud platform — provision, deploy, and manage VPS-backed apps via a declarative manifest.
|
|
5
|
+
License-Expression: MIT
|
|
6
|
+
License-File: LICENSE
|
|
7
|
+
Keywords: cloud,deployment,vps,hetzner,ansible,blue-green,iac,infrastructure-as-code,sdk
|
|
8
|
+
Author: ForkTex
|
|
9
|
+
Author-email: info@forktex.com
|
|
10
|
+
Requires-Python: >=3.14,<4.0
|
|
11
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Intended Audience :: System Administrators
|
|
14
|
+
Classifier: Operating System :: OS Independent
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
18
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
19
|
+
Classifier: Topic :: System :: Distributed Computing
|
|
20
|
+
Classifier: Topic :: System :: Installation/Setup
|
|
21
|
+
Classifier: Topic :: System :: Systems Administration
|
|
22
|
+
Classifier: Typing :: Typed
|
|
23
|
+
Requires-Dist: httpx (>=0.28,<1)
|
|
24
|
+
Requires-Dist: pydantic[email] (>=2.14.2,<3)
|
|
25
|
+
Requires-Dist: pyyaml (>=6.0.3,<7)
|
|
26
|
+
Project-URL: Changelog, https://github.com/forktex/cloud/blob/master/sdk-py/CHANGELOG.md
|
|
27
|
+
Project-URL: Documentation, https://github.com/forktex/cloud/tree/master/docs
|
|
28
|
+
Project-URL: Homepage, https://forktex.com
|
|
29
|
+
Project-URL: Issues, https://github.com/forktex/cloud/issues
|
|
30
|
+
Project-URL: Repository, https://github.com/forktex/cloud
|
|
31
|
+
Description-Content-Type: text/markdown
|
|
32
|
+
|
|
33
|
+
# forktex-cloud
|
|
34
|
+
|
|
35
|
+
[](https://pypi.org/project/forktex-cloud/)
|
|
36
|
+
[](https://pypi.org/project/forktex-cloud/)
|
|
37
|
+
[](https://github.com/forktex/cloud/blob/master/sdk-py/LICENSE)
|
|
38
|
+
|
|
39
|
+
Standalone Python SDK for the [ForkTex Cloud](https://cloud.forktex.com) platform.
|
|
40
|
+
|
|
41
|
+
`forktex-cloud` is the typed `httpx` client plus the manifest plumbing for the ForkTex
|
|
42
|
+
Cloud control plane: projects, servers, deployments, vault, manifest loading and the
|
|
43
|
+
docker-compose renderer. It is a **library, not a CLI** — it installs no console script.
|
|
44
|
+
|
|
45
|
+
## Install
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
pip install forktex-cloud
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Requires Python ≥ 3.14.
|
|
52
|
+
|
|
53
|
+
## Two layers
|
|
54
|
+
|
|
55
|
+
`CloudClient` is pure transport: one method per API operation, nothing that touches your
|
|
56
|
+
machine. `Cloud` **is** a `CloudClient` and adds what only makes sense locally —
|
|
57
|
+
`manifest()`, `compose()`, `publish()` and `deploy(project_dir=…)`. Hold a `Cloud`.
|
|
58
|
+
|
|
59
|
+
## Quick start
|
|
60
|
+
|
|
61
|
+
An org API key (CI). Org-scoped calls need `org_id`:
|
|
62
|
+
|
|
63
|
+
```python
|
|
64
|
+
from forktex_cloud import Cloud, CloudContext
|
|
65
|
+
|
|
66
|
+
ctx = CloudContext(
|
|
67
|
+
controller="https://cloud.forktex.com",
|
|
68
|
+
account_key="ftx-...",
|
|
69
|
+
org_id="00000000-0000-0000-0000-000000000001",
|
|
70
|
+
)
|
|
71
|
+
with Cloud.from_context(ctx) as cloud:
|
|
72
|
+
projects = cloud.list_projects()
|
|
73
|
+
events = cloud.list_audit_events(limit=20)
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
A user session — `login()` signs the client in, `logout()` ends the session:
|
|
77
|
+
|
|
78
|
+
```python
|
|
79
|
+
with Cloud("https://cloud.forktex.com") as cloud:
|
|
80
|
+
session = cloud.login("me@example.com", "password")
|
|
81
|
+
org_id = str(cloud.me().orgs[0].id)
|
|
82
|
+
|
|
83
|
+
# Later, from the stored token:
|
|
84
|
+
cloud = Cloud("https://cloud.forktex.com", access_token=session.token, org_id=org_id)
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
A failed call raises `CloudAPIError` carrying the controller's error envelope:
|
|
88
|
+
`status_code`, `code`, `message`, `details`, `trace_id`. Every SDK error derives from
|
|
89
|
+
`CloudError`; an org-scoped call on a client without `org_id` raises `ConfigurationError`.
|
|
90
|
+
|
|
91
|
+
For tests, pass any `httpx` transport as `transport=`.
|
|
92
|
+
|
|
93
|
+
## Onboarding a tenant
|
|
94
|
+
|
|
95
|
+
A controller closed to signups (`auth_policy().registration_open` is false) onboards tenants
|
|
96
|
+
through a platform admin, who creates the account and its personal org:
|
|
97
|
+
|
|
98
|
+
```python
|
|
99
|
+
with Cloud(URL) as admin:
|
|
100
|
+
admin.login(ADMIN_EMAIL, ADMIN_PASSWORD)
|
|
101
|
+
admin.create_user("tenant@example.com", initial_password)
|
|
102
|
+
|
|
103
|
+
with Cloud(URL) as tenant:
|
|
104
|
+
tenant.login("tenant@example.com", initial_password)
|
|
105
|
+
org_id = str(tenant.me().orgs[0].id)
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
`set_user_active(user_id, False)` disables an account; `set_platform_admin` grants or revokes
|
|
109
|
+
the flag.
|
|
110
|
+
|
|
111
|
+
## Deploying
|
|
112
|
+
|
|
113
|
+
A deploy is addressed by `(project_id, environment_id)`. `create_project` is idempotent on
|
|
114
|
+
`(org, name)` and returns both ids.
|
|
115
|
+
|
|
116
|
+
```python
|
|
117
|
+
from pathlib import Path
|
|
118
|
+
|
|
119
|
+
from forktex_cloud import DeployBlocked
|
|
120
|
+
|
|
121
|
+
project = cloud.create_project("my-app", environment="production")
|
|
122
|
+
|
|
123
|
+
# What deploying the environment's stored manifest would change (read-only).
|
|
124
|
+
print(cloud.plan(str(project.id), str(project.environment_id)))
|
|
125
|
+
|
|
126
|
+
# From a working tree: reads forktex.json (+ the forktex.<env>.json overlay), builds every
|
|
127
|
+
# service with a `build` block (docker buildx) and pushes it to the platform registry,
|
|
128
|
+
# tarballs the bind-mounted asset directories and records git HEAD as provenance.
|
|
129
|
+
job = cloud.deploy(
|
|
130
|
+
str(project.id),
|
|
131
|
+
str(project.environment_id),
|
|
132
|
+
project_dir=Path("."),
|
|
133
|
+
env="production",
|
|
134
|
+
)
|
|
135
|
+
|
|
136
|
+
# A failed run is returned (check run.status), not raised. DeployBlocked is raised when the
|
|
137
|
+
# run waits for a person (an approval, a DNS record): answer the task and wait again.
|
|
138
|
+
try:
|
|
139
|
+
run = cloud.wait_for_run(job.job_id)
|
|
140
|
+
except DeployBlocked as blocked:
|
|
141
|
+
task = blocked.waiting[0]
|
|
142
|
+
cloud.complete_task(
|
|
143
|
+
job.job_id, task.element_id, "confirm" if task.kind == "dns_record" else "approve"
|
|
144
|
+
)
|
|
145
|
+
run = cloud.wait_for_run(job.job_id)
|
|
146
|
+
|
|
147
|
+
cloud.destroy_environment(str(project.id), str(project.environment_id))
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
`deploy` also accepts `manifest_data=` instead of `project_dir=`, plus `image_artifacts=`,
|
|
151
|
+
`commit_sha=`, `assets_tarball_b64=`, `skip_dns=`, `skip_ssl=`, `require_approval=`,
|
|
152
|
+
`registry_address=` and `into=`.
|
|
153
|
+
|
|
154
|
+
An org that brings its own registry builds into it instead of the platform's: add it as a
|
|
155
|
+
credential (`add_registry`), then pass its id and your push login. No platform push token is
|
|
156
|
+
minted, and the servers pull with the credential the org stored.
|
|
157
|
+
|
|
158
|
+
```python
|
|
159
|
+
from forktex_cloud import OwnRegistry
|
|
160
|
+
|
|
161
|
+
own = OwnRegistry(
|
|
162
|
+
registry_id=credential_id,
|
|
163
|
+
address="ghcr.io",
|
|
164
|
+
repository_prefix="acme/site",
|
|
165
|
+
username="acme-bot",
|
|
166
|
+
password=token,
|
|
167
|
+
platforms=("linux/arm64",),
|
|
168
|
+
)
|
|
169
|
+
cloud.deploy(project_id, environment_id, project_dir=Path("."), into=own)
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
`platforms` names what the servers run (`linux/amd64`, `linux/arm64`); an image built for
|
|
173
|
+
another architecture pulls and then fails to start.
|
|
174
|
+
|
|
175
|
+
Beyond deploys, the client covers environments (`create_environment`, `attach_server`,
|
|
176
|
+
`detach_server`), image pins (`list_service_images`, `set_service_image`), backups
|
|
177
|
+
(`list_backups`, `create_backup`, `sync_backups`, `restore_backup`), DNS (`dns_zone`,
|
|
178
|
+
`set_dns_credential`, `create_dns_record`), runs (`stream_flow_run`, `flow_events`, `cancel_flow_run`) and
|
|
179
|
+
the provider catalog (`catalog_flavours`, `catalog_regions`, `catalog_images`).
|
|
180
|
+
|
|
181
|
+
## Manifest loading and validation
|
|
182
|
+
|
|
183
|
+
```python
|
|
184
|
+
from forktex_cloud import Manifest, ManifestError
|
|
185
|
+
|
|
186
|
+
try:
|
|
187
|
+
m = Manifest.load(Path("forktex.json"), env="production")
|
|
188
|
+
except ManifestError as e:
|
|
189
|
+
print(f"Invalid manifest: {e}")
|
|
190
|
+
raise
|
|
191
|
+
|
|
192
|
+
print(m.cloud.metadata.name)
|
|
193
|
+
for svc in m.services_for_env(env="production"):
|
|
194
|
+
print(svc["id"], svc["type"], svc.get("image"))
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
`m.cloud` is the typed model; `m.root`, `m.services`, `m.compute_services()` and the other
|
|
198
|
+
accessors return plain dicts.
|
|
199
|
+
|
|
200
|
+
## Rendering a local stack
|
|
201
|
+
|
|
202
|
+
```python
|
|
203
|
+
import yaml
|
|
204
|
+
|
|
205
|
+
compose = cloud.compose(".", env="local") # a docker-compose dict
|
|
206
|
+
Path("docker-compose.local.yml").write_text(yaml.safe_dump(compose))
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
`forktex_cloud.local.main()` is the ready-made driver — render, up, down, logs, ps — behind
|
|
210
|
+
the cloud repo's `make start`.
|
|
211
|
+
|
|
212
|
+
## Secrets vault (server-side, org-scoped)
|
|
213
|
+
|
|
214
|
+
```python
|
|
215
|
+
cloud.vault_set("POSTGRES_PASSWORD", "hunter2") # -> VaultSetResponse
|
|
216
|
+
secret = cloud.vault_get("POSTGRES_PASSWORD") # -> VaultGetResponse
|
|
217
|
+
keys = cloud.vault_list() # -> list[str]
|
|
218
|
+
cloud.vault_delete("POSTGRES_PASSWORD")
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
## What's in the package
|
|
222
|
+
|
|
223
|
+
| Module | Purpose |
|
|
224
|
+
|---|---|
|
|
225
|
+
| `forktex_cloud.client` | `Cloud` / `CloudClient` (sync httpx) + every OpenAPI-generated pydantic model |
|
|
226
|
+
| `forktex_cloud.errors` | `CloudError`, `CloudAPIError`, `ConfigurationError`, `DeployBlocked` |
|
|
227
|
+
| `forktex_cloud.manifest` | `Manifest` loader, the generated schema, overlay deep-merge, `ManifestError` |
|
|
228
|
+
| `forktex_cloud.config` | `CloudContext` — controller URL, credential, org |
|
|
229
|
+
| `forktex_cloud.local` | The local-stack driver (`main()`): render, up, down, logs, ps |
|
|
230
|
+
| `forktex_cloud.platform` | What the platform runs beside a project, locally and on a server: pinned images, the container labels, and the log stack (Loki, Alloy) and its configs |
|
|
231
|
+
| `forktex_cloud.bridge` | `local_compose_from_manifest`, `render_observability_configs` |
|
|
232
|
+
| `forktex_cloud.presets` | `PRESETS`, `Preset`: what a persistence service naming `preset` is given |
|
|
233
|
+
| `forktex_cloud.agent` | `forktex-agent`, the host agent: phase 0 says it is alive on an interval (`--interval`, `--once`) |
|
|
234
|
+
|
|
235
|
+
The client, manifest and bridge layers deal in data; only `forktex_cloud.local` writes files,
|
|
236
|
+
under the project's `.forktex/cache/`. Request and response models come from the server's
|
|
237
|
+
OpenAPI spec, and the package ships `py.typed`.
|
|
238
|
+
|
|
239
|
+
## Top-level re-exports
|
|
240
|
+
|
|
241
|
+
```python
|
|
242
|
+
from forktex_cloud import (
|
|
243
|
+
Cloud,
|
|
244
|
+
CloudClient,
|
|
245
|
+
CloudError,
|
|
246
|
+
CloudAPIError,
|
|
247
|
+
ConfigurationError,
|
|
248
|
+
DeployBlocked,
|
|
249
|
+
CloudContext,
|
|
250
|
+
Manifest,
|
|
251
|
+
ManifestError,
|
|
252
|
+
SPEC_VERSION,
|
|
253
|
+
SPEC_HASH,
|
|
254
|
+
ApiKeyCreated,
|
|
255
|
+
ApiKeyRead,
|
|
256
|
+
AuditEventRead,
|
|
257
|
+
EnvironmentRead,
|
|
258
|
+
StatusRead,
|
|
259
|
+
JobResponse,
|
|
260
|
+
MeResponse,
|
|
261
|
+
OrgRead,
|
|
262
|
+
ProjectRead,
|
|
263
|
+
ServerRead,
|
|
264
|
+
StatusResponse,
|
|
265
|
+
SessionResponse,
|
|
266
|
+
UserRead,
|
|
267
|
+
VaultGetResponse,
|
|
268
|
+
)
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
They resolve lazily (PEP 562), so `import forktex_cloud` stays cheap. The full model set
|
|
272
|
+
lives in `forktex_cloud.client.generated`.
|
|
273
|
+
|
|
274
|
+
## Versioning
|
|
275
|
+
|
|
276
|
+
SemVer. The models are generated from the server's OpenAPI spec at a fixed `SPEC_VERSION` +
|
|
277
|
+
`SPEC_HASH`, readable at runtime from `forktex_cloud.client.generated`.
|
|
278
|
+
|
|
279
|
+
## Repository
|
|
280
|
+
|
|
281
|
+
This SDK lives in the [`forktex/cloud`](https://github.com/forktex/cloud) monorepo beside
|
|
282
|
+
the API server (`api/`) and the Expo client (`client/`), and is published to PyPI
|
|
283
|
+
independently.
|
|
284
|
+
|
|
285
|
+
- Issues: https://github.com/forktex/cloud/issues
|
|
286
|
+
- Changelog: [CHANGELOG.md](CHANGELOG.md)
|
|
287
|
+
|
|
288
|
+
## License
|
|
289
|
+
|
|
290
|
+
MIT — see [LICENSE](LICENSE).
|
|
291
|
+
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
# forktex-cloud
|
|
2
|
+
|
|
3
|
+
[](https://pypi.org/project/forktex-cloud/)
|
|
4
|
+
[](https://pypi.org/project/forktex-cloud/)
|
|
5
|
+
[](https://github.com/forktex/cloud/blob/master/sdk-py/LICENSE)
|
|
6
|
+
|
|
7
|
+
Standalone Python SDK for the [ForkTex Cloud](https://cloud.forktex.com) platform.
|
|
8
|
+
|
|
9
|
+
`forktex-cloud` is the typed `httpx` client plus the manifest plumbing for the ForkTex
|
|
10
|
+
Cloud control plane: projects, servers, deployments, vault, manifest loading and the
|
|
11
|
+
docker-compose renderer. It is a **library, not a CLI** — it installs no console script.
|
|
12
|
+
|
|
13
|
+
## Install
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
pip install forktex-cloud
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Requires Python ≥ 3.14.
|
|
20
|
+
|
|
21
|
+
## Two layers
|
|
22
|
+
|
|
23
|
+
`CloudClient` is pure transport: one method per API operation, nothing that touches your
|
|
24
|
+
machine. `Cloud` **is** a `CloudClient` and adds what only makes sense locally —
|
|
25
|
+
`manifest()`, `compose()`, `publish()` and `deploy(project_dir=…)`. Hold a `Cloud`.
|
|
26
|
+
|
|
27
|
+
## Quick start
|
|
28
|
+
|
|
29
|
+
An org API key (CI). Org-scoped calls need `org_id`:
|
|
30
|
+
|
|
31
|
+
```python
|
|
32
|
+
from forktex_cloud import Cloud, CloudContext
|
|
33
|
+
|
|
34
|
+
ctx = CloudContext(
|
|
35
|
+
controller="https://cloud.forktex.com",
|
|
36
|
+
account_key="ftx-...",
|
|
37
|
+
org_id="00000000-0000-0000-0000-000000000001",
|
|
38
|
+
)
|
|
39
|
+
with Cloud.from_context(ctx) as cloud:
|
|
40
|
+
projects = cloud.list_projects()
|
|
41
|
+
events = cloud.list_audit_events(limit=20)
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
A user session — `login()` signs the client in, `logout()` ends the session:
|
|
45
|
+
|
|
46
|
+
```python
|
|
47
|
+
with Cloud("https://cloud.forktex.com") as cloud:
|
|
48
|
+
session = cloud.login("me@example.com", "password")
|
|
49
|
+
org_id = str(cloud.me().orgs[0].id)
|
|
50
|
+
|
|
51
|
+
# Later, from the stored token:
|
|
52
|
+
cloud = Cloud("https://cloud.forktex.com", access_token=session.token, org_id=org_id)
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
A failed call raises `CloudAPIError` carrying the controller's error envelope:
|
|
56
|
+
`status_code`, `code`, `message`, `details`, `trace_id`. Every SDK error derives from
|
|
57
|
+
`CloudError`; an org-scoped call on a client without `org_id` raises `ConfigurationError`.
|
|
58
|
+
|
|
59
|
+
For tests, pass any `httpx` transport as `transport=`.
|
|
60
|
+
|
|
61
|
+
## Onboarding a tenant
|
|
62
|
+
|
|
63
|
+
A controller closed to signups (`auth_policy().registration_open` is false) onboards tenants
|
|
64
|
+
through a platform admin, who creates the account and its personal org:
|
|
65
|
+
|
|
66
|
+
```python
|
|
67
|
+
with Cloud(URL) as admin:
|
|
68
|
+
admin.login(ADMIN_EMAIL, ADMIN_PASSWORD)
|
|
69
|
+
admin.create_user("tenant@example.com", initial_password)
|
|
70
|
+
|
|
71
|
+
with Cloud(URL) as tenant:
|
|
72
|
+
tenant.login("tenant@example.com", initial_password)
|
|
73
|
+
org_id = str(tenant.me().orgs[0].id)
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
`set_user_active(user_id, False)` disables an account; `set_platform_admin` grants or revokes
|
|
77
|
+
the flag.
|
|
78
|
+
|
|
79
|
+
## Deploying
|
|
80
|
+
|
|
81
|
+
A deploy is addressed by `(project_id, environment_id)`. `create_project` is idempotent on
|
|
82
|
+
`(org, name)` and returns both ids.
|
|
83
|
+
|
|
84
|
+
```python
|
|
85
|
+
from pathlib import Path
|
|
86
|
+
|
|
87
|
+
from forktex_cloud import DeployBlocked
|
|
88
|
+
|
|
89
|
+
project = cloud.create_project("my-app", environment="production")
|
|
90
|
+
|
|
91
|
+
# What deploying the environment's stored manifest would change (read-only).
|
|
92
|
+
print(cloud.plan(str(project.id), str(project.environment_id)))
|
|
93
|
+
|
|
94
|
+
# From a working tree: reads forktex.json (+ the forktex.<env>.json overlay), builds every
|
|
95
|
+
# service with a `build` block (docker buildx) and pushes it to the platform registry,
|
|
96
|
+
# tarballs the bind-mounted asset directories and records git HEAD as provenance.
|
|
97
|
+
job = cloud.deploy(
|
|
98
|
+
str(project.id),
|
|
99
|
+
str(project.environment_id),
|
|
100
|
+
project_dir=Path("."),
|
|
101
|
+
env="production",
|
|
102
|
+
)
|
|
103
|
+
|
|
104
|
+
# A failed run is returned (check run.status), not raised. DeployBlocked is raised when the
|
|
105
|
+
# run waits for a person (an approval, a DNS record): answer the task and wait again.
|
|
106
|
+
try:
|
|
107
|
+
run = cloud.wait_for_run(job.job_id)
|
|
108
|
+
except DeployBlocked as blocked:
|
|
109
|
+
task = blocked.waiting[0]
|
|
110
|
+
cloud.complete_task(
|
|
111
|
+
job.job_id, task.element_id, "confirm" if task.kind == "dns_record" else "approve"
|
|
112
|
+
)
|
|
113
|
+
run = cloud.wait_for_run(job.job_id)
|
|
114
|
+
|
|
115
|
+
cloud.destroy_environment(str(project.id), str(project.environment_id))
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
`deploy` also accepts `manifest_data=` instead of `project_dir=`, plus `image_artifacts=`,
|
|
119
|
+
`commit_sha=`, `assets_tarball_b64=`, `skip_dns=`, `skip_ssl=`, `require_approval=`,
|
|
120
|
+
`registry_address=` and `into=`.
|
|
121
|
+
|
|
122
|
+
An org that brings its own registry builds into it instead of the platform's: add it as a
|
|
123
|
+
credential (`add_registry`), then pass its id and your push login. No platform push token is
|
|
124
|
+
minted, and the servers pull with the credential the org stored.
|
|
125
|
+
|
|
126
|
+
```python
|
|
127
|
+
from forktex_cloud import OwnRegistry
|
|
128
|
+
|
|
129
|
+
own = OwnRegistry(
|
|
130
|
+
registry_id=credential_id,
|
|
131
|
+
address="ghcr.io",
|
|
132
|
+
repository_prefix="acme/site",
|
|
133
|
+
username="acme-bot",
|
|
134
|
+
password=token,
|
|
135
|
+
platforms=("linux/arm64",),
|
|
136
|
+
)
|
|
137
|
+
cloud.deploy(project_id, environment_id, project_dir=Path("."), into=own)
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
`platforms` names what the servers run (`linux/amd64`, `linux/arm64`); an image built for
|
|
141
|
+
another architecture pulls and then fails to start.
|
|
142
|
+
|
|
143
|
+
Beyond deploys, the client covers environments (`create_environment`, `attach_server`,
|
|
144
|
+
`detach_server`), image pins (`list_service_images`, `set_service_image`), backups
|
|
145
|
+
(`list_backups`, `create_backup`, `sync_backups`, `restore_backup`), DNS (`dns_zone`,
|
|
146
|
+
`set_dns_credential`, `create_dns_record`), runs (`stream_flow_run`, `flow_events`, `cancel_flow_run`) and
|
|
147
|
+
the provider catalog (`catalog_flavours`, `catalog_regions`, `catalog_images`).
|
|
148
|
+
|
|
149
|
+
## Manifest loading and validation
|
|
150
|
+
|
|
151
|
+
```python
|
|
152
|
+
from forktex_cloud import Manifest, ManifestError
|
|
153
|
+
|
|
154
|
+
try:
|
|
155
|
+
m = Manifest.load(Path("forktex.json"), env="production")
|
|
156
|
+
except ManifestError as e:
|
|
157
|
+
print(f"Invalid manifest: {e}")
|
|
158
|
+
raise
|
|
159
|
+
|
|
160
|
+
print(m.cloud.metadata.name)
|
|
161
|
+
for svc in m.services_for_env(env="production"):
|
|
162
|
+
print(svc["id"], svc["type"], svc.get("image"))
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
`m.cloud` is the typed model; `m.root`, `m.services`, `m.compute_services()` and the other
|
|
166
|
+
accessors return plain dicts.
|
|
167
|
+
|
|
168
|
+
## Rendering a local stack
|
|
169
|
+
|
|
170
|
+
```python
|
|
171
|
+
import yaml
|
|
172
|
+
|
|
173
|
+
compose = cloud.compose(".", env="local") # a docker-compose dict
|
|
174
|
+
Path("docker-compose.local.yml").write_text(yaml.safe_dump(compose))
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
`forktex_cloud.local.main()` is the ready-made driver — render, up, down, logs, ps — behind
|
|
178
|
+
the cloud repo's `make start`.
|
|
179
|
+
|
|
180
|
+
## Secrets vault (server-side, org-scoped)
|
|
181
|
+
|
|
182
|
+
```python
|
|
183
|
+
cloud.vault_set("POSTGRES_PASSWORD", "hunter2") # -> VaultSetResponse
|
|
184
|
+
secret = cloud.vault_get("POSTGRES_PASSWORD") # -> VaultGetResponse
|
|
185
|
+
keys = cloud.vault_list() # -> list[str]
|
|
186
|
+
cloud.vault_delete("POSTGRES_PASSWORD")
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
## What's in the package
|
|
190
|
+
|
|
191
|
+
| Module | Purpose |
|
|
192
|
+
|---|---|
|
|
193
|
+
| `forktex_cloud.client` | `Cloud` / `CloudClient` (sync httpx) + every OpenAPI-generated pydantic model |
|
|
194
|
+
| `forktex_cloud.errors` | `CloudError`, `CloudAPIError`, `ConfigurationError`, `DeployBlocked` |
|
|
195
|
+
| `forktex_cloud.manifest` | `Manifest` loader, the generated schema, overlay deep-merge, `ManifestError` |
|
|
196
|
+
| `forktex_cloud.config` | `CloudContext` — controller URL, credential, org |
|
|
197
|
+
| `forktex_cloud.local` | The local-stack driver (`main()`): render, up, down, logs, ps |
|
|
198
|
+
| `forktex_cloud.platform` | What the platform runs beside a project, locally and on a server: pinned images, the container labels, and the log stack (Loki, Alloy) and its configs |
|
|
199
|
+
| `forktex_cloud.bridge` | `local_compose_from_manifest`, `render_observability_configs` |
|
|
200
|
+
| `forktex_cloud.presets` | `PRESETS`, `Preset`: what a persistence service naming `preset` is given |
|
|
201
|
+
| `forktex_cloud.agent` | `forktex-agent`, the host agent: phase 0 says it is alive on an interval (`--interval`, `--once`) |
|
|
202
|
+
|
|
203
|
+
The client, manifest and bridge layers deal in data; only `forktex_cloud.local` writes files,
|
|
204
|
+
under the project's `.forktex/cache/`. Request and response models come from the server's
|
|
205
|
+
OpenAPI spec, and the package ships `py.typed`.
|
|
206
|
+
|
|
207
|
+
## Top-level re-exports
|
|
208
|
+
|
|
209
|
+
```python
|
|
210
|
+
from forktex_cloud import (
|
|
211
|
+
Cloud,
|
|
212
|
+
CloudClient,
|
|
213
|
+
CloudError,
|
|
214
|
+
CloudAPIError,
|
|
215
|
+
ConfigurationError,
|
|
216
|
+
DeployBlocked,
|
|
217
|
+
CloudContext,
|
|
218
|
+
Manifest,
|
|
219
|
+
ManifestError,
|
|
220
|
+
SPEC_VERSION,
|
|
221
|
+
SPEC_HASH,
|
|
222
|
+
ApiKeyCreated,
|
|
223
|
+
ApiKeyRead,
|
|
224
|
+
AuditEventRead,
|
|
225
|
+
EnvironmentRead,
|
|
226
|
+
StatusRead,
|
|
227
|
+
JobResponse,
|
|
228
|
+
MeResponse,
|
|
229
|
+
OrgRead,
|
|
230
|
+
ProjectRead,
|
|
231
|
+
ServerRead,
|
|
232
|
+
StatusResponse,
|
|
233
|
+
SessionResponse,
|
|
234
|
+
UserRead,
|
|
235
|
+
VaultGetResponse,
|
|
236
|
+
)
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
They resolve lazily (PEP 562), so `import forktex_cloud` stays cheap. The full model set
|
|
240
|
+
lives in `forktex_cloud.client.generated`.
|
|
241
|
+
|
|
242
|
+
## Versioning
|
|
243
|
+
|
|
244
|
+
SemVer. The models are generated from the server's OpenAPI spec at a fixed `SPEC_VERSION` +
|
|
245
|
+
`SPEC_HASH`, readable at runtime from `forktex_cloud.client.generated`.
|
|
246
|
+
|
|
247
|
+
## Repository
|
|
248
|
+
|
|
249
|
+
This SDK lives in the [`forktex/cloud`](https://github.com/forktex/cloud) monorepo beside
|
|
250
|
+
the API server (`api/`) and the Expo client (`client/`), and is published to PyPI
|
|
251
|
+
independently.
|
|
252
|
+
|
|
253
|
+
- Issues: https://github.com/forktex/cloud/issues
|
|
254
|
+
- Changelog: [CHANGELOG.md](CHANGELOG.md)
|
|
255
|
+
|
|
256
|
+
## License
|
|
257
|
+
|
|
258
|
+
MIT — see [LICENSE](LICENSE).
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "forktex-cloud"
|
|
3
|
-
version = "
|
|
3
|
+
version = "3.0.0"
|
|
4
4
|
description = "Typed Python SDK for the ForkTex Cloud platform — provision, deploy, and manage VPS-backed apps via a declarative manifest."
|
|
5
5
|
authors = [
|
|
6
6
|
{name = "ForkTex", email = "info@forktex.com"}
|
|
@@ -8,9 +8,8 @@ authors = [
|
|
|
8
8
|
readme = "README.md"
|
|
9
9
|
license = "MIT"
|
|
10
10
|
license-files = ["LICENSE"]
|
|
11
|
-
requires-python = ">=3.
|
|
11
|
+
requires-python = ">=3.14,<4.0"
|
|
12
12
|
keywords = [
|
|
13
|
-
"forktex",
|
|
14
13
|
"cloud",
|
|
15
14
|
"deployment",
|
|
16
15
|
"vps",
|
|
@@ -28,8 +27,7 @@ classifiers = [
|
|
|
28
27
|
"Operating System :: OS Independent",
|
|
29
28
|
"Programming Language :: Python :: 3",
|
|
30
29
|
"Programming Language :: Python :: 3 :: Only",
|
|
31
|
-
"Programming Language :: Python :: 3.
|
|
32
|
-
"Programming Language :: Python :: 3.12",
|
|
30
|
+
"Programming Language :: Python :: 3.14",
|
|
33
31
|
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
34
32
|
"Topic :: System :: Distributed Computing",
|
|
35
33
|
"Topic :: System :: Installation/Setup",
|
|
@@ -37,12 +35,14 @@ classifiers = [
|
|
|
37
35
|
"Typing :: Typed",
|
|
38
36
|
]
|
|
39
37
|
dependencies = [
|
|
40
|
-
"pydantic[email]
|
|
41
|
-
"httpx
|
|
42
|
-
"pyyaml>=6.0",
|
|
43
|
-
"cryptography>=42.0",
|
|
38
|
+
"pydantic[email]>=2.14.2,<3",
|
|
39
|
+
"httpx>=0.28,<1",
|
|
40
|
+
"pyyaml>=6.0.3,<7",
|
|
44
41
|
]
|
|
45
42
|
|
|
43
|
+
[project.scripts]
|
|
44
|
+
forktex-agent = "forktex_cloud.agent:main"
|
|
45
|
+
|
|
46
46
|
[project.urls]
|
|
47
47
|
"Homepage" = "https://forktex.com"
|
|
48
48
|
"Documentation" = "https://github.com/forktex/cloud/tree/master/docs"
|
|
@@ -56,15 +56,20 @@ build-backend = "poetry.core.masonry.api"
|
|
|
56
56
|
|
|
57
57
|
[dependency-groups]
|
|
58
58
|
dev = [
|
|
59
|
-
"pytest
|
|
60
|
-
"pytest-asyncio
|
|
61
|
-
"ruff
|
|
62
|
-
"pyright
|
|
63
|
-
|
|
59
|
+
"pytest>=9.2",
|
|
60
|
+
"pytest-asyncio>=1.4",
|
|
61
|
+
"ruff>=0.17.3",
|
|
62
|
+
"pyright==1.1.414",
|
|
63
|
+
# Release tooling. `make build` and `make publish` shell out to these, so
|
|
64
|
+
# undeclared they turn a release into "No module named twine" at the moment
|
|
65
|
+
# you try to ship. Same pair, same versions, as ../forktex-py.
|
|
66
|
+
"build>=1.6",
|
|
67
|
+
"twine>=7",
|
|
68
|
+
"pip-audit>=2.10",
|
|
64
69
|
]
|
|
65
70
|
|
|
66
71
|
[tool.ruff]
|
|
67
|
-
target-version = "
|
|
72
|
+
target-version = "py314"
|
|
68
73
|
line-length = 100
|
|
69
74
|
extend-exclude = [
|
|
70
75
|
# Auto-generated by OpenAPI codegen. Canonical import shape comes from
|
|
@@ -76,6 +81,7 @@ extend-exclude = [
|
|
|
76
81
|
[tool.ruff.lint]
|
|
77
82
|
select = ["E", "F", "I", "W"]
|
|
78
83
|
|
|
84
|
+
|
|
79
85
|
[tool.pytest.ini_options]
|
|
80
86
|
asyncio_mode = "auto"
|
|
81
87
|
testpaths = ["tests"]
|