deploy-chalk-function

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Deploy a Chalk function

部署 Chalk 函数

Make a python file that uses the
chalkcompute
package (PyPI name is
chalkcompute
, not
chalk-sandbox-sdk
). Use a
uv
shebang. Pin Python to
<3.14
because a transitive Rust dep (
chalk-remote-call-python
) builds against PyO3 which currently maxes out at 3.13.
py
#!/usr/bin/env -S uv run --script
#
创建一个使用
chalkcompute
包的 Python 文件(PyPI 名称是
chalkcompute
,而不是
chalk-sandbox-sdk
)。使用
uv
shebang。将 Python 版本固定为
<3.14
,因为传递性 Rust 依赖(
chalk-remote-call-python
)基于 PyO3 构建,而 PyO3 当前最高支持 3.13。
py
#!/usr/bin/env -S uv run --script
#

/// script

/// script

requires-python = ">=3.12,<3.14"

requires-python = ">=3.12,<3.14"

dependencies = ["chalkcompute"]

dependencies = ["chalkcompute"]

///

///

import chalkcompute
@chalkcompute.function() def some_function(arg_1: str) -> str: return f"hi {arg_1}"
if name == "main": print(some_function("world"))

Notes:

- `@chalkcompute.function` must be **called** — `@chalkcompute.function()` (keyword-only args). Bare `@chalkcompute.function` raises `TypeError: function() takes 0 positional arguments but 1 was given`.
- The decorator deploys the function at import time (builds image, uploads, registers).
- Calling the decorated function (`some_function("world")`) invokes it remotely and returns the result.
import chalkcompute
@chalkcompute.function() def some_function(arg_1: str) -> str: return f"hi {arg_1}"
if name == "main": print(some_function("world"))

注意:

- `@chalkcompute.function` 必须被**调用**,即使用 `@chalkcompute.function()`(仅限关键字参数)。直接使用 `@chalkcompute.function` 会抛出 `TypeError: function() takes 0 positional arguments but 1 was given`。
- 装饰器会在导入时部署函数(构建镜像、上传并注册)。
- 调用已装饰的函数(`some_function("world")`)会在远程执行该函数并返回结果。

Required env vars

必需的环境变量

The SDK reads creds from env, not from
chalk
CLI config. The env var is
CHALK_ENVIRONMENT_ID
, not
CHALK_ENVIRONMENT
.
CHALK_API_SERVER
CHALK_CLIENT_ID
CHALK_CLIENT_SECRET
CHALK_ENVIRONMENT_ID
You can read these out of
chalk config
output for the current project. Example invocation:
CHALK_API_SERVER=... CHALK_CLIENT_ID=... CHALK_CLIENT_SECRET=... CHALK_ENVIRONMENT_ID=... ./your_script.py
Without
CHALK_ENVIRONMENT_ID
you'll get a
permission_denied
error from
CustomImageService.GetOrBuildCustomImage
even though
CHALK_CLIENT_ID
/
CHALK_CLIENT_SECRET
are valid.
SDK 从环境变量读取凭据,而不是从
chalk
CLI 配置中读取。环境变量名称是
CHALK_ENVIRONMENT_ID
,而不是
CHALK_ENVIRONMENT
。
CHALK_API_SERVER
CHALK_CLIENT_ID
CHALK_CLIENT_SECRET
CHALK_ENVIRONMENT_ID
可以从当前项目的
chalk config
输出中读取这些值。调用示例:
CHALK_API_SERVER=... CHALK_CLIENT_ID=... CHALK_CLIENT_SECRET=... CHALK_ENVIRONMENT_ID=... ./your_script.py
如果未设置
CHALK_ENVIRONMENT_ID
,即使
CHALK_CLIENT_ID
和
CHALK_CLIENT_SECRET
有效,也会收到来自
CustomImageService.GetOrBuildCustomImage
的
permission_denied
错误。

Local SDK source

本地 SDK 源码

If
chalkcompute
isn't on the configured index (e.g. the script can't resolve
chalkcompute
from PyPI), point uv at a local checkout of
chalk-sandbox-sdk
:
undefined
如果配置的索引中没有
chalkcompute
(例如脚本无法从 PyPI 解析
chalkcompute
),请让 uv 指向
chalk-sandbox-sdk
的本地检出副本:
undefined

[tool.uv.sources]

[tool.uv.sources]

chalkcompute = { path = "/path/to/chalk-sandbox-sdk" }

chalkcompute = { path = "/path/to/chalk-sandbox-sdk" }

undefined
undefined