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
Close
Hashes for futured-0.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 504e4a25dadec954868192737c7984e834e48682762fa18596fbdeba593009cd |
|
MD5 | d2ee9c898aa9d3d52387206f05f2a7d6 |
|
BLAKE2b-256 | 423b15b36140ada7d283fdc01448cdb627075a2846ea6d63f897cd6e08378e4d |