wagtail-traverse
Utilities for traversing Wagtail StreamField and StreamValue objects.
Installation
pip install wagtail-traverse
Usage
This is a set of two functions:
-
traverse_block(block, parent=None)walks a StreamField's block definition tree (the schema, not page data).Given a root block, it yields back
(path, block)tuples for every block reachable from that root, including the root itself. This is intended to be used to discover what block types and paths can exist in a StreamField.from wagtailtraverse import traverse_block streamfield = MyPage._meta.get_field("body") for child_name in streamfield.stream_block.child_blocks: for path, block in traverse_block( streamfield.stream_block.child_blocks[child_name] ): print(f"{path}: {block.__class__.__name__}")
For a page with a
bodyfield containingheading,paragraph, and aheroStructBlock that has animageandcaption, this would print:heading: CharBlock paragraph: RichTextBlock hero: StructBlock hero.image: ImageChooserBlock hero.caption: CharBlock -
traverse_value(value, parent=None)walks the value of a StreamField on a page.It yields
(path, bound_block)tuples for every block in the stream value, recursing intoStreamValues,StructValues,ListValues, andTypedTables. This is intended to be used for deeply inspecting or migrating the content stored in a StreamField.from wagtail_traverse import traverse_value page = MyPage.objects.get(slug="example") for path, bound_block in traverse_value(page.body): print(f"{path}: {bound_block.block.__class__.__name__} = {bound_block.value}")
Paths
Both functions produce dotted path strings like hero.image or section.list.item that describe where a block sits in the tree.
License
This project is licensed under the MIT License. See LICENSE for details.
These functions originate in the wagtail-content-audit library as part of a block usage auditing. I have broken them out in this small utility library for convenience, since the ability to traverse StreamFields and their values is something I occasionally have found need to do.
Metadata
Release files for wagtail-traverse 1.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| wagtail_traverse-1.0.1.tar.gz | 10.2 kB | With provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| wagtail_traverse-1.0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 20.5 kB
Release files / wagtail_traverse-1.0.1.tar.gz
| Download URL | wagtail_traverse-1.0.1.tar.gz |
|---|---|
| Size | 10.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f39014fe6cf94f9981f3841563d325ed2552bdd0efea50c9842d2f91a8964f14
|
|
BLAKE2b-256 checksum How to use checksums |
eb29696ccb3e8e7c778b68a12e5cd99223f080b6b666954f62ae35cebc5936ea
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 3, 2026.
Transparency logRelease files / wagtail_traverse-1.0.1-py3-none-any.whl
| Download URL | wagtail_traverse-1.0.1-py3-none-any.whl |
|---|---|
| Size | 10.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d4f4d1cad2db48744742a07479f283f88536aac35cbfe68f15b3c13bf4581fc9
|
|
BLAKE2b-256 checksum How to use checksums |
4fd77c8c0ed062657803328cc9825d7ed4b7dadc2042a0f26d21a1399a1a3861
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 3, 2026.
Transparency logSecurity for wagtail-traverse 1.0.1
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.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for wagtail_traverse-1.0.1.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Apr 3, 2026.
Transparency logA 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.