{"id":10269,"library":"stopwatch-py","title":"A Simple Python Stopwatch","description":"stopwatch-py is a lightweight Python library providing a simple stopwatch functionality to measure elapsed time. It is currently at version 2.0.1 and has a low release cadence, primarily focusing on minor improvements and maintenance.","status":"active","version":"2.0.1","language":"en","source_language":"en","source_url":"https://github.com/ravener/stopwatch.py","tags":["stopwatch","timer","utility","time measurement"],"install":[{"cmd":"pip install stopwatch-py","lang":"bash","label":"Install latest version"}],"dependencies":[],"imports":[{"note":"As of v2.0.1, the library was refactored into a single-file module, removing the submodule structure.","wrong":"from stopwatch.stopwatch import Stopwatch","symbol":"Stopwatch","correct":"from stopwatch import Stopwatch"}],"quickstart":{"code":"from stopwatch import Stopwatch\nimport time\n\ns = Stopwatch() # Starts automatically on creation\nprint(f\"Stopwatch started. Elapsed: {s.duration:.2f}s\")\n\ntime.sleep(1.5)\nprint(f\"After 1.5s, Elapsed: {s.duration:.2f}s\")\n\ns.stop()\nprint(f\"Stopwatch stopped. Elapsed: {s.duration:.2f}s\")\n\ntime.sleep(0.5)\nprint(f\"After 0.5s while stopped, Elapsed: {s.duration:.2f}s (should be same)\")\n\ns.start() # Resume\ntime.sleep(0.75)\nprint(f\"After resuming for 0.75s, Total Elapsed: {s.duration:.2f}s\")\n\ns.reset() # Reset to 0 and stop\nprint(f\"Stopwatch reset. Elapsed: {s.duration:.2f}s\")","lang":"python","description":"Initializes a stopwatch, measures time, stops and resumes, then resets it."},"warnings":[{"fix":"Separate method calls. Instead of `s.stop().duration`, use `s.stop(); print(s.duration)`.","message":"Methods `start()`, `stop()`, `reset()`, `restart()` no longer return `self`. This change in v2.0.0 breaks method chaining.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Ensure your Python environment is 3.5 or newer. If you must use an older Python version, pin `stopwatch-py<2.0.0`.","message":"The minimum required Python version increased from Python 3.0 to Python 3.5 due to the introduction of type hints in v2.0.0.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Remove any references to `stopwatch.__github__` from your code.","message":"The internal `__github__` constant was removed in v2.0.1. While this was not intended to break user code, any specific reliance on this internal constant will now fail.","severity":"gotcha","affected_versions":">=2.0.1"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"Separate the method calls: `s.stop(); print(s.duration)`.","cause":"Attempting to chain methods like `s.stop().duration` after upgrading to v2.0.0+. Methods `start()`, `stop()`, `reset()`, `restart()` no longer return `self`.","error":"AttributeError: 'NoneType' object has no attribute 'duration'"},{"fix":"Upgrade your Python interpreter to version 3.5 or newer, or downgrade the library to `pip install stopwatch-py==1.x`.","cause":"Running `stopwatch-py` v2.0.0+ on Python versions older than 3.5, which do not support the introduced type hints.","error":"SyntaxError: invalid syntax (often pointing to type hints) or ModuleNotFoundError: No module named 'stopwatch'"},{"fix":"Update your import statement to `from stopwatch import Stopwatch`.","cause":"Attempting to import `Stopwatch` from a submodule path (`stopwatch.stopwatch`) which was used in earlier versions. As of v2.0.1, it's a single-file module.","error":"ImportError: cannot import name 'Stopwatch' from 'stopwatch.stopwatch' (.../stopwatch/stopwatch.py)"}]}