podstack 1.7.0__tar.gz → 1.8.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 (88) hide show
  1. podstack-1.8.0/AGENTS.md +68 -0
  2. podstack-1.8.0/MANIFEST.in +10 -0
  3. podstack-1.8.0/PKG-INFO +138 -0
  4. podstack-1.8.0/README.md +105 -0
  5. podstack-1.8.0/docs/audit.md +54 -0
  6. podstack-1.8.0/docs/functions.md +65 -0
  7. podstack-1.8.0/examples/01_quickstart.py +26 -0
  8. podstack-1.8.0/examples/02_functions.py +42 -0
  9. podstack-1.8.0/examples/03_instances.py +52 -0
  10. podstack-1.8.0/examples/04_jobs.py +39 -0
  11. podstack-1.8.0/examples/05_endpoints.py +53 -0
  12. podstack-1.8.0/examples/06_inference.py +50 -0
  13. podstack-1.8.0/examples/07_balance.py +34 -0
  14. podstack-1.8.0/examples/08_tools.py +39 -0
  15. podstack-1.8.0/examples/09_mcp.py +45 -0
  16. podstack-1.8.0/examples/README.md +18 -0
  17. podstack-1.8.0/llms.txt +25 -0
  18. podstack-1.8.0/pyproject.toml +84 -0
  19. podstack-1.8.0/skills/podstack/SKILL.md +37 -0
  20. podstack-1.8.0/src/podstack/__init__.py +52 -0
  21. podstack-1.8.0/src/podstack/_version.py +3 -0
  22. podstack-1.8.0/src/podstack/async_client.py +907 -0
  23. podstack-1.8.0/src/podstack/client.py +1134 -0
  24. podstack-1.8.0/src/podstack/config.py +82 -0
  25. podstack-1.8.0/src/podstack/exceptions.py +156 -0
  26. podstack-1.8.0/src/podstack/functions.py +305 -0
  27. podstack-1.8.0/src/podstack/mcp.py +191 -0
  28. podstack-1.8.0/src/podstack/models.py +745 -0
  29. podstack-1.8.0/src/podstack/py.typed +0 -0
  30. podstack-1.8.0/src/podstack/ssh.py +137 -0
  31. podstack-1.8.0/src/podstack/tools.py +414 -0
  32. podstack-1.8.0/src/podstack/transport.py +294 -0
  33. podstack-1.8.0/src/podstack.egg-info/SOURCES.txt +38 -0
  34. podstack-1.8.0/tests/conftest.py +38 -0
  35. podstack-1.8.0/tests/test_client.py +272 -0
  36. podstack-1.8.0/tests/test_config_and_errors.py +77 -0
  37. podstack-1.8.0/tests/test_functions.py +132 -0
  38. podstack-1.8.0/tests/test_ssh_async.py +46 -0
  39. podstack-1.8.0/tests/test_tools_mcp.py +109 -0
  40. podstack-1.7.0/PKG-INFO +0 -919
  41. podstack-1.7.0/README.md +0 -867
  42. podstack-1.7.0/podstack/__init__.py +0 -375
  43. podstack-1.7.0/podstack/agent/__init__.py +0 -105
  44. podstack-1.7.0/podstack/agent/client.py +0 -308
  45. podstack-1.7.0/podstack/agent/exceptions.py +0 -56
  46. podstack-1.7.0/podstack/agent/models.py +0 -279
  47. podstack-1.7.0/podstack/agent/spec.py +0 -160
  48. podstack-1.7.0/podstack/annotations.py +0 -996
  49. podstack-1.7.0/podstack/cell.py +0 -860
  50. podstack-1.7.0/podstack/client.py +0 -322
  51. podstack-1.7.0/podstack/exceptions.py +0 -125
  52. podstack-1.7.0/podstack/execution.py +0 -291
  53. podstack-1.7.0/podstack/gpu_runner.py +0 -1662
  54. podstack-1.7.0/podstack/image.py +0 -515
  55. podstack-1.7.0/podstack/models.py +0 -274
  56. podstack-1.7.0/podstack/notebook.py +0 -410
  57. podstack-1.7.0/podstack/pipelines.py +0 -269
  58. podstack-1.7.0/podstack/registry/__init__.py +0 -701
  59. podstack-1.7.0/podstack/registry/autolog.py +0 -196
  60. podstack-1.7.0/podstack/registry/client.py +0 -1693
  61. podstack-1.7.0/podstack/registry/exceptions.py +0 -107
  62. podstack-1.7.0/podstack/registry/experiment.py +0 -420
  63. podstack-1.7.0/podstack/registry/model.py +0 -273
  64. podstack-1.7.0/podstack/registry/model_utils.py +0 -231
  65. podstack-1.7.0/podstack/runners.py +0 -312
  66. podstack-1.7.0/podstack/sandbox.py +0 -474
  67. podstack-1.7.0/podstack/serialization.py +0 -359
  68. podstack-1.7.0/podstack/session.py +0 -117
  69. podstack-1.7.0/podstack/storage.py +0 -291
  70. podstack-1.7.0/podstack.egg-info/PKG-INFO +0 -919
  71. podstack-1.7.0/podstack.egg-info/SOURCES.txt +0 -47
  72. podstack-1.7.0/podstack.egg-info/dependency_links.txt +0 -1
  73. podstack-1.7.0/podstack.egg-info/requires.txt +0 -30
  74. podstack-1.7.0/podstack.egg-info/top_level.txt +0 -2
  75. podstack-1.7.0/podstack_gpu/__init__.py +0 -126
  76. podstack-1.7.0/podstack_gpu/app.py +0 -675
  77. podstack-1.7.0/podstack_gpu/exceptions.py +0 -35
  78. podstack-1.7.0/podstack_gpu/image.py +0 -325
  79. podstack-1.7.0/podstack_gpu/runner.py +0 -746
  80. podstack-1.7.0/podstack_gpu/secret.py +0 -189
  81. podstack-1.7.0/podstack_gpu/utils.py +0 -203
  82. podstack-1.7.0/podstack_gpu/volume.py +0 -198
  83. podstack-1.7.0/pyproject.toml +0 -82
  84. podstack-1.7.0/tests/test_cell_serialization.py +0 -207
  85. podstack-1.7.0/tests/test_image_builder.py +0 -208
  86. podstack-1.7.0/tests/test_runners_catalog.py +0 -250
  87. {podstack-1.7.0 → podstack-1.8.0}/LICENSE +0 -0
  88. {podstack-1.7.0 → podstack-1.8.0}/setup.cfg +0 -0
