mpaka-sdk 0.1.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.
- mpaka_sdk-0.1.0/.gitignore +14 -0
- mpaka_sdk-0.1.0/CONTRACT.md +60 -0
- mpaka_sdk-0.1.0/LICENSE +21 -0
- mpaka_sdk-0.1.0/PKG-INFO +216 -0
- mpaka_sdk-0.1.0/README.md +198 -0
- mpaka_sdk-0.1.0/pyproject.toml +33 -0
- mpaka_sdk-0.1.0/src/mpaka/__init__.py +46 -0
- mpaka_sdk-0.1.0/src/mpaka/client.py +423 -0
- mpaka_sdk-0.1.0/src/mpaka/errors.py +48 -0
- mpaka_sdk-0.1.0/src/mpaka/models.py +206 -0
- mpaka_sdk-0.1.0/tests/test_client.py +411 -0
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# mPaka API contract used by the SDKs
|
|
2
|
+
|
|
3
|
+
## Source revisions
|
|
4
|
+
|
|
5
|
+
| Source | Revision | Evidence |
|
|
6
|
+
| --- | --- | --- |
|
|
7
|
+
| RustBox API and domain | `130004a7d5e073ea966bb1e8fc99f26da802c6a9` | `crates/api/openapi.json`, route handlers in `crates/api/src/lib.rs`, API HTTP tests, domain status model |
|
|
8
|
+
| Official CLI | `a907c5411d6409df1e898be806d68d14bc4aa314` | Local checkout `/home/apardo/Projects/mpaka-cli`; request construction, polling, environment examples, OpenAPI snapshot |
|
|
9
|
+
| Official MCP server | `8c361d582016bc301468c6cd5cd8630adcf210a7` | Local checkout `/home/apardo/Projects/mpaka-mcp`; authenticated API client, wait logic, Node environment reuse tests |
|
|
10
|
+
|
|
11
|
+
RustBox OpenAPI snapshot SHA-256: `6a7b7bf9f6ba34934f9ffb4de206c7d6304cb64abbe00fdbeccec8c5441d1954`.
|
|
12
|
+
|
|
13
|
+
The SDKs default to `https://api.mpaka.dev`, allow an explicit base URL, and authenticate workload routes with `Authorization: Bearer <API key>`. They accept HTTPS URLs and loopback HTTP URLs for tests. The API key is supplied as a constructor argument; documentation shows loading it from `MPAKA_API_KEY`.
|
|
14
|
+
|
|
15
|
+
## Routes used
|
|
16
|
+
|
|
17
|
+
| Route | SDK behavior |
|
|
18
|
+
| --- | --- |
|
|
19
|
+
| `POST /v1/executions` | Submit code; requires `Idempotency-Key` (1–128 characters); returns HTTP 202 and an execution projection |
|
|
20
|
+
| `GET /v1/executions/{id}` | Read status and result fields (`stdout`, `stderr`, `exit_code`, `mode`) |
|
|
21
|
+
| `GET /v1/executions` | List executions with `page`, `page_size`, `status`, `language`, `q`, and `created_on` filters |
|
|
22
|
+
| `POST /v1/executions/{id}/cancel` | Request cancellation; SDK does not retry this mutation |
|
|
23
|
+
| `POST /v1/environments` | Build reusable Python or Node environment; requires `Idempotency-Key` |
|
|
24
|
+
| `GET /v1/environments/{id}` | Read environment build status and metadata |
|
|
25
|
+
| `GET /v1/environments` | List environments with `page` and `page_size` |
|
|
26
|
+
| `GET /v1/limits` | Read request bounds, supported languages, and instance-enabled languages |
|
|
27
|
+
| `GET /v1/quota` | Read tenant quota snapshot |
|
|
28
|
+
|
|
29
|
+
The HTTP implementation adds `x-request-id`; SDK errors preserve it when present. Structured API failures use `{ "error": { "code": "...", "message": "..." } }`.
|
|
30
|
+
|
|
31
|
+
## Models and terminal states
|
|
32
|
+
|
|
33
|
+
Execution responses include ID, status, language, timeout, memory and CPU limits, creation/finish timestamps, stdout, stderr, exit code, and execution `mode`. Execution lifecycle values are `queued`, `assigned`, `leased`, `provisioning`, `running`, `completed`, `failed`, `timed_out`, and `cancelled`. Terminal values are `completed`, `failed`, `timed_out`, and `cancelled`.
|
|
34
|
+
|
|
35
|
+
Environment responses carry ID, runtime language, status, dependency inputs, artifact metadata, and timestamps. Environment lifecycle values are `queued`, `building`, `ready`, and `failed`; terminal values are `ready` and `failed`.
|
|
36
|
+
|
|
37
|
+
Python environments use pinned `requirements`. Node environments use `package_json` and the complete npm lockfile v3 object. The Node package policy requires `registry.npmjs.org`, SHA-512 integrity, and no install scripts. A ready Node environment may be attached to either JavaScript or TypeScript jobs; API tests prove this reuse.
|
|
38
|
+
|
|
39
|
+
## Errors and retry rules
|
|
40
|
+
|
|
41
|
+
| HTTP/status condition | SDK error behavior |
|
|
42
|
+
| --- | --- |
|
|
43
|
+
| `401` invalid bearer key | `AuthenticationError` |
|
|
44
|
+
| `400`, `409`, `422` invalid input, idempotency conflict, or environment not ready | `ValidationError` |
|
|
45
|
+
| `429` tenant rate/concurrency/quota limit | `QuotaError` |
|
|
46
|
+
| Other non-2xx response | `ApiError`, preserving status, structured code, and request ID |
|
|
47
|
+
| Transport failure | `NetworkError` |
|
|
48
|
+
| HTTP request or total polling deadline | SDK timeout error |
|
|
49
|
+
|
|
50
|
+
GET requests may retry a bounded number of times after transport failure or HTTP 502/503/504. Job submission and environment creation may retry only because their API contract requires a stable idempotency key; each attempt uses the exact same key. Cancellation is not retried. Redirects are rejected so bearer credentials are not forwarded to a redirected URL. API keys are never logged or emitted in errors; returned error text/code/request IDs are redacted if the server echoes the key.
|
|
51
|
+
|
|
52
|
+
## Capabilities and discrepancies
|
|
53
|
+
|
|
54
|
+
- The schema recognizes Python, JavaScript, and TypeScript. Python is enabled by default; Node language execution requires `RUSTBOX_NODE_ENABLED`. `/v1/limits` distinguishes `supported_languages` from `enabled_languages`. SDK method availability therefore does not imply a particular instance has Node enabled.
|
|
55
|
+
- Node environment creation also requires the Node environment builder and approved npm proxy. OpenAPI describes `503 node_builder_unavailable` while that proxy is unavailable. The SDK does not claim that public deployment has Node environment builds ready.
|
|
56
|
+
- The 25 October 2026 functional beta audit in this revision describes Python-only submission, unpaginated execution listing, and the mock control-plane path. Those statements conflict with the later OpenAPI/source contract and HTTP tests in this revision, which document three languages (with Node gated), paginated execution listing, and a durable scheduled execution path. The SDK follows executable current route/schema evidence and preserves runtime-gate errors.
|
|
57
|
+
- The production operations guide and repository deployment instructions say the dedicated production guest runs Python through a remote Firecracker executor and must never select the mock; the functional beta audit snapshot says public real-execution admission evidence is pending. The documented host state and the audit's admission assessment are not aligned. SDKs expose the returned `mode`, make no claim about live endpoint readiness, and do not present `mock_no_code_execution` as a sandbox.
|
|
58
|
+
- Request ID is attached by API middleware but is not part of the OpenAPI response body schema; clients read the `x-request-id` header and tolerate a body `request_id` if a future API returns one.
|
|
59
|
+
|
|
60
|
+
Live endpoint capabilities and a production smoke check were not verified: no authorized test credential was supplied for this work.
|
mpaka_sdk-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Spluca
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
mpaka_sdk-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: mpaka-sdk
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Official asynchronous Python SDK for the mPaka API
|
|
5
|
+
Author: mPaka
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Keywords: api,execution,mpaka,sdk
|
|
9
|
+
Classifier: Development Status :: 3 - Alpha
|
|
10
|
+
Classifier: Framework :: AsyncIO
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
16
|
+
Requires-Python: >=3.11
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
|
|
19
|
+
# mPaka Python SDK
|
|
20
|
+
|
|
21
|
+
Official asynchronous Python client for the mPaka API. The package is named `mpaka-sdk` on PyPI and imported as `mpaka`.
|
|
22
|
+
|
|
23
|
+
## Install
|
|
24
|
+
|
|
25
|
+
Install the published package when available:
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
uv add mpaka-sdk
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
To install a local wheel:
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
uv pip install dist/mpaka_sdk-0.1.0-py3-none-any.whl
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
The SDK requires Python 3.11 or newer and has no runtime dependencies.
|
|
38
|
+
|
|
39
|
+
## Verify a source checkout
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
uv build
|
|
43
|
+
python -m unittest discover -s tests -v
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
The wheel build and tests were verified with Python 3.14.5 and `uv` 0.13.13.
|
|
47
|
+
|
|
48
|
+
## Configure and submit a job
|
|
49
|
+
|
|
50
|
+
Create an API key in mPaka, then load it from your environment. Do not put keys in source code or log them.
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
export MPAKA_API_KEY="your-key"
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
```python
|
|
57
|
+
import asyncio
|
|
58
|
+
import os
|
|
59
|
+
from mpaka import MpakaClient
|
|
60
|
+
|
|
61
|
+
async def main():
|
|
62
|
+
async with MpakaClient(
|
|
63
|
+
os.environ["MPAKA_API_KEY"],
|
|
64
|
+
base_url=os.getenv("MPAKA_API_BASE_URL", "https://api.mpaka.dev"),
|
|
65
|
+
) as client:
|
|
66
|
+
accepted = await client.submit(
|
|
67
|
+
"print(1 + 1)",
|
|
68
|
+
language="python",
|
|
69
|
+
idempotency_key="job-2026-01-15-001",
|
|
70
|
+
)
|
|
71
|
+
print(f"Accepted {accepted.id}: {accepted.status}")
|
|
72
|
+
|
|
73
|
+
result = await client.wait_for_execution(
|
|
74
|
+
accepted.id, timeout=30, poll_interval=0.5
|
|
75
|
+
)
|
|
76
|
+
print(result.stdout)
|
|
77
|
+
if result.status.value != "completed":
|
|
78
|
+
print(result.stderr)
|
|
79
|
+
|
|
80
|
+
asyncio.run(main())
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
The default base URL is `https://api.mpaka.dev`. Pass another `base_url` for a test server or staging. Non-loopback URLs must use HTTPS. Every submission needs an idempotency key (1–128 visible ASCII characters); the client reuses that same key when safely retrying a transient submit response.
|
|
84
|
+
|
|
85
|
+
The client rejects HTTP redirects so it will not forward the bearer key to a second URL.
|
|
86
|
+
|
|
87
|
+
Use individual operations (`submit`, `get_execution`, `list_executions`, and `cancel_execution`) when you need to control polling yourself. `wait_for_execution` applies a total deadline and returns only on `completed`, `failed`, `timed_out`, or `cancelled`.
|
|
88
|
+
|
|
89
|
+
## JavaScript and TypeScript jobs
|
|
90
|
+
|
|
91
|
+
The instance may enable JavaScript and TypeScript independently of the SDK. Check `await client.get_limits()` and its `enabled_languages` field. The API accepts JavaScript and TypeScript source when the Node.js runtime is enabled. TypeScript accepts a single `.mts` file using erasable types only; syntax requiring transformation, such as enums, is rejected by Node.
|
|
92
|
+
|
|
93
|
+
```python
|
|
94
|
+
js = await client.submit(
|
|
95
|
+
"console.log(42)", language="javascript", idempotency_key="node-js-001"
|
|
96
|
+
)
|
|
97
|
+
ts = await client.submit(
|
|
98
|
+
"const answer: number = 42; console.log(answer)",
|
|
99
|
+
language="typescript",
|
|
100
|
+
idempotency_key="node-ts-001",
|
|
101
|
+
)
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## Reusable dependency environments
|
|
105
|
+
|
|
106
|
+
### Python dependencies
|
|
107
|
+
|
|
108
|
+
Send pinned requirements when building an environment:
|
|
109
|
+
|
|
110
|
+
```python
|
|
111
|
+
environment = await client.create_environment(
|
|
112
|
+
language="python",
|
|
113
|
+
requirements=["requests==2.32.3"],
|
|
114
|
+
idempotency_key="python-env-001",
|
|
115
|
+
)
|
|
116
|
+
ready = await client.wait_for_environment(environment.id, timeout=300, poll_interval=2)
|
|
117
|
+
job = await client.submit(
|
|
118
|
+
"import requests; print(requests.__version__)",
|
|
119
|
+
environment_id=ready.id,
|
|
120
|
+
idempotency_key="python-env-job-001",
|
|
121
|
+
)
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
### Node dependencies shared by JavaScript and TypeScript
|
|
125
|
+
|
|
126
|
+
Generate a complete npm lockfile v3 locally so the API receives pinned package versions and integrity hashes:
|
|
127
|
+
|
|
128
|
+
```bash
|
|
129
|
+
mkdir mpaka-node-env && cd mpaka-node-env
|
|
130
|
+
npm init -y
|
|
131
|
+
npm install lodash@4.17.21 --package-lock-only
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
```python
|
|
135
|
+
import json
|
|
136
|
+
|
|
137
|
+
with open("package.json", encoding="utf-8") as file:
|
|
138
|
+
package_json = json.load(file)
|
|
139
|
+
with open("package-lock.json", encoding="utf-8") as file:
|
|
140
|
+
package_lock = json.load(file)
|
|
141
|
+
|
|
142
|
+
node_env = await client.create_environment(
|
|
143
|
+
language="node",
|
|
144
|
+
package_json=package_json,
|
|
145
|
+
package_lock=package_lock,
|
|
146
|
+
idempotency_key="node-env-001",
|
|
147
|
+
)
|
|
148
|
+
ready_node = await client.wait_for_environment(node_env.id, timeout=300, poll_interval=2)
|
|
149
|
+
|
|
150
|
+
js_job = await client.submit(
|
|
151
|
+
"const _ = require('lodash'); console.log(_.camelCase('mPaka SDK'))",
|
|
152
|
+
language="javascript",
|
|
153
|
+
environment_id=ready_node.id,
|
|
154
|
+
idempotency_key="node-js-env-job-001",
|
|
155
|
+
)
|
|
156
|
+
ts_job = await client.submit(
|
|
157
|
+
"import _ from 'lodash'; console.log(_.camelCase('mPaka SDK'))",
|
|
158
|
+
language="typescript",
|
|
159
|
+
environment_id=ready_node.id,
|
|
160
|
+
idempotency_key="node-ts-env-job-001",
|
|
161
|
+
)
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
The same ready Node environment can be selected by JavaScript and TypeScript jobs. Node execution is instance-gated, and environment creation can return `node_builder_unavailable` until the approved npm proxy is configured. Python environments use pinned requirements. Package build constraints are enforced by the API.
|
|
165
|
+
|
|
166
|
+
## Errors
|
|
167
|
+
|
|
168
|
+
```python
|
|
169
|
+
from mpaka import (
|
|
170
|
+
ApiError,
|
|
171
|
+
AuthenticationError,
|
|
172
|
+
MpakaTimeoutError,
|
|
173
|
+
NetworkError,
|
|
174
|
+
QuotaError,
|
|
175
|
+
ValidationError,
|
|
176
|
+
)
|
|
177
|
+
|
|
178
|
+
try:
|
|
179
|
+
result = await client.submit("print('hello')", idempotency_key="example-001")
|
|
180
|
+
except AuthenticationError:
|
|
181
|
+
# Check that MPAKA_API_KEY is valid.
|
|
182
|
+
raise
|
|
183
|
+
except ValidationError as error:
|
|
184
|
+
print(error.code, error.status_code, error.request_id)
|
|
185
|
+
except QuotaError as error:
|
|
186
|
+
print("Rate or quota limit", error.status_code, error.request_id)
|
|
187
|
+
except MpakaTimeoutError:
|
|
188
|
+
print("The HTTP request or total wait deadline expired")
|
|
189
|
+
except NetworkError:
|
|
190
|
+
print("The API could not be reached")
|
|
191
|
+
except ApiError as error:
|
|
192
|
+
print(error.code, error.status_code, error.request_id)
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
API exceptions retain `status_code`, the server's structured `code`, and `request_id` from the `x-request-id` response header when present. The SDK never includes the API key in exception text or its `repr` output.
|
|
196
|
+
|
|
197
|
+
`Execution.mode` is part of the result. A value of `mock_no_code_execution` means the submitted source was not run; the SDK does not claim that a mock is a production sandbox.
|
|
198
|
+
|
|
199
|
+
## Feature coverage
|
|
200
|
+
|
|
201
|
+
| Feature | Supported |
|
|
202
|
+
| --- | --- |
|
|
203
|
+
| Python, JavaScript, and TypeScript submission | Yes; Node languages depend on instance capability |
|
|
204
|
+
| Get execution status and result | Yes |
|
|
205
|
+
| List execution history | Yes |
|
|
206
|
+
| Cancel execution | Yes |
|
|
207
|
+
| Wait with total timeout and poll interval | Yes |
|
|
208
|
+
| Create, get, list, and wait for reusable environments | Yes |
|
|
209
|
+
| Reuse Node environment for JavaScript and TypeScript | Yes |
|
|
210
|
+
| Read runtime limits and tenant quota | Yes |
|
|
211
|
+
| Safe bounded retries | GET reads; POST only with a stable idempotency key |
|
|
212
|
+
| Typed auth, validation, quota, API, network, and timeout errors | Yes |
|
|
213
|
+
|
|
214
|
+
## Contract source
|
|
215
|
+
|
|
216
|
+
The SDK contract is based on RustBox revision `130004a7d5e073ea966bb1e8fc99f26da802c6a9` and cross-checked against the mPaka CLI revision `a907c5411d6409df1e898be806d68d14bc4aa314` and MCP revision `8c361d582016bc301468c6cd5cd8630adcf210a7`. The OpenAPI schema recognizes Python, JavaScript, and TypeScript, while `/v1/limits` reports which languages are enabled on a particular instance. Node environment creation can return HTTP 503 when its approved builder or npm proxy is unavailable. See the accompanying contract record for the schema hash and route details.
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
# mPaka Python SDK
|
|
2
|
+
|
|
3
|
+
Official asynchronous Python client for the mPaka API. The package is named `mpaka-sdk` on PyPI and imported as `mpaka`.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
Install the published package when available:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
uv add mpaka-sdk
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
To install a local wheel:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
uv pip install dist/mpaka_sdk-0.1.0-py3-none-any.whl
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
The SDK requires Python 3.11 or newer and has no runtime dependencies.
|
|
20
|
+
|
|
21
|
+
## Verify a source checkout
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
uv build
|
|
25
|
+
python -m unittest discover -s tests -v
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
The wheel build and tests were verified with Python 3.14.5 and `uv` 0.13.13.
|
|
29
|
+
|
|
30
|
+
## Configure and submit a job
|
|
31
|
+
|
|
32
|
+
Create an API key in mPaka, then load it from your environment. Do not put keys in source code or log them.
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
export MPAKA_API_KEY="your-key"
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
```python
|
|
39
|
+
import asyncio
|
|
40
|
+
import os
|
|
41
|
+
from mpaka import MpakaClient
|
|
42
|
+
|
|
43
|
+
async def main():
|
|
44
|
+
async with MpakaClient(
|
|
45
|
+
os.environ["MPAKA_API_KEY"],
|
|
46
|
+
base_url=os.getenv("MPAKA_API_BASE_URL", "https://api.mpaka.dev"),
|
|
47
|
+
) as client:
|
|
48
|
+
accepted = await client.submit(
|
|
49
|
+
"print(1 + 1)",
|
|
50
|
+
language="python",
|
|
51
|
+
idempotency_key="job-2026-01-15-001",
|
|
52
|
+
)
|
|
53
|
+
print(f"Accepted {accepted.id}: {accepted.status}")
|
|
54
|
+
|
|
55
|
+
result = await client.wait_for_execution(
|
|
56
|
+
accepted.id, timeout=30, poll_interval=0.5
|
|
57
|
+
)
|
|
58
|
+
print(result.stdout)
|
|
59
|
+
if result.status.value != "completed":
|
|
60
|
+
print(result.stderr)
|
|
61
|
+
|
|
62
|
+
asyncio.run(main())
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
The default base URL is `https://api.mpaka.dev`. Pass another `base_url` for a test server or staging. Non-loopback URLs must use HTTPS. Every submission needs an idempotency key (1–128 visible ASCII characters); the client reuses that same key when safely retrying a transient submit response.
|
|
66
|
+
|
|
67
|
+
The client rejects HTTP redirects so it will not forward the bearer key to a second URL.
|
|
68
|
+
|
|
69
|
+
Use individual operations (`submit`, `get_execution`, `list_executions`, and `cancel_execution`) when you need to control polling yourself. `wait_for_execution` applies a total deadline and returns only on `completed`, `failed`, `timed_out`, or `cancelled`.
|
|
70
|
+
|
|
71
|
+
## JavaScript and TypeScript jobs
|
|
72
|
+
|
|
73
|
+
The instance may enable JavaScript and TypeScript independently of the SDK. Check `await client.get_limits()` and its `enabled_languages` field. The API accepts JavaScript and TypeScript source when the Node.js runtime is enabled. TypeScript accepts a single `.mts` file using erasable types only; syntax requiring transformation, such as enums, is rejected by Node.
|
|
74
|
+
|
|
75
|
+
```python
|
|
76
|
+
js = await client.submit(
|
|
77
|
+
"console.log(42)", language="javascript", idempotency_key="node-js-001"
|
|
78
|
+
)
|
|
79
|
+
ts = await client.submit(
|
|
80
|
+
"const answer: number = 42; console.log(answer)",
|
|
81
|
+
language="typescript",
|
|
82
|
+
idempotency_key="node-ts-001",
|
|
83
|
+
)
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## Reusable dependency environments
|
|
87
|
+
|
|
88
|
+
### Python dependencies
|
|
89
|
+
|
|
90
|
+
Send pinned requirements when building an environment:
|
|
91
|
+
|
|
92
|
+
```python
|
|
93
|
+
environment = await client.create_environment(
|
|
94
|
+
language="python",
|
|
95
|
+
requirements=["requests==2.32.3"],
|
|
96
|
+
idempotency_key="python-env-001",
|
|
97
|
+
)
|
|
98
|
+
ready = await client.wait_for_environment(environment.id, timeout=300, poll_interval=2)
|
|
99
|
+
job = await client.submit(
|
|
100
|
+
"import requests; print(requests.__version__)",
|
|
101
|
+
environment_id=ready.id,
|
|
102
|
+
idempotency_key="python-env-job-001",
|
|
103
|
+
)
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### Node dependencies shared by JavaScript and TypeScript
|
|
107
|
+
|
|
108
|
+
Generate a complete npm lockfile v3 locally so the API receives pinned package versions and integrity hashes:
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
mkdir mpaka-node-env && cd mpaka-node-env
|
|
112
|
+
npm init -y
|
|
113
|
+
npm install lodash@4.17.21 --package-lock-only
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
```python
|
|
117
|
+
import json
|
|
118
|
+
|
|
119
|
+
with open("package.json", encoding="utf-8") as file:
|
|
120
|
+
package_json = json.load(file)
|
|
121
|
+
with open("package-lock.json", encoding="utf-8") as file:
|
|
122
|
+
package_lock = json.load(file)
|
|
123
|
+
|
|
124
|
+
node_env = await client.create_environment(
|
|
125
|
+
language="node",
|
|
126
|
+
package_json=package_json,
|
|
127
|
+
package_lock=package_lock,
|
|
128
|
+
idempotency_key="node-env-001",
|
|
129
|
+
)
|
|
130
|
+
ready_node = await client.wait_for_environment(node_env.id, timeout=300, poll_interval=2)
|
|
131
|
+
|
|
132
|
+
js_job = await client.submit(
|
|
133
|
+
"const _ = require('lodash'); console.log(_.camelCase('mPaka SDK'))",
|
|
134
|
+
language="javascript",
|
|
135
|
+
environment_id=ready_node.id,
|
|
136
|
+
idempotency_key="node-js-env-job-001",
|
|
137
|
+
)
|
|
138
|
+
ts_job = await client.submit(
|
|
139
|
+
"import _ from 'lodash'; console.log(_.camelCase('mPaka SDK'))",
|
|
140
|
+
language="typescript",
|
|
141
|
+
environment_id=ready_node.id,
|
|
142
|
+
idempotency_key="node-ts-env-job-001",
|
|
143
|
+
)
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
The same ready Node environment can be selected by JavaScript and TypeScript jobs. Node execution is instance-gated, and environment creation can return `node_builder_unavailable` until the approved npm proxy is configured. Python environments use pinned requirements. Package build constraints are enforced by the API.
|
|
147
|
+
|
|
148
|
+
## Errors
|
|
149
|
+
|
|
150
|
+
```python
|
|
151
|
+
from mpaka import (
|
|
152
|
+
ApiError,
|
|
153
|
+
AuthenticationError,
|
|
154
|
+
MpakaTimeoutError,
|
|
155
|
+
NetworkError,
|
|
156
|
+
QuotaError,
|
|
157
|
+
ValidationError,
|
|
158
|
+
)
|
|
159
|
+
|
|
160
|
+
try:
|
|
161
|
+
result = await client.submit("print('hello')", idempotency_key="example-001")
|
|
162
|
+
except AuthenticationError:
|
|
163
|
+
# Check that MPAKA_API_KEY is valid.
|
|
164
|
+
raise
|
|
165
|
+
except ValidationError as error:
|
|
166
|
+
print(error.code, error.status_code, error.request_id)
|
|
167
|
+
except QuotaError as error:
|
|
168
|
+
print("Rate or quota limit", error.status_code, error.request_id)
|
|
169
|
+
except MpakaTimeoutError:
|
|
170
|
+
print("The HTTP request or total wait deadline expired")
|
|
171
|
+
except NetworkError:
|
|
172
|
+
print("The API could not be reached")
|
|
173
|
+
except ApiError as error:
|
|
174
|
+
print(error.code, error.status_code, error.request_id)
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
API exceptions retain `status_code`, the server's structured `code`, and `request_id` from the `x-request-id` response header when present. The SDK never includes the API key in exception text or its `repr` output.
|
|
178
|
+
|
|
179
|
+
`Execution.mode` is part of the result. A value of `mock_no_code_execution` means the submitted source was not run; the SDK does not claim that a mock is a production sandbox.
|
|
180
|
+
|
|
181
|
+
## Feature coverage
|
|
182
|
+
|
|
183
|
+
| Feature | Supported |
|
|
184
|
+
| --- | --- |
|
|
185
|
+
| Python, JavaScript, and TypeScript submission | Yes; Node languages depend on instance capability |
|
|
186
|
+
| Get execution status and result | Yes |
|
|
187
|
+
| List execution history | Yes |
|
|
188
|
+
| Cancel execution | Yes |
|
|
189
|
+
| Wait with total timeout and poll interval | Yes |
|
|
190
|
+
| Create, get, list, and wait for reusable environments | Yes |
|
|
191
|
+
| Reuse Node environment for JavaScript and TypeScript | Yes |
|
|
192
|
+
| Read runtime limits and tenant quota | Yes |
|
|
193
|
+
| Safe bounded retries | GET reads; POST only with a stable idempotency key |
|
|
194
|
+
| Typed auth, validation, quota, API, network, and timeout errors | Yes |
|
|
195
|
+
|
|
196
|
+
## Contract source
|
|
197
|
+
|
|
198
|
+
The SDK contract is based on RustBox revision `130004a7d5e073ea966bb1e8fc99f26da802c6a9` and cross-checked against the mPaka CLI revision `a907c5411d6409df1e898be806d68d14bc4aa314` and MCP revision `8c361d582016bc301468c6cd5cd8630adcf210a7`. The OpenAPI schema recognizes Python, JavaScript, and TypeScript, while `/v1/limits` reports which languages are enabled on a particular instance. Node environment creation can return HTTP 503 when its approved builder or npm proxy is unavailable. See the accompanying contract record for the schema hash and route details.
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling>=1.26"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "mpaka-sdk"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Official asynchronous Python SDK for the mPaka API"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.11"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
license-files = ["LICENSE"]
|
|
13
|
+
authors = [{ name = "mPaka" }]
|
|
14
|
+
keywords = ["mpaka", "api", "execution", "sdk"]
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Development Status :: 3 - Alpha",
|
|
17
|
+
"Framework :: AsyncIO",
|
|
18
|
+
"Programming Language :: Python :: 3",
|
|
19
|
+
"Programming Language :: Python :: 3.11",
|
|
20
|
+
"Programming Language :: Python :: 3.12",
|
|
21
|
+
"Programming Language :: Python :: 3.13",
|
|
22
|
+
"Programming Language :: Python :: 3.14",
|
|
23
|
+
]
|
|
24
|
+
dependencies = []
|
|
25
|
+
|
|
26
|
+
[tool.hatch.build.targets.wheel]
|
|
27
|
+
packages = ["src/mpaka"]
|
|
28
|
+
|
|
29
|
+
[tool.hatch.build.targets.wheel.force-include]
|
|
30
|
+
"CONTRACT.md" = "CONTRACT.md"
|
|
31
|
+
|
|
32
|
+
[tool.hatch.build.targets.sdist]
|
|
33
|
+
include = ["/src", "/tests", "/README.md", "/CONTRACT.md", "/LICENSE", "/pyproject.toml"]
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"""Official mPaka Python SDK."""
|
|
2
|
+
|
|
3
|
+
from .client import Language, MpakaClient
|
|
4
|
+
from .errors import (
|
|
5
|
+
ApiError,
|
|
6
|
+
AuthenticationError,
|
|
7
|
+
InvalidResponseError,
|
|
8
|
+
MpakaError,
|
|
9
|
+
MpakaTimeoutError,
|
|
10
|
+
NetworkError,
|
|
11
|
+
QuotaError,
|
|
12
|
+
ValidationError,
|
|
13
|
+
)
|
|
14
|
+
from .models import (
|
|
15
|
+
Environment,
|
|
16
|
+
EnvironmentPage,
|
|
17
|
+
EnvironmentStatus,
|
|
18
|
+
Execution,
|
|
19
|
+
ExecutionPage,
|
|
20
|
+
ExecutionStatus,
|
|
21
|
+
ExecutionSummary,
|
|
22
|
+
Quota,
|
|
23
|
+
RequestBounds,
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
__all__ = [
|
|
27
|
+
"ApiError",
|
|
28
|
+
"AuthenticationError",
|
|
29
|
+
"Environment",
|
|
30
|
+
"EnvironmentPage",
|
|
31
|
+
"EnvironmentStatus",
|
|
32
|
+
"Execution",
|
|
33
|
+
"ExecutionPage",
|
|
34
|
+
"ExecutionStatus",
|
|
35
|
+
"ExecutionSummary",
|
|
36
|
+
"InvalidResponseError",
|
|
37
|
+
"Language",
|
|
38
|
+
"MpakaClient",
|
|
39
|
+
"MpakaError",
|
|
40
|
+
"MpakaTimeoutError",
|
|
41
|
+
"NetworkError",
|
|
42
|
+
"Quota",
|
|
43
|
+
"QuotaError",
|
|
44
|
+
"RequestBounds",
|
|
45
|
+
"ValidationError",
|
|
46
|
+
]
|