Skip to main content

Injector - Python dependency injection framework, inspired by Guice

Project description

This framework is also similar to snake-guice, but aims for simplification.

While being inspired by Guice, it does not slavishly replicate its API. Providing a Pythonic API trumps faithful replication.

An Example

Here’s a brief, completely contrived, example from the unit tests:

from injector import Injector, Module, Key, injects, provides

Weight = Key('Weight')
Age = Key('Age')

class MyModule(Module):
    @provides(Weight)
    def provide_weight(self):
        return 50.0

    @provides(Age)
    def provide_age(self):
        return 25

    # TODO(alec) Make provides/inject order independent.
    @provides(str)
    @inject(age=Age, weight=Weight)
    def provide_description(self, age, weight):
        return 'Bob is %d and weighs %0.1fkg' % (age, weight)

assert_equal(Injector(MyModule()).get(str), 'Bob is 25 and weighs 50.0kg')

Project details


Download files

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

Source Distribution

injector-0.1.tar.gz (5.0 kB view details)

Uploaded Source

File details

Details for the file injector-0.1.tar.gz.

File metadata

  • Download URL: injector-0.1.tar.gz
  • Upload date:
  • Size: 5.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for injector-0.1.tar.gz
Algorithm Hash digest
SHA256 7b204f0422fd6e4c8ef98a2773e78709074cb69384dd2f9702e68117d8b1c795
MD5 4ac80f96442462145594c0aa10efb257
BLAKE2b-256 d8d612f5ab9f6463f010892062b7cea82070881e557755dfa2e349cbf270a431

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page