A library used to build custom functions in Cozy Creator's serverless function platform.
Project description
gen-worker
Python SDK for writing endpoints that run on Cozy's worker pool. You write a decorated Python function; the SDK handles discovery, scheduling, model loading, cancellation, file I/O, and reporting to the control plane.
Three endpoint kinds:
- Inference — request/response (optionally streaming).
- Training — long-running, stateful, can publish checkpoints back to a repo.
- Conversion — produces weight artifacts on a destination repo.
Install
uv add gen-worker # core
uv add gen-worker[torch] # with PyTorch
Quick start
import msgspec
from gen_worker import RequestContext, inference_function
class Input(msgspec.Struct):
prompt: str
class Output(msgspec.Struct):
text: str
@inference_function
def hello(ctx: RequestContext, payload: Input) -> Output:
return Output(text=f"Hello, {payload.prompt}!")
Pair it with an endpoint.toml:
schema_version = 1
name = "hello"
main = "my_pkg.main" # import path that contains your @inference_function
[resources]
ram_gb = 2
cpu_cores = 1
…and a Dockerfile:
FROM python:3.12-slim
WORKDIR /app
COPY . /app
RUN pip install uv && uv sync --frozen
RUN mkdir -p /app/.tensorhub && \
uv run python -m gen_worker.discovery > /app/.tensorhub/endpoint.lock
ENTRYPOINT ["uv", "run", "python", "-m", "gen_worker.entrypoint"]
Publish with cozyctl endpoint deploy (or via the platform UI). The control
plane reads /app/.tensorhub/endpoint.lock from the image and routes invocations.
Reference
See docs/endpoint-authoring.md for the full
authoring guide: model injection, streaming, file uploads, training/conversion
contracts, error types, and local testing.
Public surface
The top-level gen_worker module exports only what endpoint authors need:
- Decorators:
inference_function,ResourceRequirements,ScalingHints - Injection:
ModelRef,ModelRefSource - Context:
RequestContext(inference; the base),ConversionContext(transform / conversion endpoints),DatasetContext(dataset-generation),TrainingContext(trainer-class) - Types:
Asset,Tensors,Compute,LoraSpec - Errors:
ValidationError,RetryableError,FatalError,ResourceError,AuthError,CanceledError,OutputTooLargeError,WorkerError - Helpers:
Clamp,iter_transformers_text_deltas,load_loras,apply_low_vram_config,with_oom_retry
Training and conversion live in their own submodules: gen_worker.trainer,
gen_worker.conversion, gen_worker.clone.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file gen_worker-0.6.2.tar.gz.
File metadata
- Download URL: gen_worker-0.6.2.tar.gz
- Upload date:
- Size: 374.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6bb327e184419529879c2d4112abb3153473c0c7d6659e8440327b3791e4858c
|
|
| MD5 |
601b6ba8301c1fc42b846adf2147ab2f
|
|
| BLAKE2b-256 |
6c0812262d3f61847818c19ffe723521fbc86793b6dbd5644b1bf8bf84c9735a
|
File details
Details for the file gen_worker-0.6.2-py3-none-any.whl.
File metadata
- Download URL: gen_worker-0.6.2-py3-none-any.whl
- Upload date:
- Size: 426.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
03e1bc578ac919bd7be8d303b17fdcd38dcbe62ff240f39271394e93e80420bf
|
|
| MD5 |
7e1087283d536c9f02a5dbf44b77d0ec
|
|
| BLAKE2b-256 |
34bb4ad1e659560a342f989b972852b6e17a76d712b873436c29321170bf3dfb
|