Documentation & page contents

Python · beforewear

SDK

One Client. Resources are first-class. Jobs return immutable Runs. The same names exist as MCP tools.

Package beforewear. Default engine is an in-memory stub. Swap the engine later without changing call sites.

Get access and install

The SDK is provided through gated access. Request an SDK checkout before following these steps. These local examples demonstrate contracts and fixture results, not a connected physics or rendering service.

Run these commands from the root of your Beforewear SDK checkout. This installs the local source package.

python -m pip install -e ".[dev]"
pytest
python examples/run_workflow.py dress_blank

Client

aop-hoodie is an example SKU. Replace it with a product from your catalog.

from beforewear import Client

bw = Client()
blank = bw.products.get("aop-hoodie")
body = bw.bodies.select(sex="male", size="M", pose="native_straight")
material = bw.materials.get("fleece_250gsm")
run = bw.projects.create(
    product=blank.id,
    body=body.id,
    material=material.id,
).drape(device="gpu")
run = bw.finish(run.id)
run = bw.colorways.apply(run.id, {"name": "navy", "hex": "#1b2a4a"})
run = bw.graphics.apply(run.id, artwork={"front": "front.png", "back": "back.png"})
pngs = run.render(view_set="catalog", body="display")
ghost = bw.mockups.render(run.id, kind="ghost")
on_model = bw.mockups.render(run.id, kind="on_model", model="generated")
glb = run.export(format="glb")
fold = bw.space.simulate(run.id, kind="fold")
video = bw.space.video(fold.id)

drape does not take artwork. Device is cpu or gpu on that call only.

Namespaces

HandleMethods
bw.productslist, get(product_id)
bw.patternsfrom_manufacturer, draft, annotate_sketch, from_reference_images, get, revise, preflight, grade
bw.constructionspropose, apply_recipe, preflight, get, revise
bw.bodieslist, get, select(sex, size, pose=…) MHR catalog. Library pose, or a custom pose. SMPL / SMPL-X and related bodies through NVIDIA SOMA.
bw.materialslist, get, build(name, swatch=…)
bw.projectscreate(product=… | pattern=…, construction=…, body=…, material=…) then .compile(), .arrange(), .drape(device=…)
bw.colorwaysapply(run_id, {name, hex}) → child Run
bw.graphicsapply(run_id, artwork={placement: uri}) on an existing garment → child Run
bw.techpacksexport(…) — custom manufacturing pack, format=pdf | json | dxf
bw.mockupsrender(run_id, kind=on_avatar | ghost | flat | on_model, model=wearer | generated | photo | none)
bw.spacesimulate(run_id, kind=flatlay | hanger | fold), video(motion_id, format=mp4)

On the client itself: finish, status, get_run, measure, uv_audit, render, export.

patterns.grade(pattern_id, product_id=… | size_chart=…, sizes=…) returns one Pattern per size. Agents send the chart, not grade knobs.

techpacks.export is the custom-garment handoff. It is 2D. It does not drape. Pass run_id only to attach measured POM. Do not send layout knobs. Pair with export for the 3D.

mockup.render requests a presentation still using the garment’s applied artwork. Review print fidelity in delivered images. Ghost and lay-flat are product shots. On-model is a generated identity or a real photograph around the same cloth. Do not send prompts for the print.

space.simulate records cloth in space from a draped or presented Run. space.video encodes those frames. It does not invent in-between cloth. Do not send solver knobs. kind=flatlay is physics on a table, not a lay-flat mockup.

Runs

A Run is immutable. Post-drape jobs return a new id with parent_id set.

PhaseMeaning
arrangedCompile or arrange finished. Not yet draped.
drapedBlank garment on a body. UVs present. No artwork.
finishedFinish pass applied. Still a blank until stamped.
presentedColorway and/or graphic applied. Ready for mockups and catalog renders.

GateError

Raised when arrange, drape, or preflight refuses. Catch it. Do not raise clearance bounds.

from beforewear import Client, GateError

bw = Client()
try:
    bw.projects.create(product=…, body=…, material=…).drape()
except GateError as err:
    payload = err.to_dict()
    # payload["gate"], ["phase"], ["witnesses"], ["hint"]
    bw.patterns.revise(pattern_id, note=payload["hint"])

Walked example: revise_after_gate. The loop itself is the harness.