Socket
Book a DemoInstallSign in
Socket

picobox

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

picobox

Dependency injection framework designed with Python in mind.

Source
pipPyPI
Version
4.0.0
Maintainers
1

Picobox

.. image:: https://img.shields.io/pypi/l/picobox :target: https://pypi.python.org/pypi/picobox :alt: PyPI - License

.. image:: https://img.shields.io/pypi/v/picobox.svg :target: https://pypi.python.org/pypi/picobox :alt: PyPI - Version

.. image:: https://img.shields.io/pypi/pyversions/picobox :target: https://pypi.python.org/pypi/picobox :alt: PyPI - Python Versions

.. image:: https://img.shields.io/pypi/dm/picobox :target: https://pypi.python.org/pypi/picobox :alt: 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

.. code:: bash

$ [sudo] python -m pip install picobox

and then

.. code:: python

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")

FAQs

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.