pyramid_retry
raw JSON → 2.1.1 verified Fri May 01 auth: no python
An execution policy for the Pyramid web framework that supports retrying requests after certain failure exceptions. Version 2.1.1 provides integration with Pyramid's tweens to automatically retry failed requests based on configurable policies. It is maintained by the Pylons project and has a stable release cadence.
pip install pyramid-retry Common errors
error AttributeError: module 'pyramid_retry' has no attribute 'RetryablePolicy' ↓
cause Importing from wrong module or outdated version (<2.0). RetryablePolicy was introduced in 2.0.
fix
Upgrade pyramid-retry to >=2.0 and use 'from pyramid_retry import RetryablePolicy'.
error ConfigurationError: ('Unknown settings value: retry_max',) ↓
cause Using deprecated setting 'retry_max' instead of 'retry.max_attempts'.
fix
Replace 'retry_max' with 'retry.max_attempts' in your config settings.
Warnings
breaking pyramid_retry 2.0 removed the 'retry_max' setting. Use 'retry.max_attempts' instead. ↓
fix Replace 'retry_max' with 'retry.max_attempts' in your Pyramid settings.
gotcha Retry policies must be added as a list to 'retry.policies'. Forgetting the list wrapper causes a configuration error. ↓
fix Set 'retry.policies': [RetryablePolicy()] rather than just 'retry.policies': RetryablePolicy().
gotcha The retry tween factory must be added after pyramid_tm if you use transaction management; ordering matters. ↓
fix Use config.add_tween('pyramid_retry.retry_tween_factory', under='pyramid_tm.tm_tween_factory') if pyramid_tm is active.
Imports
- RetryablePolicy
from pyramid_retry import RetryablePolicy - retry_tween_factory
from pyramid_retry import retry_tween_factory
Quickstart
from wsgiref.simple_server import make_server
from pyramid.config import Configurator
from pyramid_retry import RetryablePolicy, retry_tween_factory
def hello_world(request):
return {'status': 'ok'}
if __name__ == '__main__':
with Configurator() as config:
config.add_route('home', '/')
config.add_view(hello_world, route_name='home', renderer='json')
# Set retry policy
config.add_tween('pyramid_retry.retry_tween_factory')
config.add_settings({
'retry.max_attempts': 3,
'retry.policies': [RetryablePolicy()],
})
app = config.make_wsgi_app()
server = make_server('0.0.0.0', 8080, app)
server.serve_forever()