yapcad.fasteners package

Submodules

yapcad.fasteners.builders module

Fastener construction using catalog data.

This module builds fasteners using dimensions from YAML catalogs, delegating to the core thread generation in yapcad.threadgen.

yapcad.fasteners.builders.build_hex_bolt_from_catalog(thread_series: str, size: str, length: float, tolerance_class: str = '6g', thread_length: float | None = None, starts: int = 1, thread_arc_samples: int = 180, thread_samples_per_pitch: int = 6, catalog_path: Path | None = None)[source]

Build a hex bolt using catalog dimensions.

Parameters:
  • thread_series – “metric_coarse”, “unified_coarse”, etc.

  • size – Size designation from catalog

  • length – Shank length in mm

  • tolerance_class – Thread tolerance class

  • thread_length – Thread length in mm (or computed if None)

  • starts – Number of thread starts

  • thread_arc_samples – Angular samples for thread surface

  • thread_samples_per_pitch – Profile samples per pitch

  • catalog_path – Optional custom catalog path

Returns:

yapCAD solid representing the bolt

yapcad.fasteners.builders.build_hex_nut_from_catalog(thread_series: str, size: str, tolerance_class: str = '6H', handedness: str = 'right', starts: int = 1, thread_arc_samples: int = 180, thread_samples_per_pitch: int = 6, catalog_path: Path | None = None)[source]

Build a hex nut using catalog dimensions.

Parameters:
  • thread_series – “metric_coarse”, “unified_coarse”, etc.

  • size – Size designation from catalog

  • tolerance_class – Thread tolerance class

  • handedness – “right” or “left”

  • starts – Number of thread starts

  • thread_arc_samples – Angular samples for thread surface

  • thread_samples_per_pitch – Profile samples per pitch

  • catalog_path – Optional custom catalog path

Returns:

yapCAD solid representing the nut

yapcad.fasteners.catalog module

Fastener catalog loading with bundled data and external override support.

This module provides a flexible catalog system for fastener dimensions: - Bundled YAML data files for common metric and unified sizes - Environment variable override for custom data directories - User config directory support (~/.config/yapcad/fasteners/) - Explicit path override in API calls

Environment Variables:
YAPCAD_FASTENER_DATA: Colon-separated (or semicolon on Windows) paths

to directories containing custom YAML catalog files. These are searched before bundled data.

Example

export YAPCAD_FASTENER_DATA=”/path/to/my/fasteners:/another/path”

yapcad.fasteners.catalog.clear_cache() None[source]

Clear all cached catalog data.

Call this if you modify external catalog files and want to reload.

yapcad.fasteners.catalog.get_bolt_data(thread_series: str, size: str, tolerance_class: str = '6g', custom_path: Path | None = None) Dict[str, Any][source]

Get complete data for creating a hex bolt.

Parameters:
  • thread_series – Thread series name

  • size – Size designation

  • tolerance_class – Thread tolerance class (default “6g” for metric)

  • custom_path – Optional custom catalog path

Returns:

  • thread: dict with diameter, pitch, tolerances

  • head: dict with width_across_flats, height, etc.

Return type:

Dict with all data needed to create a bolt

Raises:

KeyError – If size not found or no bolt data available

yapcad.fasteners.catalog.get_nut_data(thread_series: str, size: str, tolerance_class: str = '6H', custom_path: Path | None = None) Dict[str, Any][source]

Get complete data for creating a hex nut.

Parameters:
  • thread_series – Thread series name

  • size – Size designation

  • tolerance_class – Thread tolerance class (default “6H” for metric internal)

  • custom_path – Optional custom catalog path

Returns:

  • thread: dict with diameter, pitch, tolerances

  • body: dict with width_across_flats, thickness, etc.

Return type:

Dict with all data needed to create a nut

Raises:

KeyError – If size not found or no nut data available

yapcad.fasteners.catalog.get_thread_data(thread_series: str, size: str, tolerance_class: str | None = None, custom_path: Path | None = None) Dict[str, Any][source]

Get thread dimension data for a specific size.

Parameters:
  • thread_series – Thread series name

  • size – Size designation (e.g., “M8”, “1/4-20”)

  • tolerance_class – Optional tolerance class to validate exists

  • custom_path – Optional custom catalog path

Returns:

  • nominal_diameter: float (mm)

  • pitch: float (mm)

  • basic_minor_diameter: float (mm)

  • basic_pitch_diameter: float (mm)

  • tolerances: dict of tolerance class data

  • hex_bolt: dict of bolt head dimensions (if present)

  • hex_nut: dict of nut dimensions (if present)

Return type:

Dict with thread dimensions

Raises:

KeyError – If size or tolerance_class not found

yapcad.fasteners.catalog.list_available_sizes(thread_series: str, custom_path: Path | None = None) List[str][source]

List all available sizes for a thread series.

Parameters:
  • thread_series – Thread series name

  • custom_path – Optional custom catalog path

Returns:

List of size strings (e.g., [“M3”, “M4”, “M5”, …])

yapcad.fasteners.catalog.list_tolerance_classes(thread_series: str, custom_path: Path | None = None) List[str][source]

List available tolerance classes for a thread series.

Parameters:
  • thread_series – Thread series name

  • custom_path – Optional custom catalog path

Returns:

List of tolerance class strings (e.g., [“6g”, “6H”, “4g6g”])

yapcad.fasteners.catalog.load_catalog(thread_series: str, custom_path: Path | None = None) Dict[str, Any][source]

Load fastener catalog for a thread series.

Parameters:
  • thread_series – One of “metric_coarse”, “metric_fine”, “unified_coarse”, “unified_fine”

  • custom_path – Optional explicit path to YAML file (overrides search)

Returns:

  • schema_version: str

  • standard: str (e.g., “ISO 262”)

  • thread_series: str

  • tolerance_classes: dict of class definitions

  • sizes: dict of size data

  • _source_path: str (path catalog was loaded from)

Return type:

Parsed catalog dictionary containing

Raises:
  • FileNotFoundError – If no catalog found for the series

  • ValueError – If catalog has invalid format

Search order (unless custom_path specified):
  1. $YAPCAD_FASTENER_DATA directories

  2. ~/.config/yapcad/fasteners/

  3. Bundled data

Module contents

Fastener generation with catalog-based dimensions.

This package provides parametric fastener generation (hex bolts, hex nuts) with dimensions from YAML catalog files. Bundled catalogs cover common metric (ISO) and unified (ASME) sizes; users can extend with custom catalogs.

Quick Start:
>>> from yapcad.fasteners import metric_hex_bolt, metric_hex_nut
>>> bolt = metric_hex_bolt("M8", 25.0)
>>> nut = metric_hex_nut("M8")
Available Functions:
Metric (ISO):

metric_hex_bolt(size, length, tolerance_class=”6g”) metric_hex_nut(size, tolerance_class=”6H”)

Unified (ASME):

unified_hex_bolt(size, length, tolerance_class=”2A”) unified_hex_nut(size, tolerance_class=”2B”)

Catalog Customization:

Set YAPCAD_FASTENER_DATA environment variable to add custom catalog directories. These are searched before bundled data.

Example:

export YAPCAD_FASTENER_DATA=”/path/to/my/fasteners”

See docs/fastener_catalog_schema.md for YAML format specification.