CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-vine

Python promises library providing specialized promise-based asynchronous operations and lazy evaluation

Pending
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

Vine

A 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.

Package Information

  • Package Name: vine
  • Language: Python
  • Installation: pip install vine

Core Imports

import vine

For individual components:

from vine import promise, barrier, Thenable, maybe_promise, ensure_promise
from vine import ppartial, preplace, starpromise, transform, wrap

Basic Usage

from 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 = 20

Architecture

Vine's architecture centers around the Thenable abstract base class and specialized implementations:

  • Thenable: Abstract base class defining the .then(), .throw(), and .cancel() interface
  • promise: Main promise implementation supporting both value promises and lazy evaluation
  • barrier: Synchronization primitive for waiting on multiple promises
  • Functional utilities: Helper functions for promise composition and manipulation

This design enables everything within a promise to also be a promise, allowing for complex asynchronous workflows and lazy computation patterns.

Capabilities

Core Promise Operations

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): ...

Promise Operations

Promise Synchronization

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: ...

Synchronization

Promise Utilities

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): ...

Utilities

Abstract Base Classes

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): ...

Abstract Classes

Types

# 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]
Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/vine@5.1.x
Publish Source
CLI
Badge
tessl/pypi-vine badge