trampoline
Simple and tiny yield-based trampoline implementation.
What it is and what it does
Trampoline is a minimal yield-based implementation that allows recursive functions to sidestep Python's recursion depth limit by converting them into generators. Instead of calling functions recursively, trampolined functions yield the generator of the next call they want to make; the trampoline function then executes these generators iteratively, effectively simulating unlimited recursion without consuming stack frames.
To use it, you convert a recursive function into a generator by adding yield statements before recursive calls, then wrap the initial call with trampoline(). The package handles return values through yield expressions, preserves exception tracebacks, and supports tail calls via a TailCall exception. It has no external dependencies and consists of roughly 30 lines of core logic, making it lightweight and easy to understand.
Use it for:
- Computing factorials or other recursive mathematical functions with large inputs that would normally hit the recursion limit.
- Traversing deeply nested tree or graph structures without stack overflow.
- Implementing tail-recursive algorithms that benefit from constant-memory execution via TailCall.
- Writing recursive methods in classes where subclasses need to extend or override trampolined behavior.
- Processing recursive data structures like nested lists or custom node hierarchies in a single call.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Enables recursive functions to bypass Python's recursion depth limit by converting them into yield-based generators that the trampoline function executes iteratively.
No. The package is abandoned (last release 2018-08-18) and only declares support for Python 3.5, 3.6, 3.7, making it a poor fit for modern Python environments. While the concept is sound and the code is simple, the lack of maintenance means no compatibility fixes for newer Python versions, no bug fixes, and no assurance it will work with current tooling. For new projects, consider implementing a similar pattern yourself; for legacy code already using it, proceed with caution and test thoroughly on your target Python version.
Install
trampoline on PyPI
pip
pip install trampolineuv
uv add trampolinepoetry
poetry add trampolineInstalling trampoline
Before you install
Installation is frictionless—a pure Python wheel with no runtime dependencies. However, the package is abandoned; its latest release was 2018-08-18 with no updates since, so it will not receive bug fixes or compatibility patches for newer Python versions.
License in practice
MIT license (permissive) places no restrictions on use, modification, or distribution, making it safe to incorporate into commercial or open-source projects.
Quickstart
from trampoline import trampoline
def factorial(n):
if n <= 1:
return 1
value = yield factorial(n - 1)
return value * n
result = trampoline(factorial(10))
print(result) # 3628800
Functions must be rewritten as generators using yield at recursive call sites; existing recursive code cannot be used directly without modification.
Verify before relying
- Whether the package works reliably with Python versions beyond 3.7 (classifiers list only 3.5, 3.6, 3.7).
- Performance characteristics when recursing deeply, given the description mentions memory consumption as a caveat.
Package facts
| License | MIT (permissive) |
| Python support | not specified |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | none |
| Maintenance | abandoned — 2,918 days since the last release |
| First released | |
| Downloads | 1,796,619/month — #3,550 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: trampoline-0.1.2-py3-none-any.whl
Keywords: trampoline, recursion, tail, call
Tags
More Software Development packages
Provides backported and experimental type hints…
permissive · top 100 on PyPI
numpyNumPy provides an N-dimensional array object…
permissive · top 100 on PyPI
fastapiFastAPI is a Python web framework for building…
permissive · top 100 on PyPI
annotated-docProvides a way to document function parameters,…
permissive · top 100 on PyPI
typerTyper builds command-line applications from…
permissive · top 1,000 on PyPI
distlibDistlib provides low-level packaging utilities…
permissive · top 1,000 on PyPI
tailerTailer provides functions to read lines from…
permissive · top 15,000 on PyPI
infinityProvides an Infinity class that can be compared…
permissive · top 15,000 on PyPI
allpairspyGenerates minimal test case combinations using…
permissive · top 15,000 on PyPI
tracebackturbo3A drop-in replacement for Python's traceback…
permissive · top 15,000 on PyPI
recursive-diffRecursively compares two Python data structures…
permissive · top 15,000 on PyPI
levalLeval evaluates limited expressions safely by…
permissive · top 15,000 on PyPI
scantreeRecursively scans directories with flexible…
permissive · top 5,000 on PyPI
async_generatorProvides async generators and async context…
permissive · top 5,000 on PyPI
retryingRetrying is a decorator-based library that adds…
permissive · top 1,000 on PyPI
ovldOvld provides fast multiple dispatch for Python…
permissive · top 15,000 on PyPI