shaft_key - keys and keyways
Shaft keys transmit torque between a shaft and a mounted component such as a gear, pulley, or coupling. The key occupies matching longitudinal recesses in the shaft and hub so that the components rotate together.
The shaft_key module initially provides DIN 6885-1 parallel keys and matching
shaft or hub keyway cutters. Its dimensional data covers the nominal shaft diameters
from 6 mm through 50 mm listed in the available DIN 6885-1 extract.
Creating Parallel Keys
DIN 6885-1 selects the nominal key width and height from the shaft diameter. Key
length depends on the hub length and required torque capacity, so it is supplied
explicitly. shaft_diameter may be an integer or an integer-valued float, and
must correspond to one of the millimetre sizes returned by ShaftKey.sizes():
from bd_warehouse.shaft_key import ShaftKey
key = ShaftKey(
shaft_diameter=25,
length=40,
key_form="A",
)
Form A has two rounded ends and Form B has two square ends. The key is centered in XY, extends along the X axis, and has its minimum Z face on the placement plane.
The current implementation accepts any positive length greater than or equal to the key width. It does not yet validate the requested length against the DIN preferred- length series. Key length should be verified for shear and bearing pressure; DIN 6892 covers calculation and design of parallel-key connections.
ShaftKey
ShaftKey creates DIN 6885-1 Form A or Form B parallel-key geometry.
- class ShaftKey(shaft_diameter: int | float, length: float, key_form: ~typing.Literal['A', 'B'] = 'A', rotation: ~build123d.geometry.Rotation | tuple[float, float, float] = (0, 0, 0), align: None | ~build123d.build_enums.Align | tuple[~build123d.build_enums.Align, ~build123d.build_enums.Align, ~build123d.build_enums.Align] = None, mode: ~build123d.build_enums.Mode = <Mode.ADD>)[source]
DIN 6885-1 parallel key for a shaft-hub connection.
Shaft keys transmit torque between a shaft and a mounted component such as a gear, pulley, or coupling. Form A has two rounded ends and Form B has two square ends. DIN 6885-1 selects the nominal width and height from the shaft diameter; the key length is supplied by the caller because it depends on hub length and the required torque capacity. This initial dataset covers the nominal shaft diameters from 6 mm through 50 mm listed in the available DIN 6885-1 extract.
- Parameters:
shaft_diameter – Whole-number nominal shaft diameter in millimetres. An integer or integer-valued float may be supplied.
length – Overall key length in millimetres. The supplied custom length is not validated against the DIN preferred-length series.
key_form –
"A"for rounded ends or"B"for square ends. Defaults to"A".rotation – Sequence of angles about the X, Y, and Z axes. Defaults to
(0, 0, 0).align – Align MIN, CENTER, or MAX of the key. Defaults to None, which keeps the key centered in XY with its minimum Z face on the placement plane.
mode – Combination mode. Defaults to Mode.ADD.
- Raises:
ValueError – The shaft diameter, length, or key form is invalid.
The available shaft diameters and their nominal parameters can be inspected without creating geometry:
sizes = ShaftKey.sizes()
dimensions = ShaftKey.parameters(25)
alternatives = ShaftKey.select_by_size(25)
Keyways
Keyway creates a nominal cutter from a supplied ShaftKey. A shaft cutter
uses the tabulated shaft-keyseat depth t4; a hub cutter uses the tabulated hub-
keyway depth t2. The default placement assumes that the shaft or bore is
centered on Axis.Z. The keyway length is centered on Z and its radial face is placed
at the nominal shaft radius on positive X. A shaft keyway extends inward while a hub
keyway extends outward.
The following example cuts a Form A keyseat into a 25 mm shaft aligned with Axis.Z:
from build123d import Align, BuildPart, Cylinder
from bd_warehouse.shaft_key import Keyway, ShaftKey
key = ShaftKey(shaft_diameter=25, length=20, key_form="A")
with BuildPart() as shaft:
Cylinder(radius=12.5, height=40, align=(Align.CENTER, Align.CENTER, Align.CENTER))
Keyway(key, keyway_type="shaft", fit="Loose")
- class Keyway(key: ~shaft_key.ShaftKey, keyway_type: ~typing.Literal['shaft', 'hub'] = 'shaft', fit: ~typing.Literal['Tight', 'Loose', 'Sliding'] = 'Loose', rotation: ~build123d.geometry.Rotation | tuple[float, float, float] = (0, 0, 0), align: None | ~build123d.build_enums.Align | tuple[~build123d.build_enums.Align, ~build123d.build_enums.Align, ~build123d.build_enums.Align] = None, mode: ~build123d.build_enums.Mode = <Mode.SUBTRACT>)[source]
Nominal keyway cutter for a DIN 6885-1 parallel key.
fitselects the DIN 6885-1 tolerance class for the shaft or hub keyway. ISO 286-1 limit deviations determinemin_widthandmax_width; the cutter is modeled at their midpoint, available aswidth. By default the cutter is positioned for a shaft or bore centered on Axis.Z: its length is centered on Z, its width is centered on Y, and its radial face is located at the nominal shaft radius. Shaft keyways extend inward along negative X; hub keyways extend outward along positive X.- Parameters:
key – Parallel key defining the nominal length, width, and end form.
keyway_type –
"shaft"for a shaft keyseat or"hub"for a hub keyway. Defaults to"shaft".fit – DIN 6885-1 fit selection:
"Tight","Loose", or"Sliding". Defaults to"Loose".rotation – Sequence of angles about the X, Y, and Z axes. Defaults to
(0, 0, 0).align – Align MIN, CENTER, or MAX of the cutter. Defaults to None, which retains the shaft-centered placement.
mode – Combination mode. Defaults to Mode.SUBTRACT.
- Raises:
ValueError – The key, keyway type, or fit is invalid.
Broached Hub Keyways
Keyway.broach_profile() returns the transverse rectangular profile needed to
broach a keyway through a gear, pulley, or other hub. It is available for hub
keyways only:
key = ShaftKey(shaft_diameter=25, length=20)
hub_keyway = Keyway(key, keyway_type="hub", fit="Loose")
profile = hub_keyway.broach_profile()
The profile lies on the XY plane and starts at the shaft axis, X=0. It extends
through the nominal bore radius and a further DIN t2 depth in the positive X
direction. Its ISO-derived width is centered on Y. Extrude the profile directly
along Axis.Z through the hub thickness; no radial positioning calculation is
required.
- Keyway.broach_profile() Face[source]
Return the transverse profile of a broached hub keyway.
The profile lies on the XY plane and extends from the shaft axis at X=0 through the bore to the bottom of the keyway at the nominal shaft radius plus the keyway depth. Its width is centered on the X axis. Extrude the profile along the bore axis without applying a radial offset.
- Raises:
ValueError – If this is not a hub keyway.
Keyway Fits
DIN 6885-1 specifies different ISO 286 width-tolerance classes for the shaft and hub keyways:
Fit |
Hub keyway |
Shaft keyway |
|---|---|---|
Tight |
P9 |
P9 |
Loose |
JS9 |
N9 |
Sliding |
D10 |
H9 |
Users select the descriptive fit value; no knowledge of the ISO designation is
required. The corresponding designation remains available as
Keyway.width_tolerance. Numerical ISO 286-1 limit deviations are exposed as
Keyway.min_width and Keyway.max_width. The cutter is modeled at the midpoint
of those limits, available as Keyway.width, while Keyway.nominal_width
retains the tabulated DIN key width.