Skip to main content

asyncio special sauce

Project description

Aioli (ayo-OH-lee) is a little sauce on top of Python’s asyncio package. With a little aioli it makes it easier to take advantage of asyncio in synchronous code.

These helpers are intended for IO bound tasks that yield. If you’re not yield’ing or if your code is CPU bound then aioli probably won’t help you much unless you start getting fancy with passing in your own loops in with their own executors.

Await

@asyncio.coroutine
def func(x):
    yield from asyncio.sleep(random())
    return x
result = aioli.await(func(1))

Map

# Func will be run asynchronously for each item in iterable and results
# will be returned in order as their available.
def func(x):
    yield from asyncio.sleep(random())
    return x

for result in aioli.map(func, iterable):
    print(result)

Parallel

# Func will be run asynchronously for each item in iterable and results
# will be returned as they are available.  Order is not guaranteed.
def inc(x):
    yield from asyncio.sleep(random())
    return x + 1

for result in aioli.parallel(func, iterable):
    print(result)

Filter

# Func will be run asynchronously for each item in iterable and results
# will be returned in order as their available.
is_even = lambda x: x % 2 == 0
for result in aioli.map(is_even, range(0, 100)):
    print(result)

Filter false

# Func will be run asynchronously for each item in iterable and results
# will be returned in order as their available.
is_even = lambda x: x % 2 == 0
for result in aioli.map(is_even, range(0, 100)):
    print(result)

Filter false

# Func will be run asynchronously for each item in iterable and results
# will be returned in order as their available.
is_even = lambda x: x % 2 == 0
for result in aioli.map(is_even, range(0, 100)):
    print(result)

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 aioli, version 0.0.3
Filename, size File type Python version Upload date Hashes
Filename, size aioli-0.0.3.tar.gz (3.9 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page