Skip to main content

crumbles

A simple library for class based view breadcrumbs for any python web framework.

CI MIT License PyPI version Python 3.10 Python 3.11 Python 3.12 Python 3.13 Ruff Checked with mypy No Dependencies

Usage

First define a specific mixin for your framework. For example Django:

from django.urls import reverse


class DjangoCrumblesViewMixin(CrumblesViewMixin):
    def url_resolve(self, *args, **kwargs):
        return reverse(*args, **kwargs)

Use the Mixin in your View classes and define the breadcrumbs:

class MyListView(View, DjangoCrumblesViewMixin):
    crumbles = (
        CrumbleDefinition(url_name="my-list-view", title="Home"),
    )

Add a default breadcrumb to the mixin like so:

class DjangoCrumblesViewMixin(CrumblesViewMixin):
    def __init__(self):
        self.crumbles = (
            CrumbleDefinition(url_name="index", title="Home"),
        ) + type(self).crumbles

    def url_resolve(self, *args, **kwargs):
        return reverse(*args, **kwargs)

You can reuse "parent" crumbles for detail pages and use a callable for url resolve arguments or for defining the title:

from operator import attrgetter, methodcaller


class MyDetailView(View, DjangoCrumblesViewMixin):
    crumbles = MyListView.crumbles + (
        CrumbleDefinition(
            url_name="my-detail-view",
            url_resolve_kwargs={"pk": attrgetter("pk")},
            title=methodcaller("__str__"),
        ),
    )

The attributes context will be retrieved from instance.object. If this is not available it will default to the View class instance itself. You can set a custom context variable (including dotted syntakt) by using crumbles_context_attribute:

class MyDetailView(View, DjangoCrumblesViewMixin):
    crumbles_context_attribute = "my_object.parent"
    ...

Rendering the breadcrumb should be done in a template. An example for Django (with bootstrap):

<nav aria-label="breadcrumb">
    <ol class="breadcrumb">
        {% for item in view.resolve_crumbles %}
            {% if forloop.last %}
                <li class="breadcrumb-item active" aria-current="page">{{ item.title }}</li>
            {% else %}
                <li class="breadcrumb-item">
                    {% if item.url %}
                        <a href="{{ item.url }}">{{ item.title}}</a>
                    {% else %}
                        {{ item.title }}
                    {% endif %}
                </li>
            {% endif %}
        {% endfor %}
    </ol>
</nav>

Development setup

First clone this repository

git clone https://github.com/maerteijn/crumbles.git

Install the python project

pyenv virtualenv crumbles  # or your alternative to create a venv
pyenv activate crumbles
make install

Linting

ruff and mypy are installed and configured

make lint

Formatting

ruff are configured

make format

Test

Pytest with coverage is default enabled

make cov

Metadata

Release files for crumbles 0.1.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 crumbles 0.1.2
File Size Uploaded Provenance
crumbles-0.1.2.tar.gz 7.6 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for crumbles 0.1.2
File Interpreter ABI Platform
crumbles-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 12.3 kB

Release files / crumbles-0.1.2.tar.gz

Download URL crumbles-0.1.2.tar.gz
Size 7.6 kB
Tags Source
SHA-256 checksum
How to use checksums
c61b7bca857bb102cde511f81169949c32ff74fd37f2b66462076edec22178f8
BLAKE2b-256 checksum
How to use checksums
644deaa494d07e1040d58cd5520f7aca33b786e7c9335c26e183a0bcdfd4d13f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

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 Mar 6, 2025.

Transparency log

Release files / crumbles-0.1.2-py3-none-any.whl

Download URL crumbles-0.1.2-py3-none-any.whl
Size 4.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a80669b764f82957696da5874568201fcf4774e4fc0b8a584a52bbc0741045ec
BLAKE2b-256 checksum
How to use checksums
7ca779089290952697188b72b029a3ed698597acec73c0fe0010f54f1c223fd3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

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 Mar 6, 2025.

Transparency log

Security for crumbles 0.1.2

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.

Select from 2 files

Attestation for crumbles-0.1.2.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 Mar 6, 2025.

Transparency log

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

0.1.2 This release

2 release files Full 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