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.2.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.2.tar.gz.

File metadata

File hashes

Hashes for mechanical_tolerance_calculator-0.1.2.tar.gz
Algorithm Hash digest
SHA256 a10d5742ba5d0afe48c8a160255c0bb63935cc33e21d11eb2f0adbd63ab6504b
MD5 b167e76e6ba1e98daf86eff03626a939
BLAKE2b-256 a1e60700acd6cef98fc7d186d1b3f2c2c003440a571a0e1a4f19be6fe40bc437

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for mechanical_tolerance_calculator-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ebcf013de2a5480d1ef88863d707eab96bc4f305592f0840214d6bdc1fb73ca9
MD5 688b22ac509b40f9e4dcd1f038fd7b6c
BLAKE2b-256 5bbaaf9fb8ef4565bb65efc80733841293cbf9f4d633fc6e6a6c12aacfe6a1e6

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