Python SDK tutorial

Python SDK tutorial

Install the GenAsset Python SDK, save a generated image with full recipe metadata, attach input images, and load the saved version back into a pipeline.

Goal

Python SDKDashboard verified

Use the Python SDK when your image is created outside ComfyUI: Diffusers, a local model runner, a notebook, a batch pipeline, or a custom script. The goal is the same as the ComfyUI tutorial: save the output image plus the recipe fields needed to recreate it later.

Authenticate

Use one workspace token from GenAsset settings or onboarding.

Save the run

Send image, prompt, model, seed, sampler, dimensions, tags, and workflow metadata.

Reload later

Load a version recipe or download the saved preview into another Python run.

Setup

Install the SDK in the same environment as your generation code. Keep the token in an environment variable for local scripts, notebooks, and batch jobs.

Install and configure
bash
python3 -m venv .venv
source .venv/bin/activate

pip install gen-asset-sdk pillow

export GENASSET_TOKEN="ga_your_workspace_token"
export GENASSET_BASE_URL="https://genasset.xyz"
Token hygiene
Do not commit workspace tokens to Git, notebooks, screenshots, public logs, or shared examples. Use GENASSET_TOKEN locally and rotate the token if it is exposed.

Steps

  1. Create or choose a GenAsset workspace token.
  2. Install gen-asset-sdk and set GENASSET_TOKEN.
  3. Run your Python generation pipeline and save the output image to disk.
  4. Call client.save_image(...) with the output image and the full recipe fields.
  5. Open the GenAsset dashboard and confirm the new asset has Type Python SDK.
  6. Open the asset detail page and check prompt, negative prompt, model, seed, steps, CFG, sampler, scheduler, denoise, size, tags, and intent.
Save a text-to-image run
python
from pathlib import Path
from PIL import Image, ImageDraw
from gen_asset_sdk import GenAssetClient

client = GenAssetClient(token="ga_your_workspace_token")

out = Path("outputs/python-sdk-blue-cube.png")
out.parent.mkdir(parents=True, exist_ok=True)

# Replace this demo image with your real Diffusers, Invoke, or custom pipeline output.
image = Image.new("RGB", (512, 512), (22, 36, 54))
draw = ImageDraw.Draw(image)
draw.rounded_rectangle((150, 130, 360, 350), radius=24, fill=(39, 138, 107))
draw.text((142, 385), "GenAsset Python SDK", fill=(235, 248, 242))
image.save(out)

result = client.save_image(
    image_path=out,
    asset_name="python-sdk-blue-cube",
    prompt="a translucent blue glass cube on a brushed steel table, clean product photo, soft rim light",
    negative_prompt="low quality, blurry, text, watermark, distorted cube",
    model="runwayml/stable-diffusion-v1-5",
    seed=1778911201,
    steps=20,
    cfg=7.5,
    sampler_name="Euler",
    scheduler="normal",
    denoise=1.0,
    width=512,
    height=512,
    workflow_name="python-sdk-blue-cube",
    workflow_kind="txt2img-from-python",
    family="sd1.5",
    intent="txt2img",
    tags=["python-sdk", "product", "tutorial"],
)

print(result["asset"]["id"])
print(result["version"]["id"])
Image-to-image inputs
For edits, ControlNet, reference-image runs, or any workflow that starts from one or more source images, pass those files as input_images. GenAsset stores them in the Inputs panel so the run can be audited later.
Save a run with input images
python
result = client.save_image(
    image_path="outputs/edited-room.png",
    input_images=["inputs/source-room.png"],
    asset_name="python-sdk-room-edit",
    prompt="same room without the plant, brighter morning light",
    negative_prompt="plant, clutter, low quality",
    model="stabilityai/stable-diffusion-xl-base-1.0",
    seed=314159,
    steps=24,
    cfg=6.0,
    sampler_name="DPM++ 2M",
    scheduler="karras",
    denoise=0.42,
    width=1024,
    height=1024,
    workflow_kind="img2img-from-python",
    family="sdxl",
    intent="image_to_image",
)

Validated run

  • The SDK creates replay-focused workflow JSON automatically if you do not pass your own workflow payload.
  • Saved Python runs are shown as Type: Python SDK in the asset Generation panel.
  • Recipe fields are aligned with the ComfyUI save path: prompt, negative prompt, model, seed, steps, CFG, sampler, scheduler, denoise, width, height, family, and workflow kind.
  • Input images are uploaded with the saved version and appear in the asset Inputs panel.
Load a saved version
python
payload = client.load_version("paste_version_id_here")
version = payload["version"]

print(version["asset_id"])
print(version.get("prompt"))
print(version.get("metadata_json"))

client.download_version_image(
    "paste_version_id_here",
    "outputs/reloaded-from-genasset.png",
)

Next