Skip to main content
Knot Injector
========

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

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

knot-injector-0.0.3.tar.gz (3.4 kB view details)

Uploaded Source

File details

Details for the file knot-injector-0.0.3.tar.gz.

File metadata

  • Download URL: knot-injector-0.0.3.tar.gz
  • Upload date:
  • Size: 3.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for knot-injector-0.0.3.tar.gz
Algorithm Hash digest
SHA256 edbb3bf69efd8420c836ed91ed1f74cbbcf68344ac6aded8fa3f5a3763be480d
MD5 2e7ea95304f6092f2caed3869ea0a49b
BLAKE2b-256 eb2f27d7b443fc881f0c18a5d9fc2380ebd958e586fbd2844136c0deb8d95266

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.0.3 This release

1 file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page