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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pyramid_introspector-0.1.1.tar.gz.
File metadata
- Download URL: pyramid_introspector-0.1.1.tar.gz
- Upload date:
- Size: 56.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a5ec6e41599aac7a44ed9a77f1e7d474434de6ca258b501fde5e8675d718e499
|
|
| MD5 |
8bdfd933ef5f353fe650aa5730d464f9
|
|
| BLAKE2b-256 |
80c6d7155e5b1283c80a11857561c6bea9b2d04684dcb6347a8737c98b7f1946
|
Provenance
The following attestation bundles were made for pyramid_introspector-0.1.1.tar.gz:
Publisher:
ci.yml on cartaorobbin/pyramid-introspector
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyramid_introspector-0.1.1.tar.gz -
Subject digest:
a5ec6e41599aac7a44ed9a77f1e7d474434de6ca258b501fde5e8675d718e499 - Sigstore transparency entry: 1059830367
- Sigstore integration time:
-
Permalink:
cartaorobbin/pyramid-introspector@ca3ed35b729dacd91bb08ef6ecc6838da3b38d7c -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/cartaorobbin
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@ca3ed35b729dacd91bb08ef6ecc6838da3b38d7c -
Trigger Event:
release
-
Statement type:
File details
Details for the file pyramid_introspector-0.1.1-py3-none-any.whl.
File metadata
- Download URL: pyramid_introspector-0.1.1-py3-none-any.whl
- Upload date:
- Size: 12.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0993c081462249ba6bd2787128674569bfdfe1441cd87bc78d3b7a24e7b849bc
|
|
| MD5 |
2ba0626b50087d241ae3962be5e3e399
|
|
| BLAKE2b-256 |
aa53d9e195f8a194d9b23bb9ef35f03c94a3bc722b7c2112ecb9b49326d7acb6
|
Provenance
The following attestation bundles were made for pyramid_introspector-0.1.1-py3-none-any.whl:
Publisher:
ci.yml on cartaorobbin/pyramid-introspector
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyramid_introspector-0.1.1-py3-none-any.whl -
Subject digest:
0993c081462249ba6bd2787128674569bfdfe1441cd87bc78d3b7a24e7b849bc - Sigstore transparency entry: 1059830369
- Sigstore integration time:
-
Permalink:
cartaorobbin/pyramid-introspector@ca3ed35b729dacd91bb08ef6ecc6838da3b38d7c -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/cartaorobbin
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@ca3ed35b729dacd91bb08ef6ecc6838da3b38d7c -
Trigger Event:
release
-
Statement type: