A simple Inversion of Control container
Project description
Installation
This library is a Python 3.2 library.
Install it via pip for Python 3:
sudo pip3 install pymple
Usage
Pymple nows three types of parameters:
Values: A value is simply value that is saved and reused for all other factories/singletons
Singletons: A singleton is a callable that is executed once and the result is saved so future calls to the build method will return the same instance
Factories: A factory is callable that is executed again everytime it is accessed
from pymple.container import Container
# register simple values
container.register('param', 2)
container.build('param') == 2 # True
# register singletons
class MyClass:
def __init__(self, value):
self.value = value
container.register_singleton('MyClass', lambda x: MyClass(x.build('param')))
container.build('MyClass') == container.build('MyClass') # True
container.build('MyClass').value == 2 # True
# register factories (no instance will be saved)
container.register_factory('MyClass', lambda x: MyClass(x.build('param')))
container.build('MyClass') == container.build('MyClass') # False
container.build('MyClass').value == 2 # True
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
pymple-0.0.1.tar.gz
(14.2 kB
view details)
File details
Details for the file pymple-0.0.1.tar.gz.
File metadata
- Download URL: pymple-0.0.1.tar.gz
- Upload date:
- Size: 14.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
30b5eecd74f550f9341f65762e73c821e9bad6d576108ca32dfbda9fc632d025
|
|
| MD5 |
0644e03717412b057fa8f46ce07893d6
|
|
| BLAKE2b-256 |
0805888353d9c94e573dc7c8fe3e6a1d52d534be606da99d6713c51de61c0130
|