sketchforge3d
A Python client for the SketchForge REST API, and a runner for macros: short parameterised scripts that build a part.
pip install sketchforge3d
The install name and the import name are the same, and there are no runtime dependencies: the client speaks HTTP through urllib from the standard library, so it installs anywhere Python does and adds nothing to a macro author's lockfile.
The API is headless -- it reads and writes projects in server-side storage with no browser open -- so a macro is a build script for a design, the way a Makefile is for a binary.
Connecting
from sketchforge3d import SketchForgeClient, client_from_environment
client = SketchForgeClient(base_url="http://localhost:3000", token="...")
client = client_from_environment() # SKETCHFORGE_API_TOKEN, SKETCHFORGE_URL
health = client.check()
if not health["ok"]:
raise SystemExit(health["reason"])
Prefer the environment: the token is a password for every project on the server and does not belong in a script or in shell history. The server needs both SKETCHFORGE_API_TOKEN and SKETCHFORGE_PROJECTS_DIR set, or the API answers 404 and 503 respectively; check() says which.
The client
SketchForgeClient(base_url, token, timeout=60.0, retry_on_busy=4, headers=None, opener=None)
client.api_root -> str
client.check() -> dict
client.project(project_id) -> ProjectHandle
client.projects.list() -> list[ProjectSummary]
client.projects.get(project_id) -> ProjectDetail
client.projects.create(name) -> ProjectSummary
client.projects.delete(project_id) -> bool
client.projects.find_by_name(name) -> ProjectSummary | None
client.shapes.list(project_id) -> list[ShapeSummary]
client.shapes.create(project_id, shape) -> ShapeSummary
client.shapes.create_many(project_id, shapes) -> ShapeWriteResult
client.shapes.update(project_id, shape_id, changes) -> ShapeSummary
client.shapes.delete(project_id, shape_id) -> bool
client.shapes.delete_all(project_id) -> int
client.edges.list(project_id, shape_id) -> list[EdgeSummary]
client.edges.filletable_indexes(project_id, shape_id) -> list[int]
client.treatments.apply(project_id, shape_id, kind, amount, angle=None, edges=None) -> TreatmentResult
client.treatments.fillet(project_id, shape_id, radius, edges=None) -> TreatmentResult
client.treatments.chamfer(project_id, shape_id, distance, angle=None, edges=None) -> TreatmentResult
client.faces.list(project_id, shape_id) -> list[FaceSummary]
client.faces.facing(project_id, shape_id, direction) -> list[int]
client.shell.apply(project_id, shape_id, thickness, open_faces=None) -> ShellResult
client.shell.hollow(project_id, shape_id, thickness) -> ShellResult
client.shell.tray(project_id, shape_id, thickness, open_faces=None) -> ShellResult
A ProjectHandle is the same surface with the project id bound, which is what a macro works through:
project.get() | delete() | list_shapes() | add(shape) | add_many(shapes) | update(id, changes)
project.remove(id) | clear() | edges(id) | filletable_edges(id)
project.fillet(id, radius, edges=None) | chamfer(id, distance, angle=None, edges=None)
project.faces(id) | faces_facing(id, direction)
project.shell(id, thickness, open_faces=None) | hollow(id, thickness) | tray(id, thickness, open_faces=None)
Requests are plain dicts, because the server takes a bag of parameters; responses are frozen dataclasses with snake_case fields, so shape.rotation_x is checked and a typo is an error rather than a None. A field this version does not know about is kept in shape.extra rather than dropped.
project.add_many([
{"kind": "box", "name": "Plate", "width": 120, "depth": 40, "height": 6},
{"kind": "cylinder", "width": 8, "height": 12, "sides": 6, "x": -40, "elevation": -1, "hole": True},
{"kind": "thread", "size": "M8", "length": 10, "hole": True, "x": 40},
{"kind": "revolve", "profile": [[8, 0], [10, 0], [10, 2], [8, 2]], "pitch": 6, "turns": 6},
])
create_many is one write of the project package per request and splits lists longer than the server's 200-shape limit -- which also means a longer list is no longer atomic.
Failures are SketchForgeApiError (status, detail, plus looks_disabled, needs_storage, is_project_busy) or SketchForgeTransportError, both subclasses of SketchForgeError. A write that lost the project's lock is retried; a locked shape, which answers 409 for an unrelated reason, is not.
sketchforge3d.layout has the arithmetic a parameterised part repeats: row, grid, ring, centered_offsets, angle_of, mm.
Macros
A macro is a file that defines MACRO and builds something when it is handed a connected project:
# macros/bolt_plate.py
from sketchforge3d import MacroContext, define_macro
def build(context: MacroContext) -> dict:
params, layout = context.params, context.layout
context.log(f"{params['holes']} {params['size']} holes")
context.project.add_many(
[{"kind": "box", "name": "Plate", "width": 200, "depth": 40, "height": params["thickness"]}]
+ [
{
"kind": "thread",
"name": f"hole {index}",
"size": params["size"],
"length": params["thickness"] + 2,
"hole": True,
"x": at.x,
"z": at.z,
"elevation": -1,
}
for index, at in enumerate(layout.row(int(params["holes"]), float(params["spacing"])), start=1)
]
)
return {"holes": params["holes"]}
MACRO = define_macro(
name="Bolt plate",
project=("replace", "Bolt plate"),
params={"holes": 5, "spacing": 25.0, "size": "M8", "thickness": 8.0},
run=build,
)
SKETCHFORGE_API_TOKEN=... python -m sketchforge3d.macro macros/bolt_plate.py --holes=7 --spacing=30
python -m sketchforge3d, and the sketchforge-macro console script, run the same thing. The context carries everything the macro needs -- client, project, params, layout, log -- so a macro file imports only define_macro.
Project modes, and why there is no default
The second run is what makes a macro useful or dangerous. A script that appends to a project it found doubles the part every time, and nobody notices until they open the project. So the mode is declared and the runner, not the macro body, acts on it:
project |
What the runner does first | Use it for |
|---|---|---|
"fresh" |
Creates a new project, name stamped with the time | Something you generate several of to compare |
("replace", name) |
Finds that project and empties it, or creates it | A part you iterate on; re-running is idempotent |
("reuse", name) |
Finds or creates it, and leaves the contents alone | Adding a feature to whatever is there |
"target" |
Requires SKETCHFORGE_PROJECT_ID or --project, touches nothing else |
Operating on a project someone else named |
A module with a bare run(context) function instead of a MACRO runs in a fresh project, because that is the only mode that is safe to assume.
Parameters
params is both the defaults and the schema. An override is coerced to the type of its default -- an int default refuses 4.5, a float default takes it -- and a name the macro does not declare is refused, so --hoels=7 is an error rather than a silently ignored typo. Parameters are resolved before the project is created, so a bad one costs nothing.
Examples
examples/ holds the three worked macros, which double as the integration tests:
| Macro | Builds |
|---|---|
bolt_plate.py |
A plate sized around a computed row of tapped holes |
bolt_circle.py |
A flange with N tapped holes on a ring of radius R |
filleted_box.py |
A box from three numbers, with every roundable edge filleted on the server |
Tapped holes are {"kind": "thread", "hole": True}: the form is cut wider by a clearance and the shape is marked as a hole, so grouping it with the plate in the editor taps the plate. The API has no grouping endpoint yet, so the macros stop at marked holes.
Development
Tests are unittest from the standard library, so there is nothing to install:
PYTHONPATH=src:tests python3 -m unittest discover -s tests -t tests # unit
PYTHONPATH=src python3 -m unittest discover -s tests/integration -t tests/integration # needs a live server
From the repository root those are npm run client:test:py and npm run client:test:py:integration. The integration tests need a real server:
SKETCHFORGE_PROJECTS_DIR=$(mktemp -d) SKETCHFORGE_API_TOKEN=test-token \
npx next dev apps/web -p 3100 &
export SKETCHFORGE_API_TOKEN=test-token SKETCHFORGE_URL=http://127.0.0.1:3100
npm run client:test:py:integration
Publishing
See docs/PUBLISHING_CLIENTS.md for the trusted-publisher settings PyPI needs before the release workflow can publish this package.
Metadata
Release files for sketchforge3d 1.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| sketchforge3d-1.4.0.tar.gz | 31.3 kB | With provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| sketchforge3d-1.4.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 57.3 kB
Release files / sketchforge3d-1.4.0.tar.gz
| Download URL | sketchforge3d-1.4.0.tar.gz |
|---|---|
| Size | 31.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7557c9f754710c1cdac1e81eb96d784c09d5df0369c2e2582d9d53c307df7699
|
|
BLAKE2b-256 checksum How to use checksums |
f9587213ff601e6b953c7355269020882d2de49365a7521e3d63afd09c409949
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 20, 2026.
Transparency logRelease files / sketchforge3d-1.4.0-py3-none-any.whl
| Download URL | sketchforge3d-1.4.0-py3-none-any.whl |
|---|---|
| Size | 25.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1e8cebd01d5b0b7da3ba083612966258cda29fae1cc9ef8172d8acb3bf54d83d
|
|
BLAKE2b-256 checksum How to use checksums |
4c0fdbb33784f859ab083cd1ac5e75c4d0359035e657bbe9eb5c9a761d8e4e6c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 20, 2026.
Transparency logSecurity for sketchforge3d 1.4.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for sketchforge3d-1.4.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 20, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.