title: Is it possible to emulate Scala's traits in Python?
body: <p>I want to create lightweight interfaces with methods that I can plug into classes. Here is an short example in Scala:</p>
  
  <pre><code>class DB {
    def find(id: String) = ...
  }
  
  trait Transformation extends DB {
    def transform(obj: String): String
  
    override def find(id: String) =
      transform(super.find(id))
  }
  
  trait Cache extends DB {
    val cache = Cache()
    override def find(id: String) = {
      ...
      if (cache.contains(id))
         cache.find(id)
      else {
         cache.set(id, super.find(id))
         cache.get(id)
      }
    }   
  }
  </code></pre>
  
  <p>With these classes (traits) we can instantiate DB classes with Transformation, with Cache, or both. Note that Transformation has an abstract method transform, which still needs to implemented in concrete classes.</p>
  
  <pre><code>new DB() with Transformation {
    def transform(obj: String): obj.toLower()
  }
  new DB() with Cache
  new DB() with Transformation with Cache {
    def transform(obj: String): obj.toLower()
  }
  </code></pre>
  
  <p>Is there any way to achieve something like this in Python? I know there exists a Traits package for Python, but its purpose seems to be different.</p>