Skip to main content

pyramid_services_viewmapper

An extension for the Pyramid web framework.

pyramid_services_viewmapper provides a view mapper for use in conjunction with pyramid_services. It extends the functionality of pyramid_services to provide dependency injection: you can add custom arguments to your view functions, and the view mapper will automatically populate those arguments with matching services.

Setup

Register the view mapper in your Configurator:

from pyramid_services_viewmapper import ServiceViewMapper
config.set_view_mapper(ServiceViewMapper)

Usage

Services registered by interface alone are injected by a simple type annotation. For example this...

@view_config(route_name="home", renderer="json")
def home(request, login_svc: ILoginService):
    token = login_svc.create_token_for_login(name)
    return {"access_token": token}

...is equivalent to this:

@view_config(route_name="home", renderer="json")
def home(request):
    login_svc = request.find_service(ILoginService)
    token = login_svc.create_token_for_login(name)
    return {"access_token": token}

Services registered by name can be injected using a ServiceInjector object. For example this...

from pyramid_services_viewmapper import ServiceInjector as S

@view_config(route_name="users", renderer="json")
def users(request, db: S(name="db")):
    users = db.query(User)
    return {"users": users}

...is equivalent to this:

@view_config(route_name="users", renderer="json")
def users(request):
    db = request.find_service(name="db")
    users = db.query(User)
    return {"users": users}

The ServiceInjector class can be used as a shortcut for this:

from pyramid_services_viewmapper import ServiceInjector as S

@view_config(route_name="users", renderer="json")
def users(request, db: S):
    users = db.query(User)
    return {"users": users}

Metadata

Release files for pyramid-services-viewmapper 1.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyramid-services-viewmapper 1.1.0
File Size Uploaded
pyramid_services_viewmapper-1.1.0.tar.gz 2.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pyramid-services-viewmapper 1.1.0
File Interpreter ABI Platform
pyramid_services_viewmapper-1.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 6.5 kB

Release files / pyramid_services_viewmapper-1.1.0.tar.gz

Download URL pyramid_services_viewmapper-1.1.0.tar.gz
Size 2.8 kB
Tags Source
SHA-256 checksum
How to use checksums
0d2f7ba55f555393ce05e9780f9791b3a2e038c95acf80fcc7b0462677635e2d
BLAKE2b-256 checksum
How to use checksums
c831a7246dc8654fbbaf34263140b72f18bd4553e223c3d62ae6d0439fd93535
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.4.1 CPython/3.11.2 Linux/4.15.0-200-generic

Release files / pyramid_services_viewmapper-1.1.0-py3-none-any.whl

Download URL pyramid_services_viewmapper-1.1.0-py3-none-any.whl
Size 3.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
407438fa0488fb45d9cbec5fb6076d3285b748f9c3129143f82b712510d80d94
BLAKE2b-256 checksum
How to use checksums
abb0a1817df0e41038d3ce8313f6d6c5b9e789965a94f236dd070f484ae3b8ee
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.4.1 CPython/3.11.2 Linux/4.15.0-200-generic

Release history Release notifications | RSS feed

This release

1.1.0 This release

2 release files

1.0.1

2 release files

1.0.0

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page