Skip to main content

Dependency injection framework designed with Python in mind.

Project description

PyPI - License PyPI - Version PyPI - Python Versions PyPI - Downloads

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 (~500 LOC including scopes).

  • Zero dependencies.

  • Pure Python.

  • Annotated with types.

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-4.0.0.tar.gz (22.7 kB view hashes)

Uploaded Source

Built Distribution

picobox-4.0.0-py3-none-any.whl (11.6 kB view hashes)

Uploaded Python 3

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