Pychkari
A Very Simple Python Dependency Injector
Installation
Use pip!
pip install pychkari
Overview
Pychkari (pronounced peach kaa ree) is a simple dependency injector for Python. It is intended to be a no-fuss library that depends on as few packages as possible and just works.
This example should get us started!
# Class definitions for reference
class A:
def __init__(self,
depOne, # casing support
second_dep: "DepTwo", # annotations support
const_dep=3): # not a dependency
self.dep1 = depOne
self.dep2 = second_dep
self.const_d = const_dep
class DepOne:
def __init__(self):
self.timestamp = datetime.now()
class DepTwo:
def __init__(self):
self.timestamp = datetime.now()
class B:
def __init__(self, a, dep_one):
self.a = a
self.dep1 = dep_one
# registration
container = Container.instance()
container.register("MyAwesomeService", B) # explicitly named registration
container.register_class(A) # service name "A" implicit
container.register_class(DepOne) # service name "DepOne" implicit
container.register_class(DepTwo) # service name "DepTwo" implicit
# instantiation
service = container.get("MyAwesomeService") # creates instance of "B" with dependencies injected
Features
Lightweight
Pychkari is barely a few kilobytes. It doesn't have third party dependencies. Just drop it into your project and run with it.
Zero Commitment
Pychkari doesn't require you to change your code. As long as common Python conventions are followed, your existing code just works!
No fancy annotations, no decorations, no commitments. You're free to mix and match with any other framework.
This chart should tell you how dependencies are resolved:
| Dependency | Resolved Service Name |
|---|---|
| underscore_case | UnderscoreCase |
| camelCase | CamelCase |
| PascalCase | PascalCase |
| my_Weird_case | MyWeirdCase |
| my_service:HttpClient | HttpClient |
Extensible
Well, sort of! If the conventions don't satisfy your complex naming schemes, you can always make the names explicit by annotating the dependencies.
For example, client:"MyService" will inject and instance of MyService in place of client.
Metadata
Release files for pychkari 1.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pychkari-1.1.2.tar.gz | 4.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pychkari-1.1.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 22.3 kB
Release files / pychkari-1.1.2.tar.gz
| Download URL | pychkari-1.1.2.tar.gz |
|---|---|
| Size | 4.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2eef60f8d9aeec3133f907e7dcea9ed52302e2eedc236d8aaaca242ae1d17970
|
|
BLAKE2b-256 checksum How to use checksums |
88be99bf186c1d23086f82c2c6a899cd1d0cfb610b0e4b578beca36f9f7ae790
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.29.0 CPython/3.4.6
|
Release files / pychkari-1.1.2-py3-none-any.whl
| Download URL | pychkari-1.1.2-py3-none-any.whl |
|---|---|
| Size | 17.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5550873246cc856d6fc27f07c6d252938d8c8d80223d91c16abd0561b2ef4e03
|
|
BLAKE2b-256 checksum How to use checksums |
a8e879bbcc510adc6d0889e36fc63bea7a9fad6491cb5cbf8d6b2a70fd12576a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.29.0 CPython/3.4.6
|