GithubHelp home page GithubHelp logo

pavalso / potage Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 147 KB

A simple Python package that provides an easy way to use Dependency Injection in your projects.

Home Page: https://pypotage.readthedocs.io

License: MIT License

Python 100.00%
beans python dependency-injection development utility dependency-injection-container dependency-injection-framework design-patterns factory ioc

potage's Introduction

pypotage

img img python-package-yml codecov

A simple Python package that provides an easy way to use Dependency Injection in your projects.

alt text

Key Features

  • Easy to use
  • Supports both function and class-based dependency injection
  • Allows customizing the way dependencies are resolved
  • Allows for the use of custom containers

Installing

To install the latest pypotage version, run the following command:

python -m pip install -U pypotage

Development

To install the development version:

git clone https://github.com/pavalso/potage.git
cd potage
python -m pip install -U .

Quick Examples

Basic usage

import pypotage
import logging

@pypotage.prepare
def logger():
    logging.basicConfig(level=logging.DEBUG)
    return logging.getLogger(__name__)

pypotage.cook(logging.Logger).take_out().info("Hello World!")

Using classes

import pypotage

class A:
    def __init__(self):
        ...

@pypotage.prepare
class B(A):
    def __init__(self):
        ...

pypotage.cook(A).take_out()  # returns an instance of B

potage's People

Contributors

pavalso avatar

Stargazers

 avatar

Watchers

 avatar

potage's Issues

Generic multiple inheritance throws ingredient not found when cooking parent2

@pypotage.prepare
class SpecificChild(Parent1[int], Parent2[str]):
pass

pypotage.cook(Parent2[str]).take_out() <-- Raises RuntimeError

GenericChef._modify_formula:
...
elif hasattr(formula._type, "orig_bases"):
generic_type = formula._type.orig_bases[0].args <--- Just Parent1 is taken into account
formula.extra["generic_type"] = generic_type
...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.