Skip to main content

Test Coverage Stable Version Pre-release Version PyPI - Python Version PyPI Downloads

delegate-pattern: Python implementation of the Delegation Pattern.

delegate-pattern provides a basic implementation of the well-known Delegation Pattern.

What is delegation

Delegation is a pattern in object oriented programming where a class (delegator) delegates responsibilities to one or more delegates.

This allows for greater code reusability and reduced class complexity and may help adhering to the DRY (Do not Repeat Yourself) and SoC (Separation of Concerns) principles.

Example

Consider a trivial task of delegating the printing of an objects name to the console. Here the delegator SomeClass delegates the task to the delegate PrintNameDelegate which is not much more than a function wrapped in a class.

The delegate class is always initialized with an argument specifying its delegator, and while this example shows the use of a protocol class called NamedClassProtocol, this is merely included for convenience, and will not be enforced at runtime. In fact the type of delegator can be anything, but delegate constructors cannot have any other arguments.

Note that it's strongly recommended to use weak references to the delegator in the delegate constructor.

from typing import Protocol
from weakref import ref
from delegate.pattern import delegate

class NamedClassProtocol(Protocol):
    _name: str

class PrintNameDelegate:
    # this is a stateful delegate because its constructor
    # takes a 'delegator' argument

    def __init__(self, delegator: NamedClassProtocol):
        self.__delegator = delegator

    def __call__(self):
        print(self.__delegator._name)

class NamePropertyDelegate:
    # this is a stateless delegate because it has no
    # constructor which takes a 'delegator' argument

    def __get__(self, delegator: NamedClassProtocol) -> str:
        return delegator._name

    def __set__(self, delegator: NamedClassProtocol, value: str):
        delegator._name = value

class SomeClass:
    _name: str
    def __init__(self, name: str) -> None:
        self._name = name

    name_printer = delegate(PrintNameDelegate) # => PrintNameDelegate instance
    name = delegate(NamePropertyDelegate, str) # => string getter

some_instance = SomeClass("Neo")
some_instance.name_printer() # prints Neo

name = some_instance.name # => Neo
some_instance.name = "Trinity"
new_name = some_instance.name # => Trinity

Full documentation

Go to documentation

Metadata

Release files for delegate-pattern 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for delegate-pattern 0.1.1
File Size Uploaded Provenance Actions
delegate_pattern-0.1.1.tar.gz 9.9 kB With provenance Details for delegate_pattern-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for delegate-pattern 0.1.1
File Interpreter ABI Platform Actions
delegate_pattern-0.1.1-py3-none-any.whl Python 3 none any Details for delegate_pattern-0.1.1-py3-none-any.whl

Total release size: 21.0 kB

Release files / delegate_pattern-0.1.1.tar.gz

Download URL delegate_pattern-0.1.1.tar.gz
Size 9.9 kB
Tags Source
SHA-256 checksum
How to use checksums
d1c39e78d882a5e7d0d1bfabf3c57a44df21b5601c44aae5ad6a560097482f8f
BLAKE2b-256 checksum
How to use checksums
315c7c004d5f35a9390ed74494d9259c32926cd4df76a3fc17efbabc06fe2de9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Oct 27, 2026.

Transparency log

Release files / delegate_pattern-0.1.1-py3-none-any.whl

Download URL delegate_pattern-0.1.1-py3-none-any.whl
Size 11.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
dfcea2192da7feba75210dfacff50073bbddcd6975435a2bf3e717811835eb1d
BLAKE2b-256 checksum
How to use checksums
0880c45cb359b535876df47826acab162b828fa8c9fc25cc6a59ad64905dfbc9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Oct 27, 2026.

Transparency log

Security for delegate-pattern 0.1.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

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for delegate_pattern-0.1.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 Oct 27, 2026.

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.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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