title: What is a Pythonic way for Dependency Injection?
body: <h1>Introduction</h1>
  
  <p>For Java, Dependency Injection works as pure OOP, i.e. you provide an interface to be implemented and in your framework code accept an instance of a class that implements the defined interface.</p>
  
  <p>Now for Python, you are able to do the same way, but I think that method was too much overhead right in case of Python. So then how would you implement it in the Pythonic way?</p>
  
  <h1>Use Case</h1>
  
  <p>Say this is the framework code:</p>
  
  <pre><code>class FrameworkClass():
      def __init__(self, ...):
          ...
  
      def do_the_job(self, ...):
          # some stuff
          # depending on some external function
  </code></pre>
  
  <h1>The Basic Approach</h1>
  
  <p>The most naive (and maybe the best?) way is to require the external function to be supplied into the <code>FrameworkClass</code> constructor, and then be invoked from the <code>do_the_job</code> method.</p>
  
  <p><strong><em>Framework Code:</em></strong></p>
  
  <pre><code>class FrameworkClass():
      def __init__(self, func):
          self.func = func
  
      def do_the_job(self, ...):
          # some stuff
          self.func(...)
  </code></pre>
  
  <p><strong><em>Client Code:</em></strong></p>
  
  <pre><code>def my_func():
      # my implementation
  
  framework_instance = FrameworkClass(my_func)
  framework_instance.do_the_job(...)
  </code></pre>
  
  <h1>Question</h1>
  
  <p>The question is short. Is there any better commonly used Pythonic way to do this? Or maybe any libraries supporting such functionality?</p>
  
  <h1>UPDATE: Concrete Situation</h1>
  
  <p>Imagine I develop a micro web framework, which handles authentication using tokens. This framework needs a function to supply some <code>ID</code> obtained from the token and get the user corresponding to that <code>ID</code>.</p>
  
  <p>Obviously, the framework does not know anything about users or any other application specific logic, so the client code must inject the user getter functionality into the framework to make the authentication work.</p>