svcs-pyramid

Release UNRELEASED (What’s new?)

svcs-pyramid is the svcs integration for Pyramid.

svcs (pronounced services) is a dependency container for Python. It gives you a central place to register factories for types/interfaces and then imperatively acquire instances of those types with automatic cleanup and health checks.

svcs-pyramid wires that up for Pyramid: it stores the svcs registry in Pyramid’s own registry (yes, unfortunate name clash) and uses a tween to attach a fresh container to every request – and to close it when the request is done.

import svcs_pyramid


@view_config(route_name="index")
def view(request):
    db, api, cache = svcs_pyramid.get(request, Database, WebAPIClient, Cache)

    ...

To a type checker, db has the type Database, api has the type WebAPIClient, and cache has the type Cache. db, api, and cache will be automatically cleaned up when the request ends – it’s context managers all the way down.

Read on in Usage – or in svcs’s own documentation if you’re new to svcs itself.