- Python 99.9%
- Makefile 0.1%
SnapPeg(d, h, barb, slit, release, fit): a split peg and its socket that snap together and hold, for parts that stack (trays in a rack, a lid on a box) and must stay together when picked up. The barb meets the socket's neck on a 45 degree lead-in; its back face (release) is 45 degrees by default, so the parts come apart with a firm pull, or 90 for a shoulder that doesn't. Both print upright without support. The prongs' bending strain as the barb passes the neck is checked (2 % by default, safe for PLA), so a peg too short for its barb is refused. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> |
||
|---|---|---|
| .forgejo/workflows | ||
| src/makerlib | ||
| tests | ||
| .gitignore | ||
| Makefile | ||
| poetry.lock | ||
| pyproject.toml | ||
| README.md | ||
makerlib
Reusable building blocks for parametric 3D-printed parts, in Python + solid2 (rendered by OpenSCAD). Distilled from a collection of printed designs: the shapes, fasteners, joints and fits that were copy-pasted between them, with the values those prints actually used as defaults. Every design is a short recipe: named parameters with units and ranges, rules, parts, tests and a build record for every STL.
Written about in the makerlib series on 3ntropy.io.
from makerlib import Recipe, rounded_box, hole_pattern
r = Recipe(__file__, "Fan plate")
r.param("size", 40.0, "mm", "plate", "plate size", 30, 120)
r.param("t", 2.0, "mm", "plate", "thickness", 1, 6)
r.param("fit", "grip", "", "screws", "screw fit", choices=["free", "grip", "insert"])
def fan(p):
return hole_pattern("fan_30").at(p.size / 2, p.size / 2)
r.interface(lambda p: fan(p).interface("fan-30", fit=p.fit))
@r.model
def plate(p):
return rounded_box([p.size, p.size, p.t], r=3) - fan(p).holes(depth=p.t, fit=p.fit, z=p.t)
if __name__ == "__main__":
r.main() # poetry run python fan_plate.py --size 50 --fit grip --stl
Installing
makerlib isn't on PyPI. Install a tagged release from this repository:
# pyproject.toml of a design
[project]
dependencies = [
"makerlib @ git+https://git.3ntropy.io/aluminum-ice/makerlib.git@v0.19.0",
]
or pip install "makerlib @ git+https://git.3ntropy.io/aluminum-ice/makerlib.git@v0.19.0". To work on
makerlib and a design together, install your checkout over it in the design's environment:
pip install -e /path/to/makerlib (and go back to the tag when the change is released).
Every recipe gets one flag per parameter, --schema, --stl / --3mf / --check,
--params FILE (values shared between mating parts), --fit-profile FILE, --part NAME, and writes
scad/<name>.scad, stl/<name>.stl and stl/<name>.build.json under the project folder (the nearest
folder with a pyproject.toml). --all builds every variant in the project's params/ folder, each
named after its file (params/display_2.yaml -> stl/display_2.stl).
OpenSCAD writes an STL's triangles in a different order on every run, so the file's hash changes even
when the shape does not. The build record also holds stl_geometry_sha256, which ignores the order,
and a rebuild keeps the existing STL when the shape is unchanged, so git only shows real changes.
Modules
| Module | What | What it replaced in the designs |
|---|---|---|
fit |
EPS, OVERSHOOT, clearance("slide"), hole(), slot(), pocket(), fit profiles |
delta / buffer / gap / SLOP, which meant different things in each file (0 to 0.75 mm) |
shapes |
rounded_rect (one radius, or one per corner), rounded_box, rounded_polygon (an outline from corner points, grown by r like a hull of circles, or kept to size), round_corners (any outline), prism (extrude a cross-section along x, y or z, so long parts are modelled lying down), views (a solid from its 2D views, intersected: round the outlines in 2D to round the edges), flatted_circle (a circle with one or two flats: D and double-D shafts, a disc that stands on a flat), rounded_cuboid (every edge rounded; a pillow when one side is 2r), fillet_ring / round_ring / chamfer_ring (a fillet at the foot of a rounded-rectangle wall, or a rounded or 45° chamfered top, bottom or pocket edge, from sweep_outline, which sweeps any edge profile round the outline; chamfer a pocket's cutter to slope its floor into the walls), arc_slot (a curved slot with round ends), teardrop (a hole's section with a 45° point on top, optionally capped flat, so a hole lying down prints without support), teardrop_rod (a hole's cutter, round or a teardrop pointing a chosen way), fluted_circle (a grip outline for knobs and posts), ridged_circle (the opposite: round ridges round a screw cap, one polygon), chamfered_cylinder (45° bed and top edges; with ridges= the chamfer runs round the ridges too), rounded_cylinder, lathe + arc_points (a solid of revolution from an exact line-and-arc profile: bowls, domes, knobs), stadium, shell (uniform walls), slab, tube, chamfer_corners_2d, gusset |
round_corners_2d, roundedcube, rounded_box, rcube copies; hulls of circles (zippo, molle, bambu_spool_holder_extension) |
screws |
screw_hole(size, depth, fit=free/grip/insert, head=counterbore/countersink/none, teardrop=) (teardrop="-y" points the hole and its counterbore toward the side that will be up, for a screw lying down), screw_slot, nut_trap, bolt_length(size, grip) (the shortest standard bolt for a grip, with its nut), head_fits(size, bore) (does the head, and the driver, go down a cup or socket: for a rule), the screw table (M2 to M5, #8, #10, #12) |
per-project screw() helpers |
layout |
place, corners, grid, line, polar, mirror_copy, row (n items with walls between them and at the ends: positions and total length) |
hand-unrolled placement loops; n*item + (n+1)*gap in zippo, coin_battery_box, keycap_tray |
patterns |
hole_pattern("pi_b" / "pi_zero" / "drive_2_5" / "fan_30" / "fan_40" / "bambu_h2_exhaust" / (dx, dy)), standoffs |
Pi and fan hole patterns typed into many files |
features |
port_cutout("usb_c" ...), window, tube_window (rectangular windows through a tube's wall, one side or straight across: the catches a snap clip's tabs spring into), rounded_cutout (a box cutter with rounded edges along the axis it exits through: a radius per corner or corners="top", and span to round only the stretch through a wall), vent_slots, bore (a round hole right through along x, y or z, with overshoot; teardrop=True for one lying down), recess (a pocket down from a top surface, or a clean through-cut when it is as deep as the part; dome= gives a round one a spherical floor, a cradle for a domed object), label (raised or engraved text, Liberation Sans by default), ring_slot (a slot round a tube's wall: a bolt through a pole turns between its ends), arc_scale (a dial's ticks and numbers along an arc, reading outward, engraved or raised) |
inline connector cubes, vent() copies; rotate([90,0,0])(cylinder(...)) side holes (12 V boxes); starlink's slots of 91 cylinders and its Mac-only label font; round pockets subtracted by hand; text added in the slicer (xtool) |
threads |
Thread(d, pitch, length, fit, angle, lead): .rod(lead=) and .bore(mouth=), a threaded rod and the hole it screws into, made from the same numbers so they mesh; ISO 60° or "printable" 45° flanks; 45° lead-in chamfers so a cap starts straight; .interface() |
BOSL2's threaded_rod (airtag), which needed BOSL2 installed where OpenSCAD could find it |
devices |
AIRTAGS, airtag(gen): the sizes of things designs hold |
the AirTag sizes in xtool |
magnets |
magnet_pocket("6x2", fit, from_below, teardrop=) (a teardrop for a pocket in a side face), the disc magnet table (3x1 to 20x3), magnet_interface |
the zippo magnet experiment |
rails |
slide_rail(length, device_t, lip, back_stop, fit, screws, window, hand) |
container_store_mounts rail() |
joints |
PanelGroove, WallScrews, LipJoint, TongueGroove (a rim seal: groove, tongue and a printable TPU gasket round any rounded-rectangle outline): each makes both sides of the joint; SnapPeg(d, h, barb, release): a split peg and its socket that snap together and hold when you pick the parts up (stacking trays, lids), with the prongs' bending strain checked so a peg too short for its barb is refused; mate(outline, fit, clear): a part and its hole from one 2D outline, the clearance on the hole, the part or both |
trench, inky / Pi Zero side screws, battery_box lips |
clips |
u_clip, round_clip(d, wall, length, fit, opening / opening_angle, plate), pole_bore(d, depth, fit, end=open/flat/cone, teardrop_up, cap, lead) (the socket a pole slides into; a cone roofs one printed mouth down, a teardrop one lying down; lead chamfers the mouth) and pole_interface |
cr-v / wall-broom clip, cable clip, Relic XR2 clip |
hinges |
SnapPivot(d, length, taper, fit, snap): a tapered peg and its socket with an entry slot (narrowed by snap for a click), for hinges and latches printed without pins; .peg(axis), .socket(axis, slot, slot_len), orient. For pinned ones: lug_profile(axis, r, top, drop) (a lug or knuckle standing out of a wall round a pin, its underside at 45° so it prints without support), hinge_pin(d, length, flat) (a printed pin that lies on a flat; an M-screw of the same size fits too), pin_hole(d, length, fit, grip, teardrop) (slides, then grips over the last lug). TiltJoint(tongue_t, cheek_t, lock_r, a0, a1, bolt, fit): a tilting bracket, a tongue between a fork's cheeks on a pivot bolt, locked by a bolt in an arc slot; .cheeks(profile), .cheek_cuts(), .tongue_holes(up), .at(angle, obj), .scale() (an engraved tilt scale on both cheeks), .bolt_length() |
metal pins and screws through printed knuckles |
slices |
slice_z, arrange: split a part into print layers and lay them out; cut(obj, axis, at, keep): keep one side of a plane |
raspberry_pi_5 slicing helpers; the xtool half plate |
interfaces |
find(build.json, id), check_mate(a, b): do two parts' connection records agree? |
nothing: mismatches were found at assembly |
testing |
for project tests (from makerlib.testing import ..., not imported by import makerlib): needs_openscad, render(tmp_path, obj, name, fn), mesh, manifold, sym_diff, overlaps (the volume each pair of an assembly's parts shares), build(recipe, tmp_path, *args), variant(recipe, name) |
the same helpers copied into every project's tests |
recipe |
Recipe: flags, rules, --schema, --all (every params/*.yaml variant), build record, output="{part}" (plain part names for a one-variant, many-part design), params_dir (a second recipe in a project gets its own variant folder), part(..., when=) (parts made only for some variants: a kit's shared base once, one cradle per size), stl_fingerprint (in meshid, standard library only, so tools/repo_check can use it without OpenSCAD) |
init_argparse boilerplate in every project; shell loops over variants |
Conventions
- Millimetres, Z up, parts modelled in print orientation on z = 0; boxes are corner-anchored unless
center=True. - Clearances are total (hole minus part), never per side.
- Cutting tools overshoot what they cut (
OVERSHOOT= 1 mm); joined solids overlap byEPS= 0.01 mm. - Screw, magnet, recess and label tools: entry surface at z = 0, pointing down (a raised label stands up from it);
from_below=True(or.mirror([0,0,1])) for ones from underneath. - Every table value says where it came from:
yours(measured from printed designs) orstd(datasheet, not yet printed).
Fit profiles
Clearances depend on the printer, nozzle and material. Put calibrated values in a file and pass
--fit-profile h2c-pla.yaml (or set MAKERLIB_FIT_PROFILE):
clearance: {slide: 0.20, groove: 0.35}
screws: {M3: {grip_d: 2.65, insert_d: 4.1}}
The build record stores the profile used, so a print can be traced to the clearances it was made with.
Designs built on it
The library grew out of these; each one added the pieces in brackets.
- A screwless rack for Raspberry Pi 5 cases, trays that snap together (
SnapPeg). - A Raspberry Pi 5 case, the reference layout for a design: Poetry,
src/,params/variants, tests,stl/+ build records,scad/ignored by git. - A stand for 1 to 5 lighters (
row,rounded_polygon,prism, optionalmagnet_pocket). - A wall attachment for a bike rack tube, modelled as it prints (
views,screw_hole("#12")). - A label-roll holder in three parts (
mate,flatted_circle,output="{part}"). - Jigs for xTool lasers: base plates (
recess,cut,label,hole), an AirPods case jig (rounded_cuboid,fillet_ring,round_ring,params_dir), an AirTag jig (recess(dome=)), a self-centering jig (arc_slot,fluted_circle) and an ornament jig kit (lathe,part(when=)). - A box you size yourself with a snap-in hinge and flexure latches, no hardware (
SnapPivot,chamfer_ring,sweep_outline). - A rugged case sized from the inside, with ribs, a sealed rim, a pinned hinge, clip latches, a
padlock tab and a handle (
TongueGroove,lug_profile,hinge_pin,pin_hole,label). - A Starlink antenna mount: a tilt head with a scale, a swivel and wall brackets, all printed
without supports (
TiltJoint,arc_scale,ring_slot,pole_bore,teardrop,bolt_length). - A wall mount a trekking pole's own clip snaps into (
pole_bore,tube_window,head_fits). - A screw-together AirTag case (
Thread,chamfered_cylinder(ridges=),rounded_cylinder,AIRTAGS).
Development
poetry install
poetry run pytest # building-block sizes and volumes, joints that fit at their clearance
# and collide without it, threads that mesh, the recipe CLI
poetry run ruff check src tests
Needs openscad on the PATH for the rendering tests (they skip without it).