Skip to main content

Dependency injection framework designed with Python in mind.

Project description

https://img.shields.io/pypi/v/picobox.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 (~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-3.0.0.tar.gz (28.6 kB view details)

Uploaded Source

Built Distribution

picobox-3.0.0-py3-none-any.whl (11.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: picobox-3.0.0.tar.gz
  • Upload date:
  • Size: 28.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for picobox-3.0.0.tar.gz
Algorithm Hash digest
SHA256 59d665ee82cafe2de80a6bf9dff407d502bb4688125398eaca05dbe02dbfb07a
MD5 3252da58e9ecd34e0241e3e823cbf9ea
BLAKE2b-256 295862da7083e7d3ce07fb5d13c89636fe8d224083d1d724327636482167dfb9

See more details on using hashes here.

File details

Details for the file picobox-3.0.0-py3-none-any.whl.

File metadata

  • Download URL: picobox-3.0.0-py3-none-any.whl
  • Upload date:
  • Size: 11.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for picobox-3.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 37d00ec92694312eb0a1abad3ecb9d46d4d8ae4f4c26f24fb2eb3910f9a8a792
MD5 369afcd6206b080f72085529553c6278
BLAKE2b-256 268c5f6f6ea1ec78176229e2ed1f619d9cd075ceb4e04d32c1a77918e0bbf7f7

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