Skip to main content

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

Project description

Futured provides a simple consistent interface for concurrent functional programming in Python. It can wrap any callable to return concurrent.futures.Future objects, and it can wrap any async coroutine to return asyncio.Future objects.

Usage

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)  # returns Future

fs = (fetch(url + path) for path in paths)
fetch.results(fs)  # generates results in order
fetch.results(fs, timeout=None)  # generates results as completed

fetch.map(urls)  # generates results in order
fetch.map(urls, timeout=None)  # generates results as completed

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

@threaded
def slow():
   ...

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

The same interface works for aynscio.

from futured import asynced
import aiohttp

fetch = asynced(aiohttp.ClientSession().get)

Installation

$ pip install futured

Dependencies

  • Python 3.4+

Tests

100% branch coverage.

$ pytest [--cov]

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

futured-0.0-py2.py3-none-any.whl (4.2 kB view hashes)

Uploaded Python 2 Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page