API reference¶
Application life cycle¶
- svcs_pyramid.init(config, *, registry=None, tween_under=None, tween_over=None)[source]¶
Configure config to work with svcs.
svcs uses a tween to manage the life cycle of the container. You can affect its position by passing tween_under and tween_over.
- Parameters:
config (Configurator) – Pyramid configurator object.
registry (Registry | None) – A custom svcs registry to use. If None, a new one is created.
tween_under (Any) – Passed unchanged to
pyramid.config.Configurator.add_tween()as under.tween_over (Any) – Passed unchanged to
pyramid.config.Configurator.add_tween()as over.
- svcs_pyramid.close_registry(rh)[source]¶
Close the registry on rh, if present.
Ideal for
atexit.register()handlers.- Parameters:
rh (PyramidRegistryHaver) – An object that carries a
pyramid.registry.Registry.
- svcs_pyramid.svcs_from(request=None)[source]¶
Get the current container either from request or from thread locals.
- Parameters:
request (Request | None) – If None, thread locals are used.
- svcs_pyramid.get_registry(rh=None)[source]¶
Get the registry from rh or thread locals.
- Parameters:
rh (PyramidRegistryHaver | None) – If None, thread locals are used.
- class svcs_pyramid.PyramidRegistryHaver[source]¶
An object with a
pyramid.registry.Registryas aregistryattribute. For example aConfiguratoror an application.
Registering services¶
- svcs_pyramid.register_factory(config, svc_type, factory, *, enter=True, ping=None, on_registry_close=None)[source]¶
Same as
svcs.Registry.register_factory(), but uses registry on config.
- svcs_pyramid.register_value(config, svc_type, value, *, enter=False, ping=None, on_registry_close=None)[source]¶
Same as
svcs.Registry.register_value(), but uses registry on config.
Service acquisition¶
- svcs_pyramid.get(request, *svc_types)[source]¶
Same as
svcs.Container.get(), but uses the container from request.
- svcs_pyramid.get_abstract(request, *svc_types)[source]¶
Same as
svcs.Container.get_abstract(), but uses container from request.
- svcs_pyramid.get_pings(request)[source]¶
Like
svcs.Container.get_pings(), but uses container on request.See also