Skip to main content

Dependency injection framework designed with Python in mind.

Project description

https://img.shields.io/pypi/v/picobox.svg https://travis-ci.org/ikalnytskyi/picobox.svg https://codecov.io/gh/ikalnytskyi/picobox/branch/master/graph/badge.svg https://img.shields.io/badge/Say%20Thanks-!-1EAEDB.svg

Picobox is opinionated dependency injection framework designed to be clean, pragmatic and with Python in mind. No complex graphs, no implicit injections, no type bindings – just picoboxes, and explicit demands!

Why?

Because we usually want to decouple our code and Python lack of clean and pragmatic solutions (even third parties).

Features

  • Support both values and factories.

  • Support scopes (e.g. singleton, threadlocal).

  • Push boxes on stack, and use the top one to access values.

  • Thread-safe.

  • Lightweight ( ~141 LOC ).

  • Zero dependencies.

  • Pure Python.

Quickstart

First

$ [sudo] python -m pip install picobox

and then

import picobox
import requests

@picobox.pass_('conf')
@picobox.pass_('requests', as_='session')
def get_resource(uri, session, conf):
    return session.get(conf['base_uri'] + uri)

box = picobox.Box()
box.put('conf', {'base_uri': 'http://example.com'})
box.put('requests', factory=requests.Session, scope=picobox.threadlocal)

with picobox.push(box):
    get_resource('/resource', requests.Session(), {})
    get_resource('/resource', requests.Session())
    get_resource('/resource')

Project details


Download files

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

Source Distribution

picobox-1.1.0.tar.gz (24.2 kB view details)

Uploaded Source

File details

Details for the file picobox-1.1.0.tar.gz.

File metadata

  • Download URL: picobox-1.1.0.tar.gz
  • Upload date:
  • Size: 24.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for picobox-1.1.0.tar.gz
Algorithm Hash digest
SHA256 7366b336a36353aa181886f4128c3cb1bb4fdee7589bc8da8dd3eb81fc504ee9
MD5 b74a3fbcf55ea67d2af2f31e6e98d348
BLAKE2b-256 51e45145cfe8f8883c878efbbda4d788070edf1a9a08c203db36d4121f1b52ec

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page