Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (
Help us improve Python packaging - Donate today!

Glue code removal.

Project Description


Glue code removal. Acetone is a python library to provide inversion of control in situation where other methods are inconvenient or they are not even possible. Or you just like the library.


Create the acetone container somewhere in your application:


from acetone import AcetoneContainer

dependencies = AcetoneContainer()
# or ioc_container
# or lord_of_the_dependencies
# or services

Then use it:


from dependencies import dependencies

class ClassWithSomeDependency(object):
    # you can use strings or types as a key
    dependency = dependencies.Dependency('key')

    def use_the_dependency(self):

Create a dependency implementation:


class DependencyImplementation(object):
    def dependency_call(self, argument):

Later register the implementation and run it!


from dependencies import dependencies
from class_with_dependency import ClassWithSomeDependency
from dependency_implementation import DependencyImplementation

if __name__ == '__main__':
    dependency_implementation = DependencyImplementation()
    dependencies.register_instance('key', dependency_implementation)

    instance = ClassWithSomeDependency()

Or load it from a file:

        "name": "key",
        "module": "dependency_implementation",
        "factory": "DependencyImplementation",
        "singleton": true
import json
from dependencies import dependencies

def main():
    with open('configuration.json') as file:
        content = json.load(file)

    instance = ClassWithSomeDependency()

Frequently asked questions

How fast is it?

It’s very fast. It’s even faster then a builtin property. The very first dependency access requires some initialization for its own setup and dependency creation (provided it was not created before), but the subsequent calls are as fast as a member instance access. Dependencies use a descriptor protocol (used by @property), they are initialized lazily and once fetched from the container they are set as a normal instance member (class member in case of ClassDependency). This trick is used by several frameworks (for example werkzeuq cached_property).

How do I mock it?

Technically you can mock it, but I don’t think it’s necessary. The container is simple and well tested. Its purpose is to provide a requested dependency and the dependency can be a mock as well. You can just consider it as an essential part of your code and not mock it to your advantage (would you mock properties?).

class TestXyz(TestCase):
    def tearDown(self):

Traditionalists wouldn’t agree for sure but Python wasn’t created by traditionalists in the first place.

Are there any requirements?

No external dependencies. For the class used the only requirement is that the class has to be a normal python class with __dict__. In other words it can’t use __slots__.

Release History

Release History

This version
History Node


Download Files

Download Files

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

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
acetone-0.1.0-py2.py3-none-any.whl (10.4 kB) Copy SHA256 Checksum SHA256 py2.py3 Wheel Aug 28, 2016

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting