You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

ooze

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ooze

Brain-dead simple dependency injection

1.0.1
pipPyPI
Maintainers
1

OOZE - Brain-dead simple dependency injection

Ooze is an attempt to do depdency injection in Python in the simplest way possible. It embraces Python decorators to leverage what classes, functions, and even static values are included in the dependency injection graph. You can get started in three easy steps:

  • decorate your functions, classes and/or variable items
  • assign a startup function
  • call ooze's run() function

That's it! Here's a quick example:

import ooze

@ooze.provide                       # Inject as 'upper_case' since a name wasn't specified
def upper_case(string):
    return string.upper()


ooze.provide_static('address', {    # Inject a static dictionary, naming it 'address'
    "name": "Steve",
    "gender": "male"
})


@ooze.provide('greeter')            # Inject as 'greeter'
class WelcomeWagon:
    def __init__(self, upper_case, address):
        self.address = address
        self.upper = upper_case

    def greet(self):
        return self.upper(f"Hello {self.address['name']}")


@ooze.startup               # Define where ooze should start running your program
def main(greeter):
    print(greeter.greet())


if __name__ == '__main__':
    ooze.run()

Installing Ooze

Installing Ooze is as simple as using pip:

$ pip install ooze

Usage Notes

Ooze has many features beyond what is demonstrated in the above sample code including:

  • factories
  • automatic environment variable injection
  • automatic configuration file parsing and settings injection
  • automatic (magic) integration with manually passed arguments
  • seamless integration with bottlepy
  • injectable object pools (i.e. Database connection pools)

Be sure to check out the documentation or examples for more information.

FAQs

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts