Skip to main content

Wagtail Exposapi

Wagtail Exposapi is a Wagtail plugin that provides a JSON API for your Wagtail sites internals.

Usage Suggestion

When installed a JSON API view will list all:

  • admin listing page urls.
  • at least one of all edit page urls for installed Wagtail core apps.
  • at least one of all edit page type urls for your own models in installed apps.
  • at least one of all page type views for your own models in installed apps.

It does this with zero configuration. If need be you can provided configuration to exclude models or apps or provide a full list of apps/models to work with.

With this information it's possible to make a get request to each URL and check the response using various external tools or scripts e.g.

  • use a tool like Postman to check the responses.
  • create a script to check the responses.
  • use a monitoring service to check the responses.
  • use a CI/CD pipeline to check the responses.
  • and so on.

Site requirements

If you are checking a site locally it will work best with a full set of data, so it's best to load staging or development site data.

Try the package locally

This package has a sandbox site that you can use to try it out locally.

  1. Clone the repo
  2. Set up a virtual environment
  3. Run pip install -e '.[modeladmin2]'
  4. Run python manage.py migrate
  5. Run python manage.py load_fixtures
  6. Run python manage.py runserver

Visit http://localhost:8000/exposapi/ to see the default JSON api endpoint for the sandbox or http://localhost:8000/exposapi/?all=1 to see all possible urls for the loaded fixtures.

For admin login use superuser and superuser as the username and password.

Included Base Command

BaseResponsesCommand - A base command that you can extend in your own site to fetch the API data and check the responses.

The default behavior is to report any urls that return a response code other than 200.

You can add options to see more details: --expanded includes the 200 responses in the output, --all includes all responses endpoints in a site (could be slow depending the size of the size).

The command need to be able to login to the site so you need to provide a --username, --password and --url and --login-path, the defaults are superuser for the username and password and http://localhost:8000 for the url and /admin/login/ for the login path.

Create a new command in your site that extends BaseResponsesCommand.

from exposapi.responses_command import BaseResponsesCommand


class Command(BaseResponsesCommand):
    pass

For convenience you can add default options to the command so you don't need to type them each time you run the command.

class Command(BaseResponsesCommand):
    # you might want to fetch these from environment variables
    username = "your-login-username"
    password = "your-login-password"
    url = "http://localhost:8000"  # the base url of your site
    login_path = "/admin/login/"  # the login url for your site

Installation

Install the package with pip:

pip install wagtail-exposapi # coming soon

Before it's released you can install it from this repo:

pip install git+https://github.com/wagtail-packages/wagtail-exposapi.git

Add exposapi to your INSTALLED_APPS in your Django settings file: make sure you really want to enable it in your production site. It doesn't really expose anything sensitive but you may not want to expose your site's internals. You could just add this to your development settings or staging site settings.

Update your urls.py to include the exposapi urls:

urlpatterns = [
    ...,
    path("exposapi/", include("exposapi.urls")),
    ...,
]

Configuration

If you want to customise the introspection you can provide the configuration shown below.

EXPOSAPI_CONFIG = {
    "base_url": "http://localhost:8000",
    "listing_exclude": [
        "wagtailimages",
        ...,  # these apps won't be included in the listing pages
    ],
    "listing_pages_config": [
        {
            "title": "Search promotions",
            "app_name": "wagtailsearchpromotions",
            "listing_name": "wagtailsearchpromotions:index",
        },
        {
            "title": "Forms",
            "app_name": "wagtailforms",
            "listing_name": "wagtailforms:index",
        },
        ...,  # these will override the introspection for the listing pages
    ],
    "apps_exclude": [
        "wagtailimages",
        ...,  # these apps won't be included in the edit pages
    ],
}

Tested With

  • Python 3.8, 3.9, 3.10, 3,11, 3.12
  • Django 3.2, 4.0, 4.1, 4.2, 5.0
  • Wagtail 4.1, 4.2, 5.0, 5.1, 5.2, 6.0

Wagtail 5.1 can be used with wagtail-modeladmin 1.0.0 and wagtail 5.2+ can be used with wagtail-modeladmin 2.0.0

Model admin is only required if you still use it in your site.

Metadata

Release files for wagtail-exposapi 1.0.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 wagtail-exposapi 1.0.0
File Size Uploaded Provenance
wagtail-exposapi-1.0.0.tar.gz 13.5 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for wagtail-exposapi 1.0.0
File Interpreter ABI Platform
wagtail_exposapi-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 23.0 kB

Release files / wagtail-exposapi-1.0.0.tar.gz

Download URL wagtail-exposapi-1.0.0.tar.gz
Size 13.5 kB
Tags Source
SHA-256 checksum
How to use checksums
df86ec924dd5bf8cd09c8261dbba863ff45921aa0a1fe6f1bb7e19e9adcfb9e1
BLAKE2b-256 checksum
How to use checksums
6da9633a9fa4300ff67659be377748111a3a311b2c9f7bbfffd39b47fdb36ef2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.11.4

Release files / wagtail_exposapi-1.0.0-py3-none-any.whl

Download URL wagtail_exposapi-1.0.0-py3-none-any.whl
Size 9.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cc10eb6873e09b54c23ba96c8a9acff4808d3223c50e5be496b29f5094da5f2d
BLAKE2b-256 checksum
How to use checksums
9601394eb1dd81a26cbc232f58b88fcf6cfe99a107642f3797dd8aef318b1362
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.11.4

Security for wagtail-exposapi 1.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files No provenance

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