Module contents

Run pyramid app using asyncio


Setup the basic configuration to run Pyramid with asyncio.


aiopyramid.config module

This module provides view mappers for running views in asyncio.

class aiopyramid.config.AsyncioMapperBase(**kw)[source]

Bases: pyramid.config.views.DefaultViewMapper

Base class for asyncio view mappers.

class aiopyramid.config.CoroutineMapper(**kw)[source]

Bases: aiopyramid.config.AsyncioMapperBase

class aiopyramid.config.CoroutineOrExecutorMapper(**kw)[source]

Bases: aiopyramid.config.AsyncioMapperBase

class aiopyramid.config.ExecutorMapper(**kw)[source]

Bases: aiopyramid.config.AsyncioMapperBase

aiopyramid.exceptions module

exception aiopyramid.exceptions.ScopeError[source]

Bases: Exception

Error indicating execution in the wrong greenlet.

aiopyramid.helpers module


Tests whether func is capable of becoming an asyncio.coroutine.

aiopyramid.helpers.run_in_greenlet(back, future, func, *args, **kwargs)[source]

Wait for coroutine func and switch back to the request greenlet setting any result in the future or an Exception where approrpiate.

func is often a view callable

aiopyramid.helpers.spawn_greenlet(func, *args, **kwargs)[source]

Spawns a new greenlet and waits on any asyncio.Future objects returned.

This is used by the Gunicorn worker to proxy a greenlet within an asyncio event loop.


Wraps a callable handling any ScopeErrors that may occur because the callable is called from inside of a coroutine.

If no ScopeError occurs, the callable is executed normally and return arguments are passed through, otherwise, when a ScopeError does occur, a coroutine to retrieve the result of the callable is returned instead.

aiopyramid.helpers.synchronize(*args, strict=True)[source]

Decorator for transforming an async coroutine function into a regular function relying on the aiopyramid architecture to schedule the coroutine and obtain the result.

def my_coroutine():
    ... code that yields
aiopyramid.helpers.use_executor(*args, executor=None)[source]

A decorator for running a callback in the executor.

This is useful to provide a declarative style for converting some thread-based code to a coroutine. It creates a coroutine by running the wrapped code in a separate thread.

aiopyramid.traversal module

The aiopyramid.traversal module is deprecated, use aiopyramid.helpers.synchronize instead. See

aiopyramid.tweens module

The aiopyramid.tweens module is deprecated. See example in the docs:

aiopyramid.tweens.coroutine_logger_tween_factory(handler, registry)[source]

Example of an asynchronous tween that delegates a synchronous function to a child thread. This tween asynchronously logs all requests and responses.