Docs

Python · beforewear

SDK

One Client, the protocol's tools as typed calls. It calls Beforewear's hosted server with a personal token; garments are built on Beforewear's computers, not in the package.

Get access and install

The SDK is in preview: ask for access to its repository, then install it and make a personal token in Studio, under Connect.

python -m pip install "git+https://github.com/algorithmic-labs/beforewear-sdk"

Use it

from beforewear import Client

bw = Client("vbl_pat_...")
hoodie = bw.garments.get("vb-py-aop-hood")
design = bw.designs.create(hoodie.id, "L", "Club hoodie", base_colour="navy")
design = bw.designs.place(design.id, "front", artwork="logo.png", width_cm=24, y=0.3)
design = bw.designs.place(design.id, "left sleeve", text="EST. 2026", rotate=True, colour="cream")
shots = bw.mockups.render(design.id, views=["front", "back"])  # saved to beforewear-output/
files = bw.designs.export(design.id)  # print files: a PNG per piece at 150 dpi
print(design.url)  # the design, open in Studio

Artwork is a local file (sent along with the call) or an https link. Areas are named as a person reads them; a design lists its areas and its layers, each layer with the id that place(layer=...) and remove take.

Calls

SDKTool
bw.garments.list() / .get(id)garment.list / garment.get
bw.presets.list(kind=None)preset.list
bw.designs.create(garment, size, name, base_colour=, preset=)design.create
bw.designs.place(id, area, artwork= | text= | preset=, width_cm=, x=, y=, rotate=, colour=)design.place
bw.designs.place(id, layer=..., y=...)design.place with layer_id
bw.designs.update / .remove / .delete / .get / .listdesign.update / remove / delete / get / list
bw.designs.generate(id, words) then .wait(run)design.generate, design.get_generation
bw.designs.export(id)design.export (the ZIP saved to disk)
bw.mockups.render(id, views=[...])mockup.render (the mockups saved to disk)
bw.balance.get()balance.get
bw.builds.price(sizes)build.price
bw.builds.request(words, pattern=[...] | model=..., chart=, photos=, name=, sizes=, cap=)build.request
bw.builds.get(id) / .list() / .answer(id, answers) / .cancel(id)build.get / build.list / build.answer / build.cancel
bw.builds.send(id, pattern=..., chart=, sizes=, cap=)build.send

bw.call(tool, arguments) reaches any tool by its name.

The design generator

words = next(p.words for p in bw.presets.list(kind="mural"))
run = bw.designs.generate(design.id, words)  # a generated design's price, from your balance
design = bw.designs.wait(run)  # minutes; the drawing is then a "generated" layer

Offline

Client() with no token answers from a stand-in server in the package: the same calls and answers, in memory. The examples (examples/dress_a_garment.py, examples/generate.py) and the tests run on it; set BEFOREWEAR_TOKEN to run them on the hosted server.

Errors

NotAuthorized: no token, or one the server does not take. Refused: the server's sentence says why. NotEnoughFunds: the balance does not cover the call; funds are added in Studio.