https://github.com/ekiro/haps
Pure Python dependency injection library
https://github.com/ekiro/haps
annotations dependency-injection python python3
Last synced: 10 months ago
JSON representation
Pure Python dependency injection library
- Host: GitHub
- URL: https://github.com/ekiro/haps
- Owner: ekiro
- License: mit
- Created: 2017-04-25T11:19:29.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2022-02-04T20:15:20.000Z (over 4 years ago)
- Last Synced: 2025-07-17T11:23:45.856Z (11 months ago)
- Topics: annotations, dependency-injection, python, python3
- Language: Python
- Size: 93.8 KB
- Stars: 49
- Watchers: 6
- Forks: 3
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# haps [](https://pypi.python.org/pypi/haps/) [](https://github.com/lunarwings/haps/actions/workflows/python-app.yml)
Haps [χaps] is a simple DI library, with IoC container included. It is written in pure Python with no external dependencies.
Look how easy it is to use:
```python
from haps import Container as IoC, Inject, inject
# import interfaces
from my_application.core import IDatabase, IUserService
class MyApp:
db: IDatabase = Inject() # dependency as a property
@inject # or passed to the constructor
def __init__(self, user_service: IUserService) -> None:
self.user_service = user_service
IoC.autodiscover('my_application') # find all interfaces and implementations
if __name__ == '__main__':
app = MyApp()
assert isinstance(app.db, IDatabase)
assert isinstance(app.user_service, IUserService)
```
# Installation
pip install haps
# Documentation
See https://haps.readthedocs.io/en/latest/
# Usage examples
See https://github.com/lunarwings/haps/tree/master/samples
# Testing
Install `requirements.test.txt` and run `py.test` in main directory.
# Changelog
## 1.1.3 (2022-02-04)
- Add `>>` operator
- Add `DI` alias
- ~~Update~~ Remove `.travis.yml`
- Setup GitHub actions
## 1.1.1 (2018-07-27)
- Fix bug with optional arguments for functions decorated with `@inject`
## 1.1.0 (2018-07-26)
- Add configuration module
- Add application class and runner
- Add profiles
- Minor fixes
## 1.0.5 (2018-07-12)
- `@egg` decorator can be used without function invocation
## 1.0.4 (2018-06-30)
- Add support for python 3.7
- Fix autodiscover sample
## 1.0.0 (2018-06-15)
- First stable release