Skip to main content

A library that helps introspect Pyramid views and extract their metadata and information.

Project description

pyramid-introspector

Extract route and view metadata from Pyramid applications, with an extension system that handles library-specific introspection for Cornice and pycornmarsh.

Why

Pyramid's introspectable registry holds rich metadata about routes and views, but extracting it -- especially when libraries like Cornice and pycornmarsh layer their own conventions on top -- requires non-trivial, repetitive code. This library provides a single, tested entry point for that work.

Installation

pip install pyramid-introspector

With Cornice/Marshmallow support:

pip install pyramid-introspector[cornice]

Quick start

from pyramid.config import Configurator
from pyramid_introspector import PyramidIntrospector

config = Configurator()
# ... add routes, views, include cornice, etc.
config.commit()

introspector = PyramidIntrospector(config.registry)
routes = introspector.introspect()

for route in routes:
    for view in route.views:
        print(f"{view.method:6} {route.pattern}")
        if view.request_schema:
            print(f"       body: {view.request_schema.name}")
        if view.response_schema:
            print(f"       resp: {view.response_schema.name}")

What you get

Each RouteInfo contains:

Field Type Description
name str Pyramid route name
pattern str URL pattern (e.g. /items/{id})
views list[ViewInfo] One per HTTP method
factory Any Route factory for ACL contexts
extra dict Extension-specific route metadata

Each ViewInfo contains:

Field Type Description
method str HTTP method (GET, POST, ...)
callable Any The Python view function
permission str | None Pyramid permission (from ACL)
security str | None Auth scheme type (e.g. "bearer", "BearerAuth")
description str First line of view docstring
parameters list[ParameterInfo] Path, querystring, and body parameters
request_schema SchemaInfo | None Marshmallow schema for request body
querystring_schema SchemaInfo | None Marshmallow schema for querystring
response_schema SchemaInfo | None Primary 2xx response schema
response_schemas dict[int, SchemaInfo] All response schemas keyed by status code
extra dict Extension-specific view metadata

Extensions

Extensions enrich the base route/view data with library-specific metadata. Built-in extensions are loaded automatically when their dependencies are installed.

Cornice

Activated when cornice is installed. Discovers Cornice services, matches them to routes by path, and extracts Marshmallow schemas from service definitions -- both composite schemas (body/querystring/path as nested fields) and flat schemas with location detection from validators.

pycornmarsh

Activated when cornice is installed. Reads pycornmarsh predicates (pcm_request, pcm_responses, pcm_tags, pcm_summary, pcm_description, pcm_security, pcm_show) from Cornice service definition args and populates the corresponding ViewInfo fields.

Writing custom extensions

Any class that satisfies the IntrospectionExtension protocol can be used:

from pyramid_introspector.extensions import IntrospectionExtension
from pyramid_introspector.models import RouteInfo

class MyExtension:
    name = "my_library"

    def is_available(self) -> bool:
        try:
            import my_library
            return True
        except ImportError:
            return False

    def enrich(self, registry, routes: list[RouteInfo]) -> list[RouteInfo]:
        # Mutate views with library-specific metadata
        return routes

Pass it directly:

introspector = PyramidIntrospector(registry, extensions=[MyExtension()])

Or register it via entry points for automatic discovery:

[project.entry-points."pyramid_introspector.extensions"]
my_library = "my_package:MyExtension"

Development

git clone https://github.com/your-org/pyramid-introspector.git
cd pyramid-introspector
uv sync --group dev

Run tests:

uv run pytest

Lint and format:

uv run ruff check src/ tests/
uv run black src/ tests/

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyramid_introspector-0.2.0.tar.gz (64.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyramid_introspector-0.2.0-py3-none-any.whl (12.8 kB view details)

Uploaded Python 3

File details

Details for the file pyramid_introspector-0.2.0.tar.gz.

File metadata

  • Download URL: pyramid_introspector-0.2.0.tar.gz
  • Upload date:
  • Size: 64.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pyramid_introspector-0.2.0.tar.gz
Algorithm Hash digest
SHA256 ea744015347b2d2c4d829c98fec7f8869c183cb6309b489d239c9fc0adc07bdb
MD5 c1ac471d2cb881c8309f04af77d2a94e
BLAKE2b-256 861b85ce125e3d4e79224e3213d9a0a1226b18bad7c495208523d4a3eefc8f9c

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyramid_introspector-0.2.0.tar.gz:

Publisher: ci.yml on cartaorobbin/pyramid-introspector

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyramid_introspector-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for pyramid_introspector-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2f7428176580959224e8bc40ae6fa26c22c71f84fc7d481b119806ec7fd16ad5
MD5 1d19c1a13919a145e0159b13f7b408d6
BLAKE2b-256 cd0734c9805cba04be57b98122799f2161749aefa279a217455ad75535dabfbe

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyramid_introspector-0.2.0-py3-none-any.whl:

Publisher: ci.yml on cartaorobbin/pyramid-introspector

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page