Skip to main content
Pecan Mount
===========
A utility to mount Pecan applications at different points to act as one.


Adding applications
-------------------
Pecan applications are usually mounted at `/` and they do not have an easy way
to be able to compound different apps working in unison. If you are using
`pecan_mount` you need to use the tree as the actual WSGI application as it
acts as WSGI middleware to properly return the apps at given mount points.

You only need two things for mounting an app, an application configuration and
the mount point. The configuration can be either a path to a file or
a dictionary (Pecan takes care of this loading for us). So to mount a single
application at `/application` with a configuration file living in
`/path/to/config.py` it would look like this::

import pecan_mount
pecan_mount.tree.mount('/application', '/path/to/config.py')

The nice things about Pecan configuration is that it will take care of finding
the right modules and everything necessary for your application. At most, the
important decision here is the mount point.


Running multiple applications
----------------------------
Ideally, you would want to mount all the applications you need in one place,
and this place should be where the WSGI application is constructed so that it
can be consumed by a WSGI server (for example `gunicorn` or Apache with
`mod_wsgi`). This is how having 4 different applications would look in a file
called `wsgi.py`::

import pecan_mount

pecan_mount.tree.mount('/', '/path/to/main_config.py')
pecan_mount.tree.mount('/admin', '/path/to/admin_config.py')
pecan_mount.tree.mount('/registration', '/path/to/registration_config.py')
pecan_mount.tree.mount('/_metrics', '/path/to/metrics_config.py')

application = pecan_mount.tree


Naming the mounts
-----------------
Optionally, when mounting, you can pass in a ``mount_name`` that will be used
added to the WSGI app as an attribute. This is useful when debugging or when
you need to have a better representation of what application is mounted at some
point.

If no ``mount_name`` is passed in to the ``mount`` callable, it will default to
inferring the name from the ``script_name``, which in turn will use ``root``
for empty strings or None and for dotted conversions for other paths.

For example, a ``script_name`` that looks like: ``/foo/bar`` will be translated
to a ``mount_name`` of ``foo.bar``.


Preventing overriding of mounts
-------------------------------
The ``tree`` object will prevent you from mounting applications in locations
where there is already an app mounted. This is convenient when there are
multiple applications mounted and unknowingly a new app is using a location
already taken. An ``AttributeError`` will be raised to indicate what
application at what mount point is being used and prevent further execution.


Mounting other WSGI apps
------------------------
Other WSGI applications can also be mounted easily. The WSGI app will need to
be properly configured before mounting and will use a different callable::

import pecan_mount
import my_app

my_wsgi_app = my_app()

pecan_mount.tree.graft(my_app, '/mount_point')

Metadata

Release files for pecan-mount 0.0.2

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

Source distribution (sdist)

Source distribution for pecan-mount 0.0.2
File Size Uploaded
pecan-mount-0.0.2.tar.gz 6.5 kB Details

Release files / pecan-mount-0.0.2.tar.gz

Download URL pecan-mount-0.0.2.tar.gz
Size 6.5 kB
Tags Source
SHA-256 checksum
How to use checksums
28de6a41ae7218c6efb7ba04c614fa44815a4b30f0f6c6102be074996c7e803e
BLAKE2b-256 checksum
How to use checksums
c432eed73dc172697b5c876fc8d184e241c6d3ef867395f9c17a38ba7376cb29
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.0.2 This release

1 release file

0.0.1

1 release file

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