Skip to main content

Small utility for asynchronous coroutine generic programming in Python +3.4.

Project description

paco Build Status PyPI Coverage Status Documentation Status Stability Code Climate Python Versions

Small and idiomatic utility library for coroutine-driven, asynchronous-oriented generic programming in Python +3.4.

Built on top of asyncio, paco provides missing capabilities from Python stdlib to write asynchronous concurrent cooperative multitasking in a nice-ish way, plus higher-order function goodness.

Features

  • Simple and idiomatic API, extending Python stdlib with async coroutines gotchas.

  • Built-in configurable control-flow concurrency support.

  • Useful iterables, decorators and functors.

  • Provides coroutine-ready compose, throttle, partial, until, race and other functional helpers.

  • Asynchronous coroutine port of Python built-in functions: filter, map, dropwhile, filterfalse, reduce

  • Concurrent iterables and higher-order functions.

  • Better asyncio.gather() and asyncio.wait() implementations with optional concurrency control and ordered results.

  • Good interoperability with asyncio and Python stdlib functions.

  • Works with both async/await and yield from coroutines syntax.

  • Small and dependency free.

  • Compatible with Python +3.4.

Installation

Using pip package manager:

pip install paco

Or install the latest sources from Github:

pip install -e git+git://github.com/h2non/paco.git#egg=paco

API

Examples

Asynchronously and concurrently execute multiple HTTP requests.

import paco
import aiohttp
import asyncio

async def fetch(url):
    async with aiohttp.ClientSession() as session:
        async with session.get(url) as res:
            return res

async def fetch_urls():
    urls = [
        'https://www.google.com',
        'https://www.yahoo.com',
        'https://www.bing.com',
        'https://www.baidu.com',
        'https://duckduckgo.com',
    ]

    # Map concurrent executor with concurrent limit of 3
    responses = await paco.map(fetch, urls, limit=3)

    for res in responses:
        print('Status:', res.status)

# Run in event loop
paco.run(fetch_urls())

License

MIT - Tomas Aparicio

History

0.1.1 (2016-10-24)

  • refactor(name): use new project name.

0.1.0 (2016-10-23)

  • First version (beta)

Project details


Download files

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

Source Distribution

paco-0.1.2.tar.gz (18.5 kB view hashes)

Uploaded Source

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