podstack 1.7.0__tar.gz → 1.9.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.
Files changed (89) hide show
  1. podstack-1.9.0/AGENTS.md +72 -0
  2. podstack-1.9.0/MANIFEST.in +10 -0
  3. podstack-1.9.0/PKG-INFO +144 -0
  4. podstack-1.9.0/README.md +110 -0
  5. podstack-1.9.0/docs/audit.md +54 -0
  6. podstack-1.9.0/docs/functions.md +117 -0
  7. podstack-1.9.0/examples/01_quickstart.py +26 -0
  8. podstack-1.9.0/examples/02_functions.py +42 -0
  9. podstack-1.9.0/examples/03_instances.py +52 -0
  10. podstack-1.9.0/examples/04_jobs.py +39 -0
  11. podstack-1.9.0/examples/05_endpoints.py +53 -0
  12. podstack-1.9.0/examples/06_inference.py +50 -0
  13. podstack-1.9.0/examples/07_balance.py +34 -0
  14. podstack-1.9.0/examples/08_tools.py +39 -0
  15. podstack-1.9.0/examples/09_mcp.py +45 -0
  16. podstack-1.9.0/examples/README.md +18 -0
  17. podstack-1.9.0/llms.txt +25 -0
  18. podstack-1.9.0/pyproject.toml +85 -0
  19. podstack-1.9.0/skills/podstack/SKILL.md +37 -0
  20. podstack-1.9.0/src/podstack/__init__.py +52 -0
  21. podstack-1.9.0/src/podstack/_version.py +3 -0
  22. podstack-1.9.0/src/podstack/async_client.py +1000 -0
  23. podstack-1.9.0/src/podstack/client.py +1232 -0
  24. podstack-1.9.0/src/podstack/config.py +86 -0
  25. podstack-1.9.0/src/podstack/exceptions.py +156 -0
  26. podstack-1.9.0/src/podstack/function_codec.py +178 -0
  27. podstack-1.9.0/src/podstack/functions.py +348 -0
  28. podstack-1.9.0/src/podstack/mcp.py +192 -0
  29. podstack-1.9.0/src/podstack/models.py +793 -0
  30. podstack-1.9.0/src/podstack/py.typed +0 -0
  31. podstack-1.9.0/src/podstack/ssh.py +137 -0
  32. podstack-1.9.0/src/podstack/tools.py +414 -0
  33. podstack-1.9.0/src/podstack/transport.py +402 -0
  34. podstack-1.9.0/src/podstack.egg-info/SOURCES.txt +39 -0
  35. podstack-1.9.0/tests/conftest.py +38 -0
  36. podstack-1.9.0/tests/test_client.py +362 -0
  37. podstack-1.9.0/tests/test_config_and_errors.py +83 -0
  38. podstack-1.9.0/tests/test_functions.py +378 -0
  39. podstack-1.9.0/tests/test_ssh_async.py +46 -0
  40. podstack-1.9.0/tests/test_tools_mcp.py +109 -0
  41. podstack-1.7.0/PKG-INFO +0 -919
  42. podstack-1.7.0/README.md +0 -867
  43. podstack-1.7.0/podstack/__init__.py +0 -375
  44. podstack-1.7.0/podstack/agent/__init__.py +0 -105
  45. podstack-1.7.0/podstack/agent/client.py +0 -308
  46. podstack-1.7.0/podstack/agent/exceptions.py +0 -56
  47. podstack-1.7.0/podstack/agent/models.py +0 -279
  48. podstack-1.7.0/podstack/agent/spec.py +0 -160
  49. podstack-1.7.0/podstack/annotations.py +0 -996
  50. podstack-1.7.0/podstack/cell.py +0 -860
  51. podstack-1.7.0/podstack/client.py +0 -322
  52. podstack-1.7.0/podstack/exceptions.py +0 -125
  53. podstack-1.7.0/podstack/execution.py +0 -291
  54. podstack-1.7.0/podstack/gpu_runner.py +0 -1662
  55. podstack-1.7.0/podstack/image.py +0 -515
  56. podstack-1.7.0/podstack/models.py +0 -274
  57. podstack-1.7.0/podstack/notebook.py +0 -410
  58. podstack-1.7.0/podstack/pipelines.py +0 -269
  59. podstack-1.7.0/podstack/registry/__init__.py +0 -701
  60. podstack-1.7.0/podstack/registry/autolog.py +0 -196
  61. podstack-1.7.0/podstack/registry/client.py +0 -1693
  62. podstack-1.7.0/podstack/registry/exceptions.py +0 -107
  63. podstack-1.7.0/podstack/registry/experiment.py +0 -420
  64. podstack-1.7.0/podstack/registry/model.py +0 -273
  65. podstack-1.7.0/podstack/registry/model_utils.py +0 -231
  66. podstack-1.7.0/podstack/runners.py +0 -312
  67. podstack-1.7.0/podstack/sandbox.py +0 -474
  68. podstack-1.7.0/podstack/serialization.py +0 -359
  69. podstack-1.7.0/podstack/session.py +0 -117
  70. podstack-1.7.0/podstack/storage.py +0 -291
  71. podstack-1.7.0/podstack.egg-info/PKG-INFO +0 -919
  72. podstack-1.7.0/podstack.egg-info/SOURCES.txt +0 -47
  73. podstack-1.7.0/podstack.egg-info/dependency_links.txt +0 -1
  74. podstack-1.7.0/podstack.egg-info/requires.txt +0 -30
  75. podstack-1.7.0/podstack.egg-info/top_level.txt +0 -2
  76. podstack-1.7.0/podstack_gpu/__init__.py +0 -126
  77. podstack-1.7.0/podstack_gpu/app.py +0 -675
  78. podstack-1.7.0/podstack_gpu/exceptions.py +0 -35
  79. podstack-1.7.0/podstack_gpu/image.py +0 -325
  80. podstack-1.7.0/podstack_gpu/runner.py +0 -746
  81. podstack-1.7.0/podstack_gpu/secret.py +0 -189
  82. podstack-1.7.0/podstack_gpu/utils.py +0 -203
  83. podstack-1.7.0/podstack_gpu/volume.py +0 -198
  84. podstack-1.7.0/pyproject.toml +0 -82
  85. podstack-1.7.0/tests/test_cell_serialization.py +0 -207
  86. podstack-1.7.0/tests/test_image_builder.py +0 -208
  87. podstack-1.7.0/tests/test_runners_catalog.py +0 -250
  88. {podstack-1.7.0 → podstack-1.9.0}/LICENSE +0 -0
  89. {podstack-1.7.0 → podstack-1.9.0}/setup.cfg +0 -0
