
Company News
Meet the Socket Team at RSAC and BSidesSF 2026
Join Socket for live demos, rooftop happy hours, and one-on-one meetings during BSidesSF and RSA 2026 in San Francisco.
forwardable
Advanced tools
Utility for easy object composition via delegation. Roughly ported from Ruby's forwardable_ standard library.
Python 2.7 or 3.3 w/ standard library. Might work on other version of Python, too.
$ pip install forwardable
Most Common Use Case
The ``@forwardable.forwardable()`` decorator enables you to use
``def_delegator()`` and ``def_delegators()`` in a class definition block.
Use ``def_delegators()`` to define multiple attr forwarding:
.. code-block:: python
from forwardable import forwardable
@forwardable() # Note the () here, which is required.
class Foo(object):
def_delegators('bar', 'add, __len__')
def __init__(self):
self.bar = set()
foo = Foo()
foo.add(1) # Delegates to foo.bar.add()
assert len(foo) == 1 # Magic methods works, too
Easy, heh?
Define a Single Forwarding
In case you only need to delegate one method to a delegatee, just
use def_delegator:
.. code-block:: python
from forwardable import forwardable
@forwardable()
class Foo(object):
def_delegator('bar', '__len__')
def __init__(self):
self.bar = set()
assert len(Foo()) == 0
And it should work just fine. Actually, def_delegators() calls
def_delegator() under the hood.
Plucking
.. code-block:: python
from forwardable import forwardable
@forwardable()
class MyDict(object):
def_delegator('dct.get', '__call__')
def __init__(self):
self.dct = {'foo', 42}
d = MyDict()
# Equivlant to d.dct.get('foo')
assert d('foo') == 42
Less Magical Usage
The @forwardable() decorator injects def_delegator{,s} into the
module scope temorarily, which is why you don't have to import them
explicitly. This is admittedly magical but discourages the usage
of import *. And it's always nice to type less characters whenever
unnecessary.
If you hesitate to utilize this injection magic, just explicitly say
from forwardable import def_delegator, def_delegators, use them in
a class definition and you'll be fine.
MIT license.
.. _forwardable: http://ruby-doc.org/stdlib-2.0/libdoc/forwardable/rdoc/Forwardable.html
FAQs
Forwardable as in Ruby's stdlib
We found that forwardable demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Company News
Join Socket for live demos, rooftop happy hours, and one-on-one meetings during BSidesSF and RSA 2026 in San Francisco.

Research
/Security News
Malicious Packagist packages disguised as Laravel utilities install an encrypted PHP RAT via Composer dependencies, enabling remote access and C2 callbacks.

Research
/Security News
OpenVSX releases of Aqua Trivy 1.8.12 and 1.8.13 contained injected natural-language prompts that abuse local AI coding agents for system inspection and potential data exfiltration.