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.com/ikalnytskyi/picobox.svg?branch=master 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, contextvars).

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

  • Thread-safe.

  • Lightweight (~213 LOC including scopes).

  • Zero dependencies (on python3).

  • 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-2.2.0.tar.gz (30.2 kB view details)

Uploaded Source

Built Distribution

picobox-2.2.0-py2.py3-none-any.whl (12.4 kB view details)

Uploaded Python 2 Python 3

File details

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

File metadata

  • Download URL: picobox-2.2.0.tar.gz
  • Upload date:
  • Size: 30.2 kB
  • Tags: Source
  • Uploaded using 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.28.1 CPython/2.7.14

File hashes

Hashes for picobox-2.2.0.tar.gz
Algorithm Hash digest
SHA256 c446ea34b5ee396ab8dc7cbed8f036e73e52403593088656b9b45b7d6382c926
MD5 c88674f252ea19bb332654329b58daa9
BLAKE2b-256 a214e8d9f54b2344c7bae1c0accf6bedd80658e0e9157e7a8aff4f1e86a8e1ef

See more details on using hashes here.

Provenance

File details

Details for the file picobox-2.2.0-py2.py3-none-any.whl.

File metadata

  • Download URL: picobox-2.2.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 12.4 kB
  • Tags: Python 2, Python 3
  • Uploaded using 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.28.1 CPython/2.7.14

File hashes

Hashes for picobox-2.2.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 0a14f8fae386a46e61671a3ce16e0d54d24fb8f15169b0971483228a3e274622
MD5 0ad3edb58bcc8bf876520a0a01fc1a0b
BLAKE2b-256 939c138280941d49dca7d4b19853f24110eaabf0113434b8f047b8d53923625e

See more details on using hashes here.

Provenance

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