Skip to main content

behaviour based duck typing library

Project description


Allows working with objects depending on their current behaviour, not their type or their registered (ABC-like) interface.

Quick example:

from ducktypes.ducktype import Duck

class MyObject(object):
    def some_method(self, a, b):
    def another_method(self, x):

class AnotherObject(object):
    def some_method(self, a, b):
    def another_method(self, a):

class AnotherDifferentObject(object):
    def some_method(self, a, b, c):
    def another_method(self, a):

duck = Duck(MyObject())

print "AnotherObject instances implement MyObject interface: ", duck.maybe_implemented_by(AnotherObject())
print "AnotherDifferentObject instances implement MyObject interface:", duck.maybe_implemented_by(AnotherDifferentObject())


AnotherObject instances implement MyObject interface:  True
AnotherDifferentObject instances implement MyObject interface: False


  • positional arguments are supposed to be called as positional arguments, and keyword arguments are supposed to be called as positional arguments. If your client code calls keyword arguments as positional ones, signature matching may fail.
  • proxy-everything methods, i.e. (*args, **kwargs)-like signature, will of course deceive our signature detection system.


  • __getattr__ / __getattribute__ overriding functions
  • subclasses exposing special methods with different signature
  • C-declared functions that don’t expose their signature.
  • implement optional strict checking.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date (16.4 kB) Copy SHA256 hash SHA256 Source None

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page