{"id":5078,"library":"tempora","title":"Tempora","description":"Tempora is a Python library by `jaraco` providing a collection of objects and routines pertaining to date and time. It offers utilities and constants in its top-level package, routines for measuring and profiling in the `timing` module, an event scheduler in `schedule`, and functionalities for handling datetime-aware UTC values in `utc`. The library is currently at version 5.8.1 and maintains a regular release cadence with frequent updates.","status":"active","version":"5.8.1","language":"en","source_language":"en","source_url":"https://github.com/jaraco/tempora","tags":["date-time","timing","scheduling","utc","utilities"],"install":[{"cmd":"pip install tempora","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Used for various collection utilities.","package":"jaraco.collections","optional":false},{"reason":"Provides additional functional programming tools.","package":"jaraco.functools","optional":false}],"imports":[{"note":"Module for measuring and profiling time.","symbol":"timing","correct":"from tempora import timing"},{"note":"Module for event scheduling.","symbol":"schedule","correct":"from tempora import schedule"},{"note":"Module for UTC datetime utilities.","symbol":"utc","correct":"from tempora import utc"},{"symbol":"timing.Stopwatch","correct":"from tempora.timing import Stopwatch"},{"symbol":"schedule.Scheduler","correct":"from tempora.schedule import Scheduler"},{"symbol":"utc.now","correct":"from tempora.utc import now"}],"quickstart":{"code":"import datetime\nfrom tempora.timing import Stopwatch\nfrom tempora.schedule import Scheduler\nfrom tempora.utc import now\n\n# Example using Stopwatch\nwith Stopwatch() as sw:\n    sum(range(10000))\nprint(f\"Summing range took: {sw.elapsed} seconds\")\n\n# Example using utc.now()\nutc_time = now()\nprint(f\"Current UTC time: {utc_time}\")\n\n# Example using Scheduler (basic usage - requires a running event loop)\ndef my_task():\n    print(f\"Task executed at {now()}\")\n\nscheduler = Scheduler()\nscheduler.add_event(my_task, datetime.timedelta(seconds=1))\nprint(\"Scheduler created to run a task after 1 second. (This example doesn't run the event loop).\")\n","lang":"python","description":"Demonstrates basic usage of `tempora.timing.Stopwatch` for measuring execution time, `tempora.utc.now()` for getting current UTC time, and adding a simple task to `tempora.schedule.Scheduler`."},"warnings":[{"fix":"Ensure `tempora` modules are reloaded or re-imported within the `freezegun` context, or mock `tempora.utc.now` directly.","message":"When using testing libraries like `freezegun`, `tempora.utc.now()` might not reflect the 'frozen' time. This is because `freezegun` patches `datetime.datetime`, and if `tempora.utc.now()` or other `tempora` functions obtain a handle to `datetime.datetime` before `freezegun`'s context is entered, they will use the original, unfrozen time.","severity":"gotcha","affected_versions":"All versions where `freezegun` is used without explicit re-import or reload."},{"fix":"Migrate your timezone handling code to use `datetime.timezone.utc` or `zoneinfo.ZoneInfo`. If compatibility with older Python versions (pre-3.9) is required, consider `backports.zoneinfo` or `python-dateutil` while being aware of their interaction with `tempora`.","message":"The library has moved away from `pytz` for timezone handling in favor of `zoneinfo` (standard library module from Python 3.9+). While `tempora` has ported this functionality, direct reliance on `pytz`-specific behaviors or imports like `pytz.UTC` might lead to incorrect results or deprecation warnings in other contexts. Always prefer `datetime.timezone.utc` or `zoneinfo.ZoneInfo` for modern Python development with time zones.","severity":"breaking","affected_versions":"Users migrating from older systems or integrating with libraries still using `pytz` might be affected. Python 3.9+ is recommended for `zoneinfo` support."},{"fix":"Implement a mechanism to run the scheduler's event loop, such as `scheduler.run_forever()` in a separate thread, or integrate it with your application's existing event loop.","message":"The `tempora.schedule.Scheduler` currently does not automatically run its event loop. To execute scheduled tasks, you need to explicitly run the scheduler's event loop, typically in a dedicated thread or by integrating it with an existing event loop (e.g., `asyncio`). The provided quickstart only sets up the schedule but does not run it.","severity":"gotcha","affected_versions":"All versions up to 5.8.1"}],"env_vars":null,"last_verified":"2026-04-12T00:00:00.000Z","next_check":"2026-07-11T00:00:00.000Z"}