@@ -0,0 +1,68 @@
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
+ Keys may start with `ps_live_` or the legacy `psk_` prefix. 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, async function-call polling, and wallet when the route is 404.
40
+
41
+ There is no instance stop or start, no instance exec HTTP API, and no dataset
42
+ upload. `exec`, `upload`, and `download` shell out to OpenSSH using the SSH
43
+ command on the instance. Fine-tuning takes an existing `training_file` id.
44
+
45
+ ## Functions
46
+
47
+ Create functions with `@podstack.function`, not with the CLI and not with an
48
+ HTTP-only helper that uploads a notebook. The contract is `docs/functions.md`.
49
+ The function must be a top-level function in a file. Arguments must be JSON.
50
+
51
+ ## Tools and MCP
52
+
53
+ `podstack.tools()` returns `openai`, `anthropic`, and `mcp` schemas. Use the
54
+ names as they are. `list_functions` does not create a function. `stop_instance`
55
+ and `start_instance` return not-available and must not be replaced with a
56
+ guessed HTTP call.
57
+
58
+ Serve the same tools with `python -m podstack.mcp` or `podstack-mcp`.
59
+
60
+ ## Errors
61
+
62
+ Catch `podstack.PodstackError`. Useful subclasses: `AuthenticationError`,
63
+ `PermissionDenied`, `NotFoundError`, `ValidationError`, `RateLimitError`,
64
+ `InsufficientBalance`, `GPUNotAvailableError`, `NotAvailableYet`,
65
+ `ConfirmationRequired`, `CommandFailed`.
66
+
67
+ Retries cover connection errors and HTTP 429 and 5xx. Other status codes are
68
+ 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,138 @@
1
+ Metadata-Version: 2.4
2
+ Name: podstack
3
+ Version: 1.8.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: httpx>=0.24
25
+ Provides-Extra: dev
26
+ Requires-Dist: build>=1.2; extra == "dev"
27
+ Requires-Dist: mypy<2,>=1.8; extra == "dev"
28
+ Requires-Dist: pytest>=7; extra == "dev"
29
+ Requires-Dist: pytest-asyncio>=0.21; extra == "dev"
30
+ Requires-Dist: ruff>=0.4; extra == "dev"
31
+ Requires-Dist: twine>=5; extra == "dev"
32
+ Dynamic: license-file
33
+
34
+ # podstack
35
+
36
+ Python SDK for the [Podstack](https://podstack.ai) platform API.
37
+
38
+ ```bash
39
+ pip install podstack
40
+ ```
41
+
42
+ The client talks to `https://podstack.ai/api/v1`. Set `PODSTACK_API_KEY` to a
43
+ `ps_live_` key (a legacy `psk_` key is also accepted), or run `podstack auth login`
44
+ so the CLI credentials file is present. `api.podstack.ai` does not resolve.
45
+
46
+ ```python
47
+ from podstack import Podstack
48
+
49
+ with Podstack() as client:
50
+ for gpu in client.gpus.list():
51
+ print(gpu.gpu_type, gpu.vram_gb)
52
+ for rate in client.rates.list():
53
+ print(rate.gpu_type, rate.region, rate.price_per_hour)
54
+ ```
55
+
56
+ `price_per_hour` and every other spec are copied from the API. The SDK does
57
+ not ship a price table or a GPU catalogue.
58
+
59
+ ## Billable calls
60
+
61
+ Create, terminate, submit, cancel, chat, embeddings, image generation, and
62
+ function deploy or invoke require `confirm=True`. `dry_run=True` returns the
63
+ request and does not send it. `dry_run` is checked first.
64
+
65
+ ```python
66
+ preview = client.instances.create(gpu_type=gpu.gpu_type, dry_run=True)
67
+ operation = client.instances.create(gpu_type=gpu.gpu_type, confirm=True)
68
+ ```
69
+
70
+ There is no stop or start that keeps an instance disk. Terminate the instance
71
+ to stop the per-second charge. Commands and file copies use the SSH command
72
+ the API returns and the local `ssh` / `scp` binaries.
73
+
74
+ ## Functions
75
+
76
+ Creating a function is this package. The CLI only lists functions.
77
+
78
+ ```python
79
+ import podstack
80
+
81
+ @podstack.function(gpu="h100_sxm", requirements=["torch"])
82
+ def device_name():
83
+ import torch
84
+ return torch.cuda.get_device_name(0)
85
+
86
+ print(device_name.deploy(dry_run=True))
87
+ print(device_name.invoke(confirm=True))
88
+ ```
89
+
90
+ The function has to live in a file. Arguments must be JSON-serializable.
91
+ Calling it like a normal function raises `ConfirmationRequired` unless the
92
+ decorator was created with `confirm=True`.
93
+
94
+ ## Agents
95
+
96
+ `podstack.tools()` returns OpenAI, Anthropic, and MCP schemas. Names match
97
+ the Podstack CLI. `python -m podstack.mcp` serves those tools on stdio.
98
+ `stop_instance` and `start_instance` are listed because the CLI lists them,
99
+ and they report that the platform does not keep a stopped machine.
100
+
101
+ See `examples/` and `AGENTS.md`.
102
+
103
+ ## Version 1.8.0
104
+
105
+ PyPI already published `podstack` 1.7.0, which was the previous notebook SDK.
106
+ 1.8.0 removes that surface. There are no deprecated shims for routes the
107
+ platform does not serve. The removed modules are listed in `docs/audit.md`.
108
+
109
+ Async code uses `AsyncPodstack`. The method names match the sync client.
110
+
111
+ ```python
112
+ import asyncio
113
+ from podstack import AsyncPodstack
114
+
115
+ async def main():
116
+ async with AsyncPodstack() as client:
117
+ print(await client.gpus.list())
118
+
119
+ asyncio.run(main())
120
+ ```
121
+
122
+ ## Development
123
+
124
+ ```bash
125
+ python -m pip install -e ".[dev]"
126
+ python -m ruff check src tests examples
127
+ python -m mypy
128
+ python -m pytest
129
+ python -m build
130
+ twine check dist/*
131
+ ```
132
+
133
+ This directory is the root of the standalone package. The release workflow is
134
+ `.github/workflows/release.yml`. It runs on a `v*` tag and on manual dispatch.
135
+ It does not publish from a pull request. Tag publish uses PyPI Trusted
136
+ Publishing (environment `pypi`, `id-token: write`) and falls back to the
137
+ `PYPI_API_TOKEN` secret when that secret is set. Manual dispatch also uploads
138
+ the built distributions to TestPyPI.
@@ -0,0 +1,105 @@
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 (a legacy `psk_` key is also accepted), or run `podstack auth login`
11
+ so the CLI credentials file is present. `api.podstack.ai` does not resolve.
12
+
13
+ ```python
14
+ from podstack import Podstack
15
+
16
+ with Podstack() as client:
17
+ for gpu in client.gpus.list():
18
+ print(gpu.gpu_type, gpu.vram_gb)
19
+ for rate in client.rates.list():
20
+ print(rate.gpu_type, rate.region, rate.price_per_hour)
21
+ ```
22
+
23
+ `price_per_hour` and every other spec are copied from the API. The SDK does
24
+ not ship a price table or a GPU catalogue.
25
+
26
+ ## Billable calls
27
+
28
+ Create, terminate, submit, cancel, chat, embeddings, image generation, and
29
+ function deploy or invoke require `confirm=True`. `dry_run=True` returns the
30
+ request and does not send it. `dry_run` is checked first.
31
+
32
+ ```python
33
+ preview = client.instances.create(gpu_type=gpu.gpu_type, dry_run=True)
34
+ operation = client.instances.create(gpu_type=gpu.gpu_type, confirm=True)
35
+ ```
36
+
37
+ There is no stop or start that keeps an instance disk. Terminate the instance
38
+ to stop the per-second charge. Commands and file copies use the SSH command
39
+ the API returns and the local `ssh` / `scp` binaries.
40
+
41
+ ## Functions
42
+
43
+ Creating a function is this package. The CLI only lists functions.
44
+
45
+ ```python
46
+ import podstack
47
+
48
+ @podstack.function(gpu="h100_sxm", requirements=["torch"])
49
+ def device_name():
50
+ import torch
51
+ return torch.cuda.get_device_name(0)
52
+
53
+ print(device_name.deploy(dry_run=True))
54
+ print(device_name.invoke(confirm=True))
55
+ ```
56
+
57
+ The function has to live in a file. Arguments must be JSON-serializable.
58
+ Calling it like a normal function raises `ConfirmationRequired` unless the
59
+ decorator was created with `confirm=True`.
60
+
61
+ ## Agents
62
+
63
+ `podstack.tools()` returns OpenAI, Anthropic, and MCP schemas. Names match
64
+ the Podstack CLI. `python -m podstack.mcp` serves those tools on stdio.
65
+ `stop_instance` and `start_instance` are listed because the CLI lists them,
66
+ and they report that the platform does not keep a stopped machine.
67
+
68
+ See `examples/` and `AGENTS.md`.
69
+
70
+ ## Version 1.8.0
71
+
72
+ PyPI already published `podstack` 1.7.0, which was the previous notebook SDK.
73
+ 1.8.0 removes that surface. There are no deprecated shims for routes the
74
+ platform does not serve. The removed modules are listed in `docs/audit.md`.
75
+
76
+ Async code uses `AsyncPodstack`. The method names match the sync client.
77
+
78
+ ```python
79
+ import asyncio
80
+ from podstack import AsyncPodstack
81
+
82
+ async def main():
83
+ async with AsyncPodstack() as client:
84
+ print(await client.gpus.list())
85
+
86
+ asyncio.run(main())
87
+ ```
88
+
89
+ ## Development
90
+
91
+ ```bash
92
+ python -m pip install -e ".[dev]"
93
+ python -m ruff check src tests examples
94
+ python -m mypy
95
+ python -m pytest
96
+ python -m build
97
+ twine check dist/*
98
+ ```
99
+
100
+ This directory is the root of the standalone package. The release workflow is
101
+ `.github/workflows/release.yml`. It runs on a `v*` tag and on manual dispatch.
102
+ It does not publish from a pull request. Tag publish uses PyPI Trusted
103
+ Publishing (environment `pypi`, `id-token: write`) and falls back to the
104
+ `PYPI_API_TOKEN` secret when that secret is set. Manual dispatch also uploads
105
+ 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` when `GET /functions/{name}/calls/{call_id}` returns 404.
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,65 @@
1
+ # Functions API
2
+
3
+ The CLI lists functions with `GET /functions`. This package is how a function
4
+ is created. The first confirmed `invoke` deploys, then calls the function.
5
+
6
+ ## Deploy
7
+
8
+ `POST /functions`
9
+
10
+ ```json
11
+ {
12
+ "name": "device_name",
13
+ "gpu": "h100_sxm",
14
+ "image": "",
15
+ "requirements": ["torch"],
16
+ "source": "def device_name():\n ...\n",
17
+ "entrypoint": "device_name",
18
+ "timeout_seconds": 3600
19
+ }
20
+ ```
21
+
22
+ `gpu` is an id from `GET /gpu-types` or `GET /jobs/gpu-types`. The SDK does not
23
+ check it against a built-in list. `image` may be empty. `requirements` is a
24
+ list of pip specifiers, or the decorator accepts a path to `requirements.txt`.
25
+
26
+ The name starts with a letter and uses letters, numbers, hyphens, and
27
+ underscores, at most 51 characters. The function must be defined in a file so
28
+ `inspect.getsource` can read it. Decorator lines are removed before upload.
29
+
30
+ ## Invoke
31
+
32
+ `POST /functions/{name}/invoke`
33
+
34
+ ```json
35
+ {"args": [], "kwargs": {}, "wait": true}
36
+ ```
37
+
38
+ `args` and `kwargs` must be JSON. `wait=false` returns after the API accepts
39
+ the call. When the response includes `call_id`, poll
40
+ `GET /functions/{name}/calls/{call_id}`. A 404 on that poll raises
41
+ `NotAvailableYet` for async function calls.
42
+
43
+ ## Logs and delete
44
+
45
+ `GET /functions/{id}/logs` returns logs. A 404 or 405 raises `NotAvailableYet`.
46
+ `DELETE /functions/{id}` removes the function and requires `confirm=True`.
47
+
48
+ ## Decorator
49
+
50
+ ```python
51
+ import podstack
52
+
53
+ @podstack.function(gpu="h100_sxm", requirements=["torch"])
54
+ def device_name():
55
+ import torch
56
+ return torch.cuda.get_device_name(0)
57
+
58
+ device_name.local() # this process, not billed
59
+ device_name.deploy(dry_run=True) # preview, not sent
60
+ device_name.invoke(confirm=True) # deploy if needed, then invoke
61
+ await device_name.ainvoke(confirm=True)
62
+ ```
63
+
64
+ `device_name()` raises `ConfirmationRequired` unless the decorator was built
65
+ 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 packages this function and posts it to POST /functions.
4
+ The first invoke deploys, then calls POST /functions/{name}/invoke.
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.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", "h100_sxm")
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()
@@ -0,0 +1,53 @@
1
+ """Create and delete a dedicated inference endpoint.
2
+
3
+ Replicas are billed while they exist. min_replicas=0 scales to zero.
4
+ The name must start with a letter and use lowercase letters, numbers, and hyphens.
5
+
6
+ PODSTACK_API_KEY=ps_live_... python examples/05_endpoints.py
7
+ PODSTACK_API_KEY=ps_live_... PODSTACK_CONFIRM=1 python examples/05_endpoints.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
+ gpus = client.gpus.list()
19
+ models = client.models.list()
20
+ gpu_type = os.environ.get("PODSTACK_GPU") or (gpus[0].gpu_type if gpus else "")
21
+ model = os.environ.get("PODSTACK_MODEL") or (models[0].id if models else "")
22
+ if not gpu_type or not model:
23
+ raise SystemExit("Need a GPU type and a model id from the API, or PODSTACK_GPU and PODSTACK_MODEL.")
24
+ name = os.environ.get("PODSTACK_ENDPOINT_NAME", "sdk-example")
25
+ if not send:
26
+ print("dry run. Set PODSTACK_CONFIRM=1 to send confirm=True.")
27
+ print(
28
+ client.endpoints.create(
29
+ name=name,
30
+ model=model,
31
+ gpu_type=gpu_type,
32
+ min_replicas=0,
33
+ max_replicas=1,
34
+ dry_run=True,
35
+ ).to_dict()
36
+ )
37
+ print(client.endpoints.delete(name, dry_run=True).to_dict())
38
+ return
39
+ endpoint = client.endpoints.create(
40
+ name=name,
41
+ model=model,
42
+ gpu_type=gpu_type,
43
+ min_replicas=0,
44
+ max_replicas=1,
45
+ confirm=True,
46
+ )
47
+ print(endpoint.id, endpoint.url, endpoint.status)
48
+ client.endpoints.delete(endpoint.id or name, confirm=True)
49
+ print("deleted", endpoint.id or name)
50
+
51
+
52
+ if __name__ == "__main__":
53
+ main()