Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ikalnytskyi/picobox
Dependency injection framework designed with Python in mind.
https://github.com/ikalnytskyi/picobox
dependency-injection inversion-of-control lightweight micro-framework
Last synced: about 18 hours ago
JSON representation
Dependency injection framework designed with Python in mind.
- Host: GitHub
- URL: https://github.com/ikalnytskyi/picobox
- Owner: ikalnytskyi
- License: mit
- Created: 2017-08-27T13:00:32.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2024-10-18T09:16:50.000Z (27 days ago)
- Last Synced: 2024-11-06T03:47:31.939Z (8 days ago)
- Topics: dependency-injection, inversion-of-control, lightweight, micro-framework
- Language: Python
- Homepage: https://picobox.readthedocs.io
- Size: 282 KB
- Stars: 49
- Watchers: 2
- Forks: 4
- Open Issues: 4
-
Metadata Files:
- Readme: README.rst
- License: LICENSE
Awesome Lists containing this project
README
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 - DownloadsPicobox 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")Links
-----* Documentation: https://picobox.readthedocs.io
* Source: https://github.com/ikalnytskyi/picobox
* Bugs: https://github.com/ikalnytskyi/picobox/issues