Skip to main content

Functional interface for concurrent futures, including asynchronous I/O.

Project description

image image image image image image image image image

Futured provides a simple consistent interface for concurrent functional programming in Python. It wraps any callable to return a concurrent.futures.Future, wraps any async coroutine to return an asyncio.Future, and provides concurrent iterators and context managers for futures.


threaded, processed

Transform any callable into one which runs in a thread or process pool, and returns a future.

from futured import threaded, processed
import requests

fetch = threaded(requests.Session().get)
fetch(url)  # return Future

fs = (fetch(url + path) for path in paths)
threaded.results(fs)  # generate results from futures
threaded.results(fs, timeout=...)  # generate results as completed  # generate results in order, timeout=...)  # generate results as completed
fetch.mapzip(urls)  # generate (url, result) pairs as completed

Thread and process pool executors may be used as context managers, customized with options, and reused with different callables.

threaded(max_workers=...)(func, ...)
processed(max_workers=...)(func, ...)

futured classes have a waiting context manager which collects results from tasks. Futures can be registered at creation, or appended to the list of tasks.

with threaded.waiting(*fs) as tasks:
tasks  # list of completed results


The same interface works for asyncio.

from futured import asynced
import httpx

fetch = asynced(httpx.Client().get)
fetch(url)  # return coroutine

asynced.results(fs)  # generate results from futures
asynced.results(fs, timeout=...)  # generate results as completed  # generate results in order, timeout=...)  # generate results as completed
fetch.mapzip(urls)  # generate (url, result) pairs as completed

asynced provides utilities for calling coroutines from a synchronous context. waiting is similar to trio's nursery, but returns results from a synchronous with block., ...)  # call and run until complete, ...)  # call and run synchronous iterator
with asynced.waiting(*fs) as tasks:  # concurrent coroutines completed in a block


Naturally futured wrappers can be used as decorators, but arguments can also be partially bound.

def slow():

fetch = threaded(requests.Session().get, url)

Methods are supported, as well as a decorated utility for automatically subclassing.

from futured import decorated

FutureSession = decorated(requests.Session, request=threaded)

 # equivalent to
class FutureSession(requests.Session):
    request = threaded(requests.Session.request)


command wraps subprocess.Popen to provide a Future compatible interface.

from futured import futured, command

command('ls').result()  # return stdout or raises stderr
command('ls').pipe('wc')  # pipes into next command, or | ('wc',... )
for line in command('ls'):  # iterable lines
command.coroutine('ls')  # return coroutine

futured(command, 'ls')  # supports `map` interface
asynced(command.coroutine, 'ls')  # supports `map` interface with timeout


forked allows iteration in separate child processes.

from futured import forked

for value in forked(values, max_workers=...):
    # in a child process
 # in parent after children have exited


% pip install futured


100% branch coverage.

% pytest [--cov]



  • Python >=3.6 required


  • Stream completed futures from a pending pool


  • Executed functions are context managers
  • starmap supported


  • forked has optional maximum number of workers
  • waiting context manager
  • command pipes (|)
  • distributed.Client support


  • command.coroutine creates asyncio subprocesses
  • futured.mapzip generates results zipped with arguments
  • supports asynchronous iterators

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for futured, version 1.2
Filename, size File type Python version Upload date Hashes
Filename, size futured-1.2-py3-none-any.whl (6.5 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size futured-1.2.tar.gz (8.3 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page