Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/duolingo/minject
A little dependency injection framework for Python.
https://github.com/duolingo/minject
dependency-injection ioc python
Last synced: about 1 month ago
JSON representation
A little dependency injection framework for Python.
- Host: GitHub
- URL: https://github.com/duolingo/minject
- Owner: duolingo
- License: apache-2.0
- Created: 2024-02-07T15:31:09.000Z (11 months ago)
- Default Branch: master
- Last Pushed: 2024-11-04T15:22:45.000Z (about 2 months ago)
- Last Synced: 2024-11-04T16:19:33.010Z (about 2 months ago)
- Topics: dependency-injection, ioc, python
- Language: Python
- Homepage:
- Size: 310 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 19
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGES.md
- License: LICENSE
Awesome Lists containing this project
README
# minject
![PyPI version](https://img.shields.io/pypi/v/minject)
[![Unit Tests](https://github.com/duolingo/minject/actions/workflows/hatch_test.yml/badge.svg?branch=master)](https://github.com/duolingo/minject/actions/workflows/hatch_test.yml)
[![Typing](https://github.com/duolingo/minject/actions/workflows/mypy.yml/badge.svg?branch=master)](https://github.com/duolingo/minject/actions/workflows/mypy.yml)[**Philosophy**](#philosophy)
| [**Documentation**](https://github.com/duolingo/minject/blob/master/docs/dependency_injection.md)
| [**PyPI Homepage**](https://pypi.org/project/minject/)## Philosophy
`minject` is a dependency injection tool that aims to be easy to use, easy to understand, and easy to ignore. To
accomplish this we follow these principles:- **Minimize boilerplate**: Adding dependency injection to a class should
require as little extra code as possible. You can add or change a dependency
with only one line of code.
- **Be obvious**: We keep the dependency injection pieces close to the code, not
separated into a different file. You should be able to understand where
and how `minject` is working from looking at the source code.
- **Work as plain Python**: Dependency injection must be easy to ignore. You can
always use `minject` classes as if they were regular classes.Here's an [example](docs/examples/philosophy.py) to demonstrate:
```python
import minject@minject.define
class Engine:
cylinders: int = minject.field(binding=4)@minject.define
class Car:
engine: Engine = minject.field(binding=minject.inject.reference(Engine))
```This code follows the preceding principles in the following ways:
- There isn't much boilerplate: one call to `@minject.define` to mark a class for
injection, and one `minject.field()` to annotate what it depends on.
- These annotations clearly show `minject` is involved and provide a starting
point for learning more.
- If you need to use this class without `minject`
you can call `my_car = Car(my_engine)` and it will work how you'd
expect without any hidden magic.### Documentation
- [Quick start](https://github.com/duolingo/minject/blob/master/docs/dependency_injection.md#quick-start)
- [Fundamentals](https://github.com/duolingo/minject/blob/master/docs/dependency_injection.md#fundamentals)### PyPI
This library is available on PyPI ([Homepage](https://pypi.org/project/minject/))
---