CAD primitives to produce images and drawings in a variety of formats from a common symbolic definition.
cadlib is a 2D CAD geometry library written in Python. It models manual drafting workflows: constructing geometry by creating points, lines, circles, and arcs, then using transformations (mirror, rotate) to build complex shapes.
pip install cadlibimport cadlib
# Create geometry
center = cadlib.Point(0, 0)
circle = cadlib.Circle(center, 10)
line = cadlib.Line(cadlib.Point(-15, 5), cadlib.Point(15, 5))
# Find intersections
pt = circle.point_at_line_intersection(line, q=1)
# Use transformations
mirrored = line.mirror_x(0)
rotated = line.rotate(center, 45)cadlib includes a sprocket generator implementing ANSI standard sprocket geometry per the gearseds design specification.
# Generate SVG
cadlib-sprocket svg
# Display with matplotlib
cadlib-sprocket matplotlibOr use it programmatically:
from cadlib.sprocket import Sprocket, create_svg, create_matplotlib
sprocket = Sprocket(ansi_chain_type="25", n_number_of_teeth=8)
create_svg(sprocket)Point(x, y)-- 2D point with mirror and rotate transformationsLine(p1, p2)-- line segment between two pointsCircle(center, radius)-- circle with intersection and tangency methodsArc(center, radius, angle1, angle2)-- arc defined by center, radius, and angle range
arc_from_points_and_radius(p1, p2, r, q)-- arc from two points and radiusarc_from_points_and_center(p1, p2, center)-- arc from two points and centerarc_from_points_and_radius_and_height(p1, p2, height)-- arc from chord and heightline_from_pt_angle_len(point, angle, length)-- line from point, angle, length
Layer-- groups elements for rendering controlDrawing-- collection of elements with coordinate transforms for outputLAYER_CONSTRUCTION-- default layer for construction guides (gray)LAYER_TOOLPATH-- layer for cutting/tool paths (red)
MIT