General purpose asyncio service loader and dependency injector
Project description
a plugin mechanic
I want to have a plugin mechanic similar to Pyramid's aproach. It should provide means to spawn arbitrary tasks to run, where every lifecycle stage should be yielded to the developer control.
You bootstrap like following:
from buvar import plugin, components
plugin.run("some.module.with.plugin.function")
# some.module.with.plugin.function
from buvar import context
# you may omit include in arguments
async def plugin(include):
await include('.another.plugin')
# create some long lasting components
my_component = context.add("some value")
async def task():
asyncio.sleep(1)
async def server():
await asyncio.Future()
# you may run simple tasks
yield task()
# you may run server tasks
yield server()
a components and dependency injection solution
I want to have some utility to store some long lasting means of aid to my business problem. I want a non-verbose lookup to those.
from buvar import di
class Bar:
pass
class Foo:
def __init__(self, bar: Bar = None):
self.bar = bar
@di.register
async def adapt(cls, baz: str) -> Foo:
return Foo()
@di.register
async def adapt(bar: Bar) -> Foo
foo = Foo(bar)
return foo
async def task():
foo = await di.nject(Foo, baz="baz")
assert foo.bar is None
bar = Bar()
foo = await di.nject(Foo, bar=bar)
assert foo.bar is bar
a config source
I want to have a config source, which automatically applies environment variables to the defaults.
config.toml
log_level = "DEBUG"
show_warnings = "yes"
[foobar]
some = "value"
export APP_FOOBAR_SOME=thing
import attr
import toml
from buvar import config
@attr.s(auto_attribs=True)
class GeneralConfig:
log_level: str = "INFO"
show_warnings: bool = config.bool_var(False)
@attr.s(auto_attribs=True)
class FoobarConfig:
some: str
source = config.ConfigSource(toml.load('config.toml'), env_prefix="APP")
general_config = source.load(GeneralConfig)
assert general_config == GeneralConfig(log_level="DEBUG", show_warnings=True)
foobar_config = source.load(FoobarConfig, 'foobar')
assert foobar_config.some == "thing"
a structlog
I want to have a nice and readable structlog in my terminal and a json log in production.
import sys
from buvar import log
log.setup_logging(sys.stdout.isatty(), general_config.log_level)
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
File details
Details for the file buvar-0.10.0.tar.gz
.
File metadata
- Download URL: buvar-0.10.0.tar.gz
- Upload date:
- Size: 23.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | db7cdf158b24ddda9247c6a0979521d0d782ac9543fefa833cf7636d9f9096cf |
|
MD5 | 5ce4cd22e19fe708381514f80fd99c82 |
|
BLAKE2b-256 | 0daa5521fdebcaacaa83a33fa741d53b7cc5f82a8d1faf9495c6f2b2dd9709cb |