Install & Compatibility
Where this runs
tested against v1.1.10 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 17.8MB
glibcpy 3.10–3.95 runs
installs and imports cleanly · install 1.5s · import 0.000s · 18MB
16MB installed
● package 16MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
freeze_time
✓ from freezegun_stubs import freeze_time
✗ from freezegun-stubs import freeze_time
Demonstrates basic usage of `freezegun` with `freeze_time` as a decorator and context manager. `types-freezegun` provides the necessary type hints for static analysis of such code.
import datetime
from freezegun import freeze_time
# Example using the decorator
@freeze_time("2023-01-01")
def demonstrate_decorator_freeze():
assert datetime.datetime.now() == datetime.datetime(2023, 1, 1)
print(f"Current time (decorator): {datetime.datetime.now()}")
demonstrate_decorator_freeze()
# Example using the context manager
with freeze_time("2024-02-29 10:30:00"):
assert datetime.date.today() == datetime.date(2024, 2, 29)
assert datetime.datetime.now().hour == 10
print(f"Current date (context manager): {datetime.date.today()}")
# To verify type checking, run a tool like Mypy (e.g., `mypy your_script.py`)
# with `types-freezegun` installed. It will ensure `freeze_time` and
# related objects are used with correct types.
Debug
Known issues
breaking`types-freezegun` is deprecated and should be uninstalled if you are using `freezegun` version 1.2.1 or newer. `freezegun` now includes its own type annotations directly within the package, rendering these external stubs redundant.fixIf `freezegun >= 1.2.1`, uninstall `types-freezegun` (e.g., `pip uninstall types-freezegun`). If using an older `freezegun` version, ensure `types-freezegun` is compatible with it.
affects: < 1.2.1 of `freezegun`
gotchaMismatched versions of `freezegun` and `types-freezegun` can lead to incorrect or incomplete type checking results. While `typeshed` aims for compatibility, newer features or breaking changes in `freezegun` might not be immediately reflected in older `types-freezegun` stubs, or vice-versa.fixAlways check for compatibility, especially if type checking errors appear after updating one of the packages. The most reliable fix is to migrate to `freezegun >= 1.2.1` and uninstall `types-freezegun`.
affects: All versions where `types-freezegun` is used with `freezegun`.
gotchaWhen `freezegun` is active, `datetime.datetime.now()` returns `FakeDatetime` objects, which inherit from `datetime.datetime` but are not strictly identical. Libraries or code performing strict type checks (e.g., `type(obj) is datetime.datetime`) rather than `isinstance(obj, datetime.datetime)` might encounter runtime errors or unexpected behavior, even if type checking passes.fixAvoid strict type equality checks (`type(obj) is expected_type`) with objects manipulated by `freezegun`. Prefer `isinstance(obj, expected_type)` for broader compatibility. Review any third-party library integrations that might perform such strict checks.
affects: All versions of `freezegun` and `types-freezegun`.
Upgrade
Version history
1.1.10latest on PyPI · released Jun 9, 2022
Audit
Dependencies
freezegunrequiredProvides the runtime functionality for which these are type stubs.