# pyhooker
Lightweight and easy-to-use python dependency injection library
Pyhooker is ready to use for Python >=2.7 and >=3.2
[](https://travis-ci.org/sighalt/pyhooker)
## Installation
```
pip install git+https://github.com/sighalt/pyhooker.git
```
## Usage
```python
import pyhooker
# wheel.py
class IWheel(object):
pass
class MichelinWheel(IWheel):
pass
# engine.py
class IEngine(object):
pass
class OttoEngine(IEngine):
pass
# car.py
class ICar(object):
pass
class Car(ICar):
@pyhooker.inject_params(engine=IEngine, wheel_type=IWheel)
def __init__(self, engine, wheel_type):
self.engine = engine
self.wheel_type = wheel_type
# driver.py
class Driver(object):
@pyhooker.inject_params(car=ICar)
def __init__(self, car):
self.car = car
# __init__.py
pyhooker.register(ICar, Car)
pyhooker.register(IEngine, OttoEngine)
pyhooker.register(IWheel, MichelinWheel)
driver = Driver()
print("The driver is %s\n... with its car %s\n... and engine %s\n... and wheel type %s" % (driver,
driver.car,
driver.car.engine,
driver.car.wheel_type))
```
Lightweight and easy-to-use python dependency injection library
Pyhooker is ready to use for Python >=2.7 and >=3.2
[](https://travis-ci.org/sighalt/pyhooker)
## Installation
```
pip install git+https://github.com/sighalt/pyhooker.git
```
## Usage
```python
import pyhooker
# wheel.py
class IWheel(object):
pass
class MichelinWheel(IWheel):
pass
# engine.py
class IEngine(object):
pass
class OttoEngine(IEngine):
pass
# car.py
class ICar(object):
pass
class Car(ICar):
@pyhooker.inject_params(engine=IEngine, wheel_type=IWheel)
def __init__(self, engine, wheel_type):
self.engine = engine
self.wheel_type = wheel_type
# driver.py
class Driver(object):
@pyhooker.inject_params(car=ICar)
def __init__(self, car):
self.car = car
# __init__.py
pyhooker.register(ICar, Car)
pyhooker.register(IEngine, OttoEngine)
pyhooker.register(IWheel, MichelinWheel)
driver = Driver()
print("The driver is %s\n... with its car %s\n... and engine %s\n... and wheel type %s" % (driver,
driver.car,
driver.car.engine,
driver.car.wheel_type))
```
Metadata
Release files for pyhooker 1.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| pyhooker-1.0.1.tar.gz | 25.7 kB | Without provenance | Details |
Release files / pyhooker-1.0.1.tar.gz
| Download URL | pyhooker-1.0.1.tar.gz |
|---|---|
| Size | 25.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d2e734197d9bcfe0610c1c17b8144aabf7486da64ff1ecc4244ad699a71afa85
|
|
BLAKE2b-256 checksum How to use checksums |
8ba569a58844c2e9225ee73b50f8d983039de4f31dca5cf9024bae74bbf83cbb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for pyhooker 1.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.