========
Framework agnostic dependency injections
This library build as a wrapper for `Knot`_ Dependencies Container.
Installation
------------
``pip install knot-injector``
Usage
-----
Example:
.. code:: python
import sqlalchemy as db
from sqlalchemy.orm import sessionmaker
from knot_injector import Container
registry = Container()
settings = {
'db': {
'uri': 'sqlite://',
'echo': False,
'encoding': 'utf8',
},
}
registry.add_service(lambda _: settings, name='settings')
@registry.service()
def dbengine(container, settings):
uri = settings['db']['uri']
return create_engine(uri, **settings['db'])
@registry.factory(name='dbsession')
def database_session(container, dbengine):
session = sessionmaker()
session.configure(bind=dbengine)
return session()
class ItemResource(object):
@registry.inject
def on_get(request, response, item_id, dbsession):
response.data = dbsession.query(Item).filter(Item.id == item_id).one()
.. _Knot: https://github.com/jaapverloop/knot
Metadata
Release files for knot-injector 0.0.3
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 | Actions |
|---|---|---|---|---|
| knot-injector-0.0.3.tar.gz | 3.4 kB | Without provenance | Details for knot-injector-0.0.3.tar.gz |
Release files / knot-injector-0.0.3.tar.gz
| Download URL | knot-injector-0.0.3.tar.gz |
|---|---|
| Size | 3.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
edbb3bf69efd8420c836ed91ed1f74cbbcf68344ac6aded8fa3f5a3763be480d
|
|
BLAKE2b-256 checksum How to use checksums |
eb2f27d7b443fc881f0c18a5d9fc2380ebd958e586fbd2844136c0deb8d95266
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for knot-injector 0.0.3
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.
To learn more about protecting yourself from malicious actors, visit our package security documentation.