Python promises library providing specialized promise-based asynchronous operations and lazy evaluation
npx @tessl/cli install tessl/pypi-vine@5.1.0A specialized Python promises library that provides both promise-based asynchronous operations and lazy evaluation. Unlike traditional promise implementations, vine allows everything within a promise to also be a promise, including filters, callbacks, and errbacks, creating a highly composable and flexible system.
pip install vineimport vineFor individual components:
from vine import promise, barrier, Thenable, maybe_promise, ensure_promise
from vine import ppartial, preplace, starpromise, transform, wrapfrom vine import promise
# Create a basic promise
p = promise()
# Chain operations using then()
p.then(lambda result: print(f"Got: {result}"))
# Fulfill the promise with a value
p(42) # Prints: Got: 42
# Create promise with function and arguments
compute_promise = promise(lambda x, y: x + y, args=(10, 20))
compute_promise.then(lambda result: print(f"Sum: {result}"))
compute_promise() # Prints: Sum: 30
# Chain multiple promises
p1 = promise(lambda x: x * 2)
p2 = promise(lambda x: x + 10)
p3 = p1.then(p2)
p1(5) # Triggers chain: 5 * 2 = 10, then 10 + 10 = 20Vine's architecture centers around the Thenable abstract base class and specialized implementations:
.then(), .throw(), and .cancel() interfaceThis design enables everything within a promise to also be a promise, allowing for complex asynchronous workflows and lazy computation patterns.
Main promise class providing asynchronous operations and lazy evaluation with full promise chaining support.
class promise:
def __init__(self, fun=None, args=None, kwargs=None, callback=None, on_error=None, weak=False, ignore_result=False): ...
def __call__(self, *args, **kwargs): ...
def then(self, callback, on_error=None): ...
def throw(self, exc=None, tb=None, propagate=True): ...
def cancel(self): ...
@property
def ready(self) -> bool: ...
@property
def failed(self) -> bool: ...
@property
def cancelled(self) -> bool: ...
@property
def value(self): ...
@property
def reason(self): ...Synchronization primitive for coordinating multiple promises and waiting for all to complete.
class barrier:
def __init__(self, promises=None, args=None, kwargs=None, callback=None, size=None): ...
def __call__(self, *args, **kwargs): ...
def add(self, promise): ...
def finalize(self): ...
def then(self, callback, errback=None): ...
def cancel(self): ...
@property
def ready(self) -> bool: ...
@property
def finalized(self) -> bool: ...
@property
def size(self) -> int: ...Functional utilities for promise creation, modification, and composition.
def maybe_promise(p): ...
def ensure_promise(p): ...
def ppartial(p, *args, **kwargs): ...
def preplace(p, *args, **kwargs): ...
def starpromise(fun, *args, **kwargs): ...
def transform(filter_, callback, *filter_args, **filter_kwargs): ...
def wrap(p): ...Core abstract classes and proxy objects for creating thenable objects.
class Thenable:
def then(self, on_success, on_error=None): ...
def throw(self, exc=None, tb=None, propagate=True): ...
def cancel(self): ...
class ThenableProxy:
def _set_promise_target(self, p): ...
def then(self, on_success, on_error=None): ...
def cancel(self): ...# Core types used throughout vine
from typing import Callable, Tuple, Any, Optional
from collections.abc import Callable
# Promise callback function types
PromiseCallback = Callable[..., Any]
ErrorCallback = Callable[[Exception], Any]
# Promise value type - stored as (args, kwargs) tuple
PromiseValue = Tuple[Tuple[Any, ...], dict]