deploy-chalk-function
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseDeploy a Chalk function
部署 Chalk 函数
Make a python file that uses the package (PyPI name is , not ). Use a shebang. Pin Python to because a transitive Rust dep () builds against PyO3 which currently maxes out at 3.13.
chalkcomputechalkcomputechalk-sandbox-sdkuv<3.14chalk-remote-call-pythonpy
#!/usr/bin/env -S uv run --script
#创建一个使用 包的 Python 文件(PyPI 名称是 ,而不是 )。使用 shebang。将 Python 版本固定为 ,因为传递性 Rust 依赖()基于 PyO3 构建,而 PyO3 当前最高支持 3.13。
chalkcomputechalkcomputechalk-sandbox-sdkuv<3.14chalk-remote-call-pythonpy
#!/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 CLI config. The env var is , not .
chalkCHALK_ENVIRONMENT_IDCHALK_ENVIRONMENTCHALK_API_SERVER
CHALK_CLIENT_ID
CHALK_CLIENT_SECRET
CHALK_ENVIRONMENT_IDYou can read these out of output for the current project. Example invocation:
chalk configCHALK_API_SERVER=... CHALK_CLIENT_ID=... CHALK_CLIENT_SECRET=... CHALK_ENVIRONMENT_ID=... ./your_script.pyWithout you'll get a error from even though / are valid.
CHALK_ENVIRONMENT_IDpermission_deniedCustomImageService.GetOrBuildCustomImageCHALK_CLIENT_IDCHALK_CLIENT_SECRETSDK 从环境变量读取凭据,而不是从 CLI 配置中读取。环境变量名称是 ,而不是 。
chalkCHALK_ENVIRONMENT_IDCHALK_ENVIRONMENTCHALK_API_SERVER
CHALK_CLIENT_ID
CHALK_CLIENT_SECRET
CHALK_ENVIRONMENT_ID可以从当前项目的 输出中读取这些值。调用示例:
chalk configCHALK_API_SERVER=... CHALK_CLIENT_ID=... CHALK_CLIENT_SECRET=... CHALK_ENVIRONMENT_ID=... ./your_script.py如果未设置 ,即使 和 有效,也会收到来自 的 错误。
CHALK_ENVIRONMENT_IDCHALK_CLIENT_IDCHALK_CLIENT_SECRETCustomImageService.GetOrBuildCustomImagepermission_deniedLocal SDK source
本地 SDK 源码
If isn't on the configured index (e.g. the script can't resolve from PyPI), point uv at a local checkout of :
chalkcomputechalkcomputechalk-sandbox-sdkundefined如果配置的索引中没有 (例如脚本无法从 PyPI 解析 ),请让 uv 指向 的本地检出副本:
chalkcomputechalkcomputechalk-sandbox-sdkundefined[tool.uv.sources]
[tool.uv.sources]
chalkcompute = { path = "/path/to/chalk-sandbox-sdk" }
chalkcompute = { path = "/path/to/chalk-sandbox-sdk" }
undefinedundefined