Dependency injection framework designed with Python in mind.
Project Links
Meta
Author: Ihor Kalnytskyi
Requires Python: >=3.8
Classifiers
Intended Audience
- Developers
License
- OSI Approved :: MIT License
Operating System
- OS Independent
Programming Language
- Python
- Python :: 3
- Python :: 3.8
- Python :: 3.9
- Python :: 3.10
- Python :: 3.11
- Python :: 3.12
- Python :: Implementation :: CPython
- Python :: Implementation :: PyPy
Topic
- Software Development :: Libraries
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")
Links
Documentation: https://picobox.readthedocs.io
Nov 20, 2023
4.0.0
Apr 02, 2023
3.0.0
Dec 24, 2018
2.2.0
Sep 25, 2018
2.1.0
Mar 18, 2018
2.0.0
Dec 19, 2017
1.1.0
Nov 25, 2017
1.0.0
Wheel compatibility matrix
Files in release
No dependencies