Install & Compatibility
Where this runs
tested against v3.3.8 · 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.920 runs
installs and imports cleanly · install 0.0s · import 0.027s · 17.8MB
glibcpy 3.10–3.920 runs
installs and imports cleanly · install 1.5s · import 0.026s · 18MB
16MB installed
● package 16MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
Future
✓ from concurrent.futures import Future
ThreadPoolExecutor
✓ from concurrent.futures import ThreadPoolExecutor
ProcessPoolExecutor
✓ from concurrent.futures import ProcessPoolExecutor
as_completed
✓ from concurrent.futures import as_completed
wait
✓ from concurrent.futures import wait
This quickstart demonstrates using `concurrent.futures.ThreadPoolExecutor` with type hints. By installing `types-futures`, type checkers will correctly interpret the types of `Future` objects and executor methods, allowing for static analysis of your concurrent code.
from concurrent.futures import ThreadPoolExecutor, Future
from typing import List
def long_running_task(n: int) -> int:
import time
time.sleep(0.1)
return n * n
def main() -> None:
with ThreadPoolExecutor(max_workers=5) as executor:
futures: List[Future[int]] = [
executor.submit(long_running_task, i) for i in range(10)
]
results: List[int] = [f.result() for f in futures]
print(f"Computed results: {results}")
if __name__ == '__main__':
main()
Debug
Known issues
gotchaDo not confuse `types-futures` with the `futures` PyPI package. The `futures` package is a Python 2 backport of `concurrent.futures` and is not compatible with Python 3. `types-futures` provides stubs for Python 3's built-in `concurrent.futures` module.fixEnsure you are installing `types-futures` for type-checking `concurrent.futures` in Python 3 environments, and do not install the `futures` runtime package on Python 3.
affects: <=3.4.0 of `futures` PyPI package (runtime)
breakingAs `types-futures` is part of Typeshed, any version bump can introduce changes to the stubs that might cause your code to fail type checking, even if the runtime behavior remains the same. This is inherent to the nature of stub files aligning with potentially evolving APIs.fixPin the `types-futures` version to match the major.minor version of the `concurrent.futures` (implicitly, your Python runtime) it's stubbing, e.g., `types-futures~=3.x.y`. Regularly update and re-run type checks.
affects: All versions
gotchaThe `asyncio.Future` and `concurrent.futures.Future` classes are distinct and incompatible. Code expecting one will not correctly process the other, leading to runtime errors or incorrect type checking. `asyncio.Future` instances are awaitable, whereas `concurrent.futures.Future` instances are not.fixBe mindful of the context (asynchronous vs. thread/process-based concurrency) and use the appropriate `Future` class. Ensure correct type hints are used for each to leverage `types-futures` effectively.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'types_futures'
The `types-futures` package provides static type annotations for `concurrent.futures`, but it is not a runtime module meant to be imported directly.
fixYou should import `concurrent.futures` from the Python standard library. The `types-futures` package is used by type checkers like MyPy, not by the Python runtime.
No type information for "concurrent.futures"
Your type checker (e.g., MyPy, Pyright) cannot find type stubs for the `concurrent.futures` module, usually because the `types-futures` package is not installed or not discoverable in the current environment.
fixInstall the `types-futures` package using pip: `pip install types-futures`. Then, re-run your type checker.
No module named types_futures.__main__; 'types_futures' is a package and cannot be directly executed
The `types-futures` package provides type stubs and is not designed to be run as a standalone script or a main module using `python -m`.
fixThe `types-futures` package is solely for type checking. It should not be executed directly. If you intended to use the `concurrent.futures` module, import it within your Python script and execute that script.
Upgrade
Version history
3.3.8latest on PyPI · released Jan 27, 2022
Audit
Dependencies
No dependency data recorded yet.