Simple library for passing values deeply
Project description
Supplier: Python library for passing values deeply, easily!
Have you ever had a piece of configuration that you want access to deeply in a function, but you don't want to always have to pass it, and you don't want to have a singleton?
This is for you!
Example
from supplier import Supplier, supply
config_supplier = Supplier('config')
def outer_function():
inner_function()
@supply(config_supplier)
def inner_function(config):
do_something_based_on(config)
with config_supplier.use(Config()):
outer_function()
This is essentially python contextvars + contextlib in one convenient package
@supply allows multiple function arguments
Supplier prepends the function's arguments with the supplied value.
@supply(foo_supplier)
def func_with_args(foo, arg1, arg2):
print(foo, arg1, arg2)
with foo_supplier.use("foo"):
func_with_args("arg1", "arg2")
@supply works with multiple suppliers
You can supply multiple variables simultaneously.
@supply(foo_supplier, bar_supplier)
def doubly_provided_func(foo, bar, arg):
print(foo, bar, arg)
with foo_supplier.use("foo"), bar_supplier.use("bar"):
doubly_provided_func("arg")
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
supplier-0.0.1.tar.gz
(2.5 kB
view details)
Built Distribution
File details
Details for the file supplier-0.0.1.tar.gz
.
File metadata
- Download URL: supplier-0.0.1.tar.gz
- Upload date:
- Size: 2.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.8.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 868a89b125d1cec9f0585d345bd81441a0a51ebc266304185c052d7c23b7791e |
|
MD5 | e531fc1edb6c23ef4f72e54cab8038ec |
|
BLAKE2b-256 | 340475a94f9bc7e3feb594b94ab9bbe3ea43f68843cd1a61521d260c4f3f9427 |
File details
Details for the file supplier-0.0.1-py3-none-any.whl
.
File metadata
- Download URL: supplier-0.0.1-py3-none-any.whl
- Upload date:
- Size: 2.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.8.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 41dca093e58527f23052b38b35f835257382941554091f0bdd318c122d08d9a7 |
|
MD5 | 706f9bc79fdbe3828694169764695837 |
|
BLAKE2b-256 | 95f0283274ff1a84ac39fdb100294f4ce5621ef5cf7d6b90199910e1da7f8119 |