@@ -0,0 +1,72 @@
1
+ # Podstack Python SDK
2
+
3
+ Use this package to call `https://podstack.ai/api/v1`. Do not use
4
+ `api.podstack.ai`. It does not resolve.
5
+
6
+ ## Credentials
7
+
8
+ `Podstack()` reads the key in this order: the `api_key` argument,
9
+ `PODSTACK_API_KEY`, then `~/.config/podstack/credentials.json`
10
+ (`XDG_CONFIG_HOME` is honored). The same file is what the Podstack CLI writes.
11
+ The server accepts `ps_live_` keys. A `psk_` string is still redacted if it appears in an error, and the API does not accept it. Do not print keys.
12
+ `repr` redacts them, and the MCP server redacts them in tool output.
13
+
14
+ Override the base with `base_url=` or `PODSTACK_API_BASE`.
15
+
16
+ ## Spending money
17
+
18
+ These calls require `confirm=True`: instance create and terminate, job submit
19
+ and cancel, endpoint create and delete, chat, embeddings, image generation,
20
+ function deploy and invoke, fine-tune create and cancel, secret delete, SSH
21
+ key delete, function delete.
22
+
23
+ `dry_run=True` returns a `DryRun` and does not send HTTP. Check `dry_run`
24
+ before asking the user to confirm. Do not estimate a price inside a dry run.
25
+ Read `client.rates.list()` and use `price_per_hour` from that response. If a
26
+ price field is missing, leave it missing.
27
+
28
+ `InsufficientBalance` means the wallet cannot cover the request. Do not invent
29
+ a shortfall amount.
30
+
31
+ ## Do not invent platform facts
32
+
33
+ GPU types, VRAM, regions, and prices come from `gpus.list()`, `rates.list()`,
34
+ `job_gpus.list()`, and `models.list()`. Pass those ids through. A 404 from
35
+ `GET /models/{id}` means that model is not available. It is not
36
+ `NotAvailableYet`.
37
+
38
+ `NotAvailableYet` is for a route the platform does not implement: function
39
+ logs when `GET /functions/{id}/logs` returns 404 or 405, and wallet when the
40
+ route is 404. A 404 from `GET /functions/{id}/runs/{run_id}` is a missing run
41
+ (`NotFoundError`).
42
+
43
+ There is no instance stop or start, no instance exec HTTP API, and no dataset
44
+ upload. `exec`, `upload`, and `download` shell out to OpenSSH using the SSH
45
+ command on the instance. Fine-tuning takes an existing `training_file` id.
46
+
47
+ ## Functions
48
+
49
+ Create functions with `@podstack.function`, not with the CLI and not with an
50
+ HTTP-only helper that uploads a notebook. The contract is `docs/functions.md`.
51
+ `deploy` registers the name, uploads a cloudpickle version, and activates it.
52
+ Invoke uses `POST /functions/{id}/runs`. The function must be a top-level
53
+ function in a file. Arguments must be JSON.
54
+
55
+ ## Tools and MCP
56
+
57
+ `podstack.tools()` returns `openai`, `anthropic`, and `mcp` schemas. Use the
58
+ names as they are. `list_functions` does not create a function. `stop_instance`
59
+ and `start_instance` return not-available and must not be replaced with a
60
+ guessed HTTP call.
61
+
62
+ Serve the same tools with `python -m podstack.mcp` or `podstack-mcp`.
63
+
64
+ ## Errors
65
+
66
+ Catch `podstack.PodstackError`. Useful subclasses: `AuthenticationError`,
67
+ `PermissionDenied`, `NotFoundError`, `ValidationError`, `RateLimitError`,
68
+ `InsufficientBalance`, `GPUNotAvailableError`, `NotAvailableYet`,
69
+ `ConfirmationRequired`, `CommandFailed`.
70
+
71
+ Retries cover connection errors and HTTP 429 and 5xx. Other status codes are
72
+ not retried.
@@ -0,0 +1,10 @@
1
+ include LICENSE README.md AGENTS.md llms.txt
2
+ recursive-include tests *.py
3
+ recursive-include docs *.md
4
+ recursive-include examples *.py
5
+ recursive-include examples *.md
6
+ recursive-include skills *.md
7
+ global-exclude *.pyc
8
+ prune build
9
+ prune dist
10
+ prune src/podstack.egg-info
@@ -0,0 +1,144 @@
1
+ Metadata-Version: 2.4
2
+ Name: podstack
3
+ Version: 1.9.0
4
+ Summary: Python SDK for the Podstack platform API
5
+ Author-email: Podstack <support@podstack.ai>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://podstack.ai
8
+ Project-URL: Documentation, https://docs.podstack.ai
9
+ Project-URL: Repository, https://github.com/Podstack-ai/podstack-python
10
+ Keywords: podstack,gpu,inference,sdk
11
+ Classifier: Development Status :: 5 - Production/Stable
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Operating System :: OS Independent
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.9
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Programming Language :: Python :: 3.13
20
+ Classifier: Typing :: Typed
21
+ Requires-Python: >=3.9
22
+ Description-Content-Type: text/markdown
23
+ License-File: LICENSE
24
+ Requires-Dist: cloudpickle<4,>=3.0
25
+ Requires-Dist: httpx>=0.24
26
+ Provides-Extra: dev
27
+ Requires-Dist: build>=1.2; extra == "dev"
28
+ Requires-Dist: mypy<2,>=1.8; extra == "dev"
29
+ Requires-Dist: pytest>=7; extra == "dev"
30
+ Requires-Dist: pytest-asyncio>=0.21; extra == "dev"
31
+ Requires-Dist: ruff>=0.4; extra == "dev"
32
+ Requires-Dist: twine>=5; extra == "dev"
33
+ Dynamic: license-file
34
+
35
+ # podstack
36
+
37
+ Python SDK for the [Podstack](https://podstack.ai) platform API.
38
+
39
+ ```bash
40
+ pip install podstack
41
+ ```
42
+
43
+ The client talks to `https://podstack.ai/api/v1`. Set `PODSTACK_API_KEY` to a
44
+ `ps_live_` key, or run `podstack auth login` so the CLI credentials file is
45
+ present. The API does not accept a `psk_` key. `api.podstack.ai` does not resolve.
46
+ Public reads such as `client.job_gpus.list()` work with no key.
47
+
48
+ ```python
49
+ from podstack import Podstack
50
+
51
+ with Podstack() as client:
52
+ for gpu in client.gpus.list():
53
+ print(gpu.gpu_type, gpu.vram_gb)
54
+ for rate in client.rates.list():
55
+ print(rate.gpu_type, rate.region, rate.price_per_hour)
56
+ ```
57
+
58
+ `price_per_hour` and every other spec are copied from the API. The SDK does
59
+ not ship a price table or a GPU catalogue.
60
+
61
+ ## Billable calls
62
+
63
+ Create, terminate, submit, cancel, chat, embeddings, image generation, and
64
+ function deploy or invoke require `confirm=True`. `dry_run=True` returns the
65
+ request and does not send it. `dry_run` is checked first.
66
+
67
+ ```python
68
+ preview = client.instances.create(gpu_type=gpu.gpu_type, dry_run=True)
69
+ operation = client.instances.create(gpu_type=gpu.gpu_type, confirm=True)
70
+ ```
71
+
72
+ There is no stop or start that keeps an instance disk. Terminate the instance
73
+ to stop the per-second charge. Commands and file copies use the SSH command
74
+ the API returns and the local `ssh` / `scp` binaries.
75
+
76
+ ## Functions
77
+
78
+ Creating a function is this package. The CLI only lists functions.
79
+
80
+ ```python
81
+ import podstack
82
+
83
+ @podstack.function(gpu="a100_80gb", requirements=["torch"])
84
+ def device_name():
85
+ import torch
86
+ return torch.cuda.get_device_name(0)
87
+
88
+ print(device_name.deploy(dry_run=True))
89
+ print(device_name.invoke(confirm=True))
90
+ ```
91
+
92
+ The function has to live in a file. Arguments must be JSON-serializable.
93
+ Calling it like a normal function raises `ConfirmationRequired` unless the
94
+ decorator was created with `confirm=True`.
95
+
96
+ ## Agents
97
+
98
+ `podstack.tools()` returns OpenAI, Anthropic, and MCP schemas. Names match
99
+ the Podstack CLI. `python -m podstack.mcp` serves those tools on stdio.
100
+ `stop_instance` and `start_instance` are listed because the CLI lists them,
101
+ and they report that the platform does not keep a stopped machine.
102
+
103
+ See `examples/` and `AGENTS.md`.
104
+
105
+ ## Version 1.9.0
106
+
107
+ `deploy` registers a function by name, uploads a cloudpickle version, and
108
+ activates it. `invoke` starts `POST /functions/{id}/runs` and unpickles the
109
+ result. See `CHANGELOG.md`.
110
+
111
+ 1.8.0 removed the previous notebook SDK. There are no deprecated shims for
112
+ routes the platform does not serve. The removed modules are listed in
113
+ `docs/audit.md`.
114
+
115
+ Async code uses `AsyncPodstack`. The method names match the sync client.
116
+
117
+ ```python
118
+ import asyncio
119
+ from podstack import AsyncPodstack
120
+
121
+ async def main():
122
+ async with AsyncPodstack() as client:
123
+ print(await client.gpus.list())
124
+
125
+ asyncio.run(main())
126
+ ```
127
+
128
+ ## Development
129
+
130
+ ```bash
131
+ python -m pip install -e ".[dev]"
132
+ python -m ruff check src tests examples
133
+ python -m mypy
134
+ python -m pytest
135
+ python -m build
136
+ twine check dist/*
137
+ ```
138
+
139
+ This directory is the root of the standalone package. The release workflow is
140
+ `.github/workflows/release.yml`. It runs on a `v*` tag and on manual dispatch.
141
+ It does not publish from a pull request. Tag publish uses PyPI Trusted
142
+ Publishing (environment `pypi`, `id-token: write`) and falls back to the
143
+ `PYPI_API_TOKEN` secret when that secret is set. Manual dispatch also uploads
144
+ the built distributions to TestPyPI.
@@ -0,0 +1,110 @@
1
+ # podstack
2
+
3
+ Python SDK for the [Podstack](https://podstack.ai) platform API.
4
+
5
+ ```bash
6
+ pip install podstack
7
+ ```
8
+
9
+ The client talks to `https://podstack.ai/api/v1`. Set `PODSTACK_API_KEY` to a
10
+ `ps_live_` key, or run `podstack auth login` so the CLI credentials file is
11
+ present. The API does not accept a `psk_` key. `api.podstack.ai` does not resolve.
12
+ Public reads such as `client.job_gpus.list()` work with no key.
13
+
14
+ ```python
15
+ from podstack import Podstack
16
+
17
+ with Podstack() as client:
18
+ for gpu in client.gpus.list():
19
+ print(gpu.gpu_type, gpu.vram_gb)
20
+ for rate in client.rates.list():
21
+ print(rate.gpu_type, rate.region, rate.price_per_hour)
22
+ ```
23
+
24
+ `price_per_hour` and every other spec are copied from the API. The SDK does
25
+ not ship a price table or a GPU catalogue.
26
+
27
+ ## Billable calls
28
+
29
+ Create, terminate, submit, cancel, chat, embeddings, image generation, and
30
+ function deploy or invoke require `confirm=True`. `dry_run=True` returns the
31
+ request and does not send it. `dry_run` is checked first.
32
+
33
+ ```python
34
+ preview = client.instances.create(gpu_type=gpu.gpu_type, dry_run=True)
35
+ operation = client.instances.create(gpu_type=gpu.gpu_type, confirm=True)
36
+ ```
37
+
38
+ There is no stop or start that keeps an instance disk. Terminate the instance
39
+ to stop the per-second charge. Commands and file copies use the SSH command
40
+ the API returns and the local `ssh` / `scp` binaries.
41
+
42
+ ## Functions
43
+
44
+ Creating a function is this package. The CLI only lists functions.
45
+
46
+ ```python
47
+ import podstack
48
+
49
+ @podstack.function(gpu="a100_80gb", requirements=["torch"])
50
+ def device_name():
51
+ import torch
52
+ return torch.cuda.get_device_name(0)
53
+
54
+ print(device_name.deploy(dry_run=True))
55
+ print(device_name.invoke(confirm=True))
56
+ ```
57
+
58
+ The function has to live in a file. Arguments must be JSON-serializable.
59
+ Calling it like a normal function raises `ConfirmationRequired` unless the
60
+ decorator was created with `confirm=True`.
61
+
62
+ ## Agents
63
+
64
+ `podstack.tools()` returns OpenAI, Anthropic, and MCP schemas. Names match
65
+ the Podstack CLI. `python -m podstack.mcp` serves those tools on stdio.
66
+ `stop_instance` and `start_instance` are listed because the CLI lists them,
67
+ and they report that the platform does not keep a stopped machine.
68
+
69
+ See `examples/` and `AGENTS.md`.
70
+
71
+ ## Version 1.9.0
72
+
73
+ `deploy` registers a function by name, uploads a cloudpickle version, and
74
+ activates it. `invoke` starts `POST /functions/{id}/runs` and unpickles the
75
+ result. See `CHANGELOG.md`.
76
+
77
+ 1.8.0 removed the previous notebook SDK. There are no deprecated shims for
78
+ routes the platform does not serve. The removed modules are listed in
79
+ `docs/audit.md`.
80
+
81
+ Async code uses `AsyncPodstack`. The method names match the sync client.
82
+
83
+ ```python
84
+ import asyncio
85
+ from podstack import AsyncPodstack
86
+
87
+ async def main():
88
+ async with AsyncPodstack() as client:
89
+ print(await client.gpus.list())
90
+
91
+ asyncio.run(main())
92
+ ```
93
+
94
+ ## Development
95
+
96
+ ```bash
97
+ python -m pip install -e ".[dev]"
98
+ python -m ruff check src tests examples
99
+ python -m mypy
100
+ python -m pytest
101
+ python -m build
102
+ twine check dist/*
103
+ ```
104
+
105
+ This directory is the root of the standalone package. The release workflow is
106
+ `.github/workflows/release.yml`. It runs on a `v*` tag and on manual dispatch.
107
+ It does not publish from a pull request. Tag publish uses PyPI Trusted
108
+ Publishing (environment `pypi`, `id-token: write`) and falls back to the
109
+ `PYPI_API_TOKEN` secret when that secret is set. Manual dispatch also uploads
110
+ the built distributions to TestPyPI.
@@ -0,0 +1,54 @@
1
+ # SDK surface
2
+
3
+ Version 1.8.0 keeps the calls that exist on `https://podstack.ai/api/v1`, plus
4
+ the functions API this package sends. Methods that targeted the old notebook
5
+ service are gone. There is no compatibility wrapper that still accepts the old
6
+ method and then fails.
7
+
8
+ ## Removed
9
+
10
+ | Old surface | Why it is gone |
11
+ | --- | --- |
12
+ | Default host `https://api.podstack.ai/v1` | That host does not resolve. The API is `https://podstack.ai/api/v1`. |
13
+ | `Client`, notebooks, cells, webhooks, registry, pipelines, storage, sandbox, `Image` | Those routes are not on the platform API. |
14
+ | `podstack_gpu` and the old `@app.function` helper | Hardcoded GPU ids, fractions, and prices. The live catalogue comes from `GET /gpu-types`. |
15
+ | `GPUType` memory and price maps | Invented specs. Prices now come only from `GET /pricing` and `GET /jobs/gpu-types`. |
16
+ | `POST /api/v1/deployments/from-source` | Notebook-service deploy. Not the platform functions API. |
17
+ | Dataset and `POST /files` upload | The platform has no dataset upload. Fine-tuning takes an existing file id. |
18
+ | Instance stop and start | Terminating an instance deletes it. The disk is not kept. |
19
+ | `/gpus`, `/billing/wallet` | Replaced by `/gpu-types`, `/pricing`, and `/wallet`. |
20
+
21
+ ## Kept
22
+
23
+ | Area | Methods | Notes |
24
+ | --- | --- | --- |
25
+ | GPUs | `gpus.list` | `GET /gpu-types`. Public. |
26
+ | Rates | `rates.list` | `GET /pricing`. `price_per_hour` is passed through. |
27
+ | Job GPUs | `job_gpus.list` | `GET /jobs/gpu-types`. Public. |
28
+ | Templates and environments | `templates.list`, `environments.get` | Public. |
29
+ | Projects | `projects.list`, `projects.create` | Same API base. |
30
+ | SSH keys | `ssh_keys.list`, `create`, `delete` | Delete requires `confirm=True`. |
31
+ | Instances | `list`, `get`, `create`, `terminate`, `ssh_command`, `exec`, `upload`, `download` | Create and terminate are billable. `get` falls back to the list on 404. Exec and copy use local OpenSSH. |
32
+ | Operations | `operations.get` | `GET /operations/{id}`. |
33
+ | Jobs | `list`, `submit`, `cancel`, `logs` | Submit and cancel require `confirm=True`. |
34
+ | Endpoints | `list`, `create`, `delete` | Create and delete require `confirm=True`. |
35
+ | Functions | decorator, `deploy`, `invoke`, `list`, `get`, `logs`, `delete`, `call` | See `docs/functions.md`. |
36
+ | Models | `models.list`, `models.get` | Model ids are one path segment. |
37
+ | Chat | `chat.completions`, `chat.stream` | `POST /chat/completions`. Billable. |
38
+ | Embeddings | `embeddings.create` | `POST /embeddings`. Billable. |
39
+ | Images | `images.generate` | `POST /images/generations`. Billable. |
40
+ | Wallet | `wallet.balance`, `wallet.transactions` | 404 raises `NotAvailableYet`. `credit_cents / 100` only when `balance` is absent. Debits are negative. |
41
+ | Secrets | `list`, `create`, `delete` | Values are write-only. Delete requires `confirm=True`. |
42
+ | Fine-tuning | `list`, `get`, `create`, `cancel`, `events` | Create does not upload a dataset. |
43
+ | Identity | `me` | `GET /me`. |
44
+
45
+ `AsyncPodstack` has the same methods.
46
+
47
+ ## Not on the API yet
48
+
49
+ These are explicit errors, not silent success:
50
+
51
+ - `functions.logs` when `GET /functions/{id}/logs` returns 404 or 405.
52
+ - `functions.call` reads `GET /functions/{id}/runs/{run_id}`. A 404 is `NotFoundError` (the run is missing).
53
+ - `wallet.balance` and `wallet.transactions` when those routes return 404.
54
+ - MCP `stop_instance` and `start_instance`. They do not send HTTP.
@@ -0,0 +1,117 @@
1
+ # Functions API
2
+
3
+ The CLI lists functions with `GET /functions`. This package creates one,
4
+ uploads a cloudpickle version, and activates it. The first confirmed
5
+ `invoke` deploys when the function has not been deployed yet, then starts a
6
+ run.
7
+
8
+ `gpu` is an id from `GET /gpu-types` or `GET /jobs/gpu-types`. Job runs use a
9
+ job GPU type such as `a100_80gb` or `l40s`. The SDK does not check the id
10
+ against a built-in list. `image` may be empty. `requirements` is a list of
11
+ pip specifiers, or the decorator accepts a path to `requirements.txt`.
12
+
13
+ The name starts with a letter and uses letters, numbers, hyphens, and
14
+ underscores, at most 51 characters. The function must be a top-level function
15
+ in a file. Arguments must be JSON.
16
+
17
+ ## Deploy
18
+
19
+ Deploy is three calls. A second deploy repeats them, so a code change is
20
+ shipped. An identical bundle can come back without an upload URL; the SDK
21
+ still activates that version.
22
+
23
+ `POST /functions`
24
+
25
+ ```json
26
+ {"name": "device_name"}
27
+ ```
28
+
29
+ `POST /functions/{id}/versions`
30
+
31
+ ```json
32
+ {
33
+ "gpu": "a100_80gb",
34
+ "pip": ["torch"],
35
+ "image": "custom:latest",
36
+ "python_version": "3.11",
37
+ "cloudpickle_version": "3.1.1",
38
+ "timeout": 3600,
39
+ "bundle_bytes": 120,
40
+ "bundle_sha256": "...",
41
+ "content_hash": "...",
42
+ "gpu_count": 1,
43
+ "min_vram_gb": 0,
44
+ "regions": [],
45
+ "idle_timeout": 300,
46
+ "max_concurrency": 1
47
+ }
48
+ ```
49
+
50
+ `pip` is the requirements list. `image` is sent only when it is non-empty.
51
+ `content_hash` is the SHA-256 of that JSON with the keys sorted, computed
52
+ before `content_hash` itself is added.
53
+
54
+ When the response includes `upload.url`, the SDK `PUT`s the raw cloudpickle
55
+ bytes to that URL with `Content-Type: application/octet-stream` and no API
56
+ key. It then confirms the version:
57
+
58
+ `POST /functions/{id}/versions/{version_id}/activate`
59
+
60
+ ```json
61
+ {}
62
+ ```
63
+
64
+ `deploy(dry_run=True)` returns a `DryRun` for the version route and does not
65
+ pickle, build a client, or send HTTP.
66
+
67
+ ## Invoke
68
+
69
+ `POST /functions/{id}/runs`
70
+
71
+ ```json
72
+ {"input": "<base64 cloudpickle of (args, kwargs)>", "version_id": "ver_..."}
73
+ ```
74
+
75
+ `version_id` is omitted until a deploy has stored one. `args` and `kwargs`
76
+ must be JSON. The call body is a pickle, limited to 4 MB before base64.
77
+
78
+ `wait=true` (the default) polls `GET /functions/{id}/runs/{run_id}?wait=25&include_result=true`
79
+ until `status` is `succeeded`, `failed`, `timed_out`, or `cancelled`, or the
80
+ function timeout elapses. `wait=false` returns the accepted run. Poll later
81
+ with `functions.call`, which reads the same run route. A 404 on that route is
82
+ `NotFoundError`.
83
+
84
+ The result object is `{result, status, call_id, error}`. `call_id` is the run
85
+ id. A base64 cloudpickle `result` is unpickled. A JSON value is left as-is.
86
+ `error` may be a string or `{"message", "type", "traceback"}`; the message is
87
+ kept.
88
+
89
+ Name or id both work in the path. After deploy, the decorator uses the id.
90
+
91
+ ## Logs, get, and delete
92
+
93
+ `GET /functions/{id}` reads one function. `GET /functions/{id}/logs` returns
94
+ logs as text. A 404 or 405 raises `NotAvailableYet`. `DELETE /functions/{id}`
95
+ removes the function and requires `confirm=True`. Pass the name or the id.
96
+
97
+ ## Decorator
98
+
99
+ ```python
100
+ import podstack
101
+
102
+ @podstack.function(gpu="a100_80gb", requirements=["torch"])
103
+ def device_name():
104
+ import torch
105
+ return torch.cuda.get_device_name(0)
106
+
107
+ device_name.local() # this process, not billed
108
+ device_name.deploy(dry_run=True) # preview, not sent
109
+ device_name.deploy(confirm=True) # create, upload, activate
110
+ device_name.invoke(confirm=True) # deploy if needed, then run
111
+ device_name.get()
112
+ device_name.logs()
113
+ await device_name.ainvoke(confirm=True)
114
+ ```
115
+
116
+ `device_name()` raises `ConfirmationRequired` unless the decorator was built
117
+ with `confirm=True`.
@@ -0,0 +1,26 @@
1
+ """List GPUs, live rates, and models.
2
+
3
+ Run:
4
+ PODSTACK_API_KEY=ps_live_... python examples/01_quickstart.py
5
+
6
+ Nothing in this example is billed.
7
+ """
8
+
9
+ from podstack import Podstack
10
+
11
+
12
+ def main() -> None:
13
+ with Podstack() as client:
14
+ print("GPU types")
15
+ for gpu in client.gpus.list():
16
+ print(f" {gpu.gpu_type}\tvram_gb={gpu.vram_gb}")
17
+ print("Rates (price_per_hour is the API value)")
18
+ for rate in client.rates.list():
19
+ print(f" {rate.gpu_type}\t{rate.region}\t{rate.price_per_hour}")
20
+ print("Models")
21
+ for model in client.models.list():
22
+ print(f" {model.id}\t{model.modality}")
23
+
24
+
25
+ if __name__ == "__main__":
26
+ main()
@@ -0,0 +1,42 @@
1
+ """Deploy and invoke a GPU function.
2
+
3
+ The decorator registers the function, uploads a cloudpickle version, and
4
+ activates it. The first invoke deploys, then starts POST /functions/{id}/runs.
5
+
6
+ PODSTACK_API_KEY=ps_live_... python examples/02_functions.py
7
+ PODSTACK_API_KEY=ps_live_... PODSTACK_CONFIRM=1 python examples/02_functions.py
8
+
9
+ PODSTACK_CONFIRM=1 sends confirm=True. Without it, the script prints a dry run.
10
+ Pick PODSTACK_GPU from client.job_gpus.list(). The default below is only a placeholder.
11
+ """
12
+
13
+ import asyncio
14
+ import os
15
+
16
+ import podstack
17
+
18
+ GPU = os.environ.get("PODSTACK_GPU", "a100_80gb")
19
+ SEND = os.environ.get("PODSTACK_CONFIRM") == "1"
20
+
21
+
22
+ @podstack.function(gpu=GPU, requirements=["torch"])
23
+ def device_name() -> str:
24
+ import torch
25
+
26
+ return str(torch.cuda.get_device_name(0))
27
+
28
+
29
+ def main() -> None:
30
+ print("local source:\n", device_name.source())
31
+ if not SEND:
32
+ print("dry run. Set PODSTACK_CONFIRM=1 to send confirm=True.")
33
+ print(device_name.deploy(dry_run=True).to_dict())
34
+ print(device_name.invoke(dry_run=True).to_dict())
35
+ return
36
+ print(device_name.deploy(confirm=True))
37
+ print(device_name.invoke(confirm=True))
38
+ print(asyncio.run(device_name.ainvoke(confirm=True)))
39
+
40
+
41
+ if __name__ == "__main__":
42
+ main()
@@ -0,0 +1,52 @@
1
+ """Create a GPU instance, run a command over SSH, then terminate it.
2
+
3
+ Instances are billed per second until terminate. There is no stop that keeps
4
+ the disk. exec uses the ssh command the API returns and the local ssh binary.
5
+
6
+ PODSTACK_API_KEY=ps_live_... python examples/03_instances.py
7
+ PODSTACK_API_KEY=ps_live_... PODSTACK_CONFIRM=1 python examples/03_instances.py
8
+ """
9
+
10
+ import os
11
+ import time
12
+
13
+ from podstack import NotAvailableYet, Podstack
14
+
15
+
16
+ def main() -> None:
17
+ send = os.environ.get("PODSTACK_CONFIRM") == "1"
18
+ with Podstack() as client:
19
+ gpus = client.gpus.list()
20
+ if not gpus:
21
+ raise SystemExit("GET /gpu-types returned no rows.")
22
+ gpu_type = os.environ.get("PODSTACK_GPU") or gpus[0].gpu_type
23
+ chosen = next((row for row in gpus if row.gpu_type == gpu_type), None)
24
+ if chosen is not None:
25
+ print(f"gpu_type={chosen.gpu_type} vram_gb={chosen.vram_gb}")
26
+ if not send:
27
+ print("dry run. Set PODSTACK_CONFIRM=1 to send confirm=True.")
28
+ print(client.instances.create(gpu_type=gpu_type, name="sdk-example", dry_run=True).to_dict())
29
+ print(client.instances.terminate("example-instance", dry_run=True).to_dict())
30
+ return
31
+ operation = client.instances.create(gpu_type=gpu_type, name="sdk-example", confirm=True)
32
+ instance_id = operation.resource_id or (operation.instance.id if operation.instance else "")
33
+ print(operation)
34
+ if not instance_id:
35
+ raise SystemExit("Create did not return an instance id. Nothing was terminated.")
36
+ instance = client.instances.get(instance_id)
37
+ for _ in range(5):
38
+ if instance.ssh_command:
39
+ break
40
+ time.sleep(2)
41
+ instance = client.instances.get(instance_id)
42
+ print(instance.status, instance.ssh_command)
43
+ try:
44
+ result = client.instances.exec(instance_id, "nvidia-smi")
45
+ print(result.stdout)
46
+ except NotAvailableYet as exc:
47
+ print(exc)
48
+ print(client.instances.terminate(instance_id, confirm=True))
49
+
50
+
51
+ if __name__ == "__main__":
52
+ main()
@@ -0,0 +1,39 @@
1
+ """Submit a GPU job, read logs, and cancel it.
2
+
3
+ You are billed only while the job runs. image and timeout use the console
4
+ form defaults when you omit them (pytorch/pytorch:latest and 3600 seconds).
5
+
6
+ PODSTACK_API_KEY=ps_live_... python examples/04_jobs.py
7
+ PODSTACK_API_KEY=ps_live_... PODSTACK_CONFIRM=1 python examples/04_jobs.py
8
+ """
9
+
10
+ import os
11
+
12
+ from podstack import Podstack
13
+
14
+
15
+ def main() -> None:
16
+ send = os.environ.get("PODSTACK_CONFIRM") == "1"
17
+ with Podstack() as client:
18
+ options = client.job_gpus.list()
19
+ gpu_type = os.environ.get("PODSTACK_GPU") or (options[0].gpu_type if options else "")
20
+ if not gpu_type:
21
+ raise SystemExit("GET /jobs/gpu-types returned no rows. Set PODSTACK_GPU.")
22
+ for row in options:
23
+ if row.gpu_type == gpu_type:
24
+ print(f"gpu_type={row.gpu_type} price_per_gpu_hour={row.price_per_gpu_hour}")
25
+ script = "print('hello from podstack')"
26
+ if not send:
27
+ print("dry run. Set PODSTACK_CONFIRM=1 to send confirm=True.")
28
+ print(client.jobs.submit(name="sdk-example", gpu_type=gpu_type, script=script, dry_run=True).to_dict())
29
+ print(client.jobs.cancel("example-job", dry_run=True).to_dict())
30
+ return
31
+ job = client.jobs.submit(name="sdk-example", gpu_type=gpu_type, script=script, confirm=True)
32
+ print(job.id, job.status)
33
+ if job.id:
34
+ print(client.jobs.logs(job.id))
35
+ print(client.jobs.cancel(job.id, confirm=True))
36
+
37
+
38
+ if __name__ == "__main__":
39
+ main()