time-machine
Travel through time in your tests.
Decision gist · record as of 2026-08-14
Yes. time-machine is a mature, actively maintained testing tool with no security vulnerabilities, permissive licensing, and broad platform support. It solves a common testing problem—controlling time—cleanly and with zero runtime dependencies. Install it if you write tests for time-dependent code.AI-flagged interpretation of the facts on this page — verify before relying
Before you install
- Requires Python 3.10 or later; compiled wheels available for common platforms but may require compilation on unsupported architectures.
- Medium install friction due to compiled wheels across multiple platforms and Python versions, but actively maintained with a release 4 days old and no known vulnerabilities.
License · maintenance · safety
MIT (permissive) — MIT license permits unrestricted use, modification, and distribution in both open-source and commercial projects with minimal obligations.
last release 2026-08-10 (4 days) · last repo commit 2026-08-12 · 991 stars
0 known vulnerabilities (OSV.dev, 2026-08-14) · 23,451,487 downloads/mo, #945 on PyPI
Alternatives
Verify before relying
pip install time-machine
import time_machine
from datetime import datetime
with time_machine.travel(datetime(2020, 5, 4)):
print(datetime.now())- Whether time-machine integrates with all major testing frameworks beyond pytest, or if pytest is the primary target.
- Performance characteristics when freezing time across long test suites or with frequent time transitions.
- Exact Python version support range beyond the classifiers listed (3.10 through 3.15 claimed in classifiers).
What it is and what it does
time-machine is a testing utility that lets you mock the system clock and datetime in your tests by traveling to any point in time. Instead of mocking individual datetime calls or using sleep-based delays, you wrap test code in a context manager that freezes or advances time globally, making it simple to test time-dependent logic without waiting for real time to pass.
The package is production-stable, actively maintained, and widely used in the top 1000 on PyPI. It has no runtime dependencies and supports modern Python versions starting from 3.10. Compiled wheels are available for most common platforms, though installation may require compilation on less common architectures.
Use it for
- Test code that checks expiration dates, timeouts, or scheduled tasks without waiting for real time to elapse.
- Verify behavior at specific dates and times such as leap years or timezone transitions.
- Simulate long-running processes or retry logic with exponential backoff in milliseconds instead of seconds.
- Test time-based caching or rate-limiting logic by advancing the clock deterministically.
- Validate logging or audit trails that depend on timestamps without relying on system clock accuracy.
Worth the install?
AI-flagged interpretation of the facts on this page. Verify before relying on it.
Yes.
time-machine is a mature, actively maintained testing tool with no security vulnerabilities, permissive licensing, and broad platform support. It solves a common testing problem—controlling time—cleanly and with zero runtime dependencies. Install it if you write tests for time-dependent code.
Install
time-machine on PyPI
Before you install
Medium install friction due to compiled wheels across multiple platforms and Python versions, but actively maintained with a release 4 days old and no known vulnerabilities.
Requires Python 3.10 or later; compiled wheels available for common platforms but may require compilation on unsupported architectures.
License in practice
MIT license permits unrestricted use, modification, and distribution in both open-source and commercial projects with minimal obligations.
Quickstart
pip install time-machine
import time_machine
from datetime import datetime
with time_machine.travel(datetime(2020, 5, 4)):
print(datetime.now())
Verify before relying
- Whether time-machine integrates with all major testing frameworks beyond pytest, or if pytest is the primary target.
- Performance characteristics when freezing time across long test suites or with frequent time transitions.
- Exact Python version support range beyond the classifiers listed (3.10 through 3.15 claimed in classifiers).
Package facts
| License | MIT permissive |
| Python support | Supports the current Python release >=3.10 |
| Install friction | Medium. Platform-specific wheel |
| Runtime dependencies | None |
| Maintenance | Actively maintained 4 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 23,451,487 / month, #945 on PyPI 30-day window, as of 2026-08-14 |
| Known vulnerabilities | None known OSV.dev, checked 2026-08-14 |
| Classifiers | Development Status :: 5 - Production/StableFramework :: PytestIntended Audience :: DevelopersNatural Language :: EnglishOperating System :: OS IndependentProgramming Language :: Python :: 3 :: OnlyProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Programming Language :: Python :: 3.15Typing :: Typed |
Evidence: time_machine-3.4.0-cp310-cp310-macosx_10_9_x86_64.whl; time_machine-3.4.0-cp310-cp310-macosx_11_0_arm64.whl; time_machine-3.4.0-cp310-cp310-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl; time_machine-3.4.0-cp310-cp310-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl; time_machine-3.4.0-cp310-cp310-musllinux_1_2_aarch64.whl; time_machine-3.4.0-cp310-cp310-musllinux_1_2_x86_64.whl; time_machine-3.4.0-cp310-cp310-win_amd64.whl; time_machine-3.4.0-cp310-cp310-win_arm64.whl; time_machine-3.4.0-cp311-cp311-macosx_10_9_x86_64.whl; time_machine-3.4.0-cp311-cp311-macosx_11_0_arm64.whl; time_machine-3.4.0-cp311-cp311-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl; time_machine-3.4.0-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl; time_machine-3.4.0-cp311-cp311-musllinux_1_2_aarch64.whl; time_machine-3.4.0-cp311-cp311-musllinux_1_2_x86_64.whl; time_machine-3.4.0-cp311-cp311-win_amd64.whl; time_machine-3.4.0-cp311-cp311-win_arm64.whl; time_machine-3.4.0-cp312-cp312-macosx_10_13_x86_64.whl; time_machine-3.4.0-cp312-cp312-macosx_11_0_arm64.whl; time_machine-3.4.0-cp312-cp312-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl; time_machine-3.4.0-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Tags
Let your AI agent find packages like this
Example. Real query, live index.
You found this page by searching. An agent finds it by wishing: SkillFed indexes 14,416 PyPI packages by what they can do, searchable in plain language.
wish › “mock time in tests”
- time-machineMocks and freezes time in tests, allowing you to travel to any point…
- freezegunFreezeGun mocks Python's datetime and time modules to let tests run…
- testfixturesTestfixtures provides helpers and mock objects for writing unit and…
Give your agent the search over MCP, or paste the wish link into any chat.
More Testing packages
Pluggy provides a plugin system that lets you define hook specifications and register implementations to be called in sequence, enabling extensible Python applications without tight coupling.
Install it if you're building an extensible application or framework.
pytest is a testing framework that lets you write test functions using plain assert statements and automatically discovers and runs them, with detailed failure reporting.
virtualenv creates isolated Python environments where packages can be installed independently without affecting the system Python or other projects.
Coverage.py measures which lines of Python code are executed during test runs, reporting coverage percentages and identifying untested code paths.
Install it if you want to measure test completeness or enforce coverage thresholds in your project.
pytest-asyncio is a pytest plugin that enables writing and running async test functions using the asyncio library, allowing developers to await code directly within test cases.
Install it if you write tests for any asyncio-based code.
A pytest plugin that generates test reports in Common Test Report Format (CTRF) as JSON, compatible with pytest-xdist and pytest-playwright for distributed and browser-based testing.
Install it if you need CTRF-formatted test output for CI/CD integration or cross-tool reporting.
See also freezegun · looptime · pytest-freezer · pytest-freezegun · testfixtures · freeze-uuid · asyncmock · mocket · pytest-mock · pytest-responses