# Convert a speed value between millimetres per second and per minute
Save this Python program as speed_units.py to convert a supplied speed between mm/s and mm/min. It accepts non-negative values and runs on your computer.
Contents
# Run the conversion
Use python3 speed_units.py VALUE --from-unit UNIT --to-unit UNIT. Each unit must be mm/s or mm/min. Read the output as a number followed by its unit.
Conversion from mm/s to mm/min multiplies by 60. Conversion in the opposite direction divides by 60. If both unit flags are the same, the number remains unchanged.
# Inputs and rounding
The converter accepts finite, non-negative decimal values. It rejects more than 100 digits and values whose adjusted exponent is outside -100 to 100. The calculations use Python Decimal with 110 digits of precision; division can round a repeating result.
Use the result to express your supplied speed in the other unit. It does not choose a setting for a machine, evaluate a material or make a safety judgement.
# Publisher
CutChart publishes this speed-unit converter. Keep the complete source and its MIT license together when copying it.
Source record: Speed unit converter; publisher: CutChart; publication date: undated authored software, copyright 2026; source: complete original Python below.
# Complete Python source
#!/usr/bin/env python3
"""Convert a non-negative speed between mm/s and mm/min."""
import argparse
from decimal import Decimal, InvalidOperation, localcontext
def convert(value, source, destination):
number = Decimal(value)
if not number.is_finite() or number < 0:
raise ValueError("Speed must be a finite, non-negative number.")
if source not in ("mm/s", "mm/min") or destination not in ("mm/s", "mm/min"):
raise ValueError("Choose mm/s or mm/min.")
if len(number.as_tuple().digits) > 100 or abs(number.adjusted()) > 100:
raise ValueError("Use at most 100 digits and an exponent between -100 and 100.")
with localcontext() as ctx:
ctx.prec = 110
if source == destination:
return number
return number * 60 if source == "mm/s" else number / 60
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("value", help="Non-negative speed")
parser.add_argument("--from-unit", required=True, choices=("mm/s", "mm/min"))
parser.add_argument("--to-unit", required=True, choices=("mm/s", "mm/min"))
args = parser.parse_args()
try:
result = convert(args.value, args.from_unit, args.to_unit)
except (InvalidOperation, ValueError) as exc:
parser.error(str(exc))
print(f"{result} {args.to_unit}")
if __name__ == "__main__":
main()
# License
MIT License
Copyright (c) 2026 CutChart
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.