The &quot;loader protocol&quot; (PEP 302) is a related trick that can be used locally, so it only affects imports from packages that opt in. I use this in <a href="https:&#x2F;&#x2F;github.com&#x2F;bdarnell&#x2F;codegenloader" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;bdarnell&#x2F;codegenloader</a> to automagically process protobuf&#x2F;thrift files and import the generated code.