skillfed

looptime

Fast-forward asyncio event loop time (in tests)

looptime v0.7 305.1K downloads/30d#7,797 on PyPI41
Permissive license MIT Active released

What it is and what it does

Looptime is a plugin that intercepts asyncio's internal clock, allowing tests to advance time instantly while the event loop sees the full passage. From the loop's perspective, sleeps, timeouts, and delayed callbacks execute in zero real time; from the observer's perspective, a test that would normally take minutes runs in seconds or less. It was originally built for Kopf, a framework for Kubernetes Operators in Python, where it reduced approximately 7000 unit tests to approximately 2 minutes.

The library does not speed up tests that are slow for reasons unrelated to explicit time delays—such as local network I/O, heavy computation, or data processing. It only compacts asyncio-based timing primitives. It works transparently and can be enabled globally or per-test, with no changes to test code itself.

Use it for:

  • Speed up asyncio test suites that use sleeps, timeouts, or rate limiters without breaking time-dependent assertions.
  • Test retry logic, exponential backoff, or other delay-based patterns in near-zero real time.
  • Verify event loop scheduling and callback ordering without waiting for actual delays.
  • Reduce CI/CD pipeline duration for projects with large asyncio test suites.
  • Test long-running background tasks or periodic jobs that would otherwise take minutes per test.

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

Looptime fakes the passage of time in asyncio event loops during tests, allowing time-dependent code to run in near-zero real time while the loop's internal clock advances by configured amounts.

Yes, if you have asyncio-based tests with explicit time delays. Install it for any suite using asyncio that includes sleeps, timeouts, or time-dependent logic—it integrates transparently, has no dependencies, and is actively maintained. Skip it if your tests have no explicit delays or use only synchronous code.

Install

looptime on PyPI

pip

pip install looptime

uv

uv add looptime

poetry

poetry add looptime

Installing looptime

Before you install

Low friction: pure Python wheel with no runtime dependencies. Actively maintained as of 2026-01-03 with recent commits.

License in practice

MIT license permits unrestricted use, modification, and distribution in both open-source and proprietary projects with minimal obligations.

Quickstart

pip install looptime

import asyncio

await asyncio.sleep(100)
assert asyncio.get_running_loop().time() == 100

Requires Python 3.10 or later.

Verify before relying

  • Whether looptime works with all asyncio patterns or only a subset of time-dependent scenarios.
  • Performance impact on very large test suites or tests with many concurrent tasks.
  • Compatibility with third-party asyncio event loop implementations beyond CPython and PyPy.
  • Integration requirements with test frameworks beyond those mentioned in classifiers.

Package facts

License MIT (permissive)
Python support supports the current Python release (>=3.10)
Install friction low — pure-Python wheel
Runtime dependencies none
Maintenance actively maintained — 223 days since the last release
Last repo commit
First released
Downloads 305,147/month — #7,797 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: looptime-0.7-py3-none-any.whl

Keywords: asyncio, event loop, time, python, pytest

Framework :: AsyncIOFramework :: PytestFramework :: aiohttpIntended Audience :: DevelopersOperating System :: OS IndependentProgramming Language :: PythonProgramming Language :: Python :: 3Programming 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 :: Implementation :: CPythonProgramming Language :: Python :: Implementation :: PyPyTopic :: Software Development :: LibrariesTopic :: Software Development :: TestingTyping :: Typed

Tags

asyncio time mockingasyncio time fast-forwardevent loop time controlasyncio sleep testingfake time asyncio teststime acceleration testingasyncio timeout testing
asyncio-testingtime-mocking

More Libraries packages