Skip to main content

A Python package for material tolerance calculations

Project description

Tolerances Package

A Python package for material tolerance calculations, converted from the original JavaScript npm package.

Installation

From PyPI (once published)

pip install mechanical_tolerance_calculator

From source

git clone https://github.com/AjayGhimire1998/mechanical_tolerance_calculator.git
cd mechanical_tolerance_calculator
pip install -e .

Usage

from tolerances import (
    get_all_tolerances_for,

    check_one_measurement_for,
    check_multiple_measurements_for
)

# Get all tolerances for a material type
housing_tolerances = get_all_tolerances_for("housing")
shaft_tolerances = get_all_tolerances_for("shaft")
shell_tolerances = get_all_tolerances_for("shell")



# Check a single measurement
result = check_one_measurement_for("shaft", 5.98)
print(result)
# Output includes:
# - measurement: the input measurement
# - nominal: calculated nominal diameter
# - specification: the specification used (e.g., "h9")
# - IT_grade: the IT grade used
# - computed_specification_bounds: upper and lower bounds
# - meets_specification: whether the measurement meets specs
# - meets_IT_tolerance: whether it meets IT tolerance

# Check multiple measurements
measurements = [5.97, 5.98, 5.99, 6.00]
result = check_multiple_measurements_for("shaft", measurements)
print(result)
# Output includes all the above plus:
# - meets_IT_Tolerance: whether measurements meet IT tolerance
# - meets_final_compliance: overall compliance status

API Reference

get_all_tolerances_for(material_type: str) -> dict

Returns all tolerances for the given material type.

Parameters:

  • material_type (str): The type of material. Valid values: 'housing', 'shaft', 'shell'

Returns:

  • dict: Object containing the relevant tolerances or an error message

Example:

tolerances = get_all_tolerances_for("housing")

check_one_measurement_for(material_type: str, measurement: float) -> dict

Check a single measurement against standard tolerances.

Parameters:

  • material_type (str): The type of material. Valid values: 'housing', 'shaft', 'shell'
  • measurement (float): The measured value to check

Returns:

  • dict: Detailed analysis including specification bounds and compliance status

Example:

result = check_one_measurement_for("shaft", 5.98)
if result.get("meets_IT_tolerance"):
    print("Measurement passes!")

check_multiple_measurements_for(material_type: str, measurements: list) -> dict

Check multiple measurements against standard tolerances.

Parameters:

  • material_type (str): The type of material. Valid values: 'housing', 'shaft', 'shell'
  • measurements (list): A list of measured values to check

Returns:

  • dict: Comprehensive analysis of all measurements including IT tolerance compliance

Example:

measurements = [5.97, 5.98, 5.99, 6.00]
result = check_multiple_measurements_for("shaft", measurements)
if result.get("meets_final_compliance"):
    print("All measurements pass!")

Material Types

The package supports three material types:

  1. Housing - Uses H8 specification (IT6 grade)
  2. Shaft - Uses h9 specification (IT5 grade)
  3. Shell - Uses H9 specification (IT6 grade)

Data Format

The package requires a Tolerances.json file with the following structure:

{
  "housingBores": {
    "H8": {
      [
        {
          "minimum_diameter": 0,
          "maximum_diameter": 3,
          "upper_deviation": "0.014",
          "lower_deviation": "0.000",
          "IT6": 0.006
        }
      ]
    }
  },
  "shafts": {
    "h9": {
      [...]
    }
  },
  "shellBores": {
    "H9": {
      [...]
    }
  }
}

License

MIT License

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Support

For issues and questions, please open an issue on GitHub.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mechanical_tolerance_calculator-0.1.3.tar.gz (3.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file mechanical_tolerance_calculator-0.1.3.tar.gz.

File metadata

File hashes

Hashes for mechanical_tolerance_calculator-0.1.3.tar.gz
Algorithm Hash digest
SHA256 177064050dd2b468d451f4507aba17a17cf7377be9b9c6aaa0b35d3f0c3000a0
MD5 1e614759442059de485a2834bc6e95e2
BLAKE2b-256 224b7e58e2243bb1f8f8ff84f96b064651915e65bff9e9456e83567b15f5e575

See more details on using hashes here.

File details

Details for the file mechanical_tolerance_calculator-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for mechanical_tolerance_calculator-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 f690c67a2ede10835e2136652120679b1dfe6bfa28670f518e1401a1faf9fa4f
MD5 d23c35fd61e2786e825063776877c119
BLAKE2b-256 fc09dec701079bf016e113ef296cd20bf7449a33c038d55b3bf9ae421e3852ea

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page