Quack Quack: A simple application initializator
Project description
Overview
This project aims to resolve problem of configuring an application, which needs to have initialization step (for example: for gathering settings or establishing connections) and use Python style code (context managers and decorators) with dependency injection to get those data.
For example, normally you would need to use two separate mechanism for connection to the database (one for web, and one for celery). Mostly it uses the web framework configuration, to use in the celery code. It is fine, until a third sub-application arrives. Or you have many microservices, where web frameworks are different depending on the microservice purpose.
Second goal was to make synchronized code without any globals or magic. That is why using Quack Quack you know when the application is initialized (started), or where to look for code you are using.
In order to use QQ, you don’t need to use hacks in some starting files, like importing something from django, starting the application, and the import the rest.
Quick Using Example
To use Quack Quack you need to create the application class (inherited from qq.Application) in which you need to add plugins. After configuring, you need to “start” (initialize) the application. After that you can use the application as context manager. Also, you can make simple decorator, so you can use injectors (dependency injection) in function’s arguments.
from qq import Application
from qq import ApplicationInitializer
from qq import Context
from qq import SimpleInjector
from qq.plugins import SettingsPlugin
from qq.plugins.types import Settings
class MyApplication(Application):
def create_plugins(self):
self.plugins["settings"] = SettingsPlugin("settings")
application = MyApplication()
application.start("application")
with Context(application) as ctx:
print(ctx["settings"])
app = ApplicationInitializer(application)
@app
def samplefun(settings: Settings = SimpleInjector("settings")):
print(settings)
samplefun()
samplefun({"info": "fake settings"}) # dependency injection !!
context["settings"] in above example, is a variable made by the SettingsPlugin. If you would like to know more, please go to the Tutorial
Installation
pip install quackquack
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
Built Distribution
File details
Details for the file quackquack-1.2.1.tar.gz
.
File metadata
- Download URL: quackquack-1.2.1.tar.gz
- Upload date:
- Size: 16.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.1 CPython/3.11.3 Linux/6.4.4-arch1-1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cc159fe5a1a2d0e5a6d0b033fca15a57471cded3b0b80f936cc5821de31595e5 |
|
MD5 | 134618f6362654e08a621a0a4623631b |
|
BLAKE2b-256 | c43c41725c12dbf68f0d7de122794f6bb7ddefbe2ddfcf2b21c4d132cacdb0f1 |
File details
Details for the file quackquack-1.2.1-py3-none-any.whl
.
File metadata
- Download URL: quackquack-1.2.1-py3-none-any.whl
- Upload date:
- Size: 26.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.1 CPython/3.11.3 Linux/6.4.4-arch1-1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 291d033eec071577cd6d4a7255fc4c574ea90ececea77cad2673d1cfb48ad382 |
|
MD5 | 0c7f4f4bfbc846c3a0457965e7fd0a21 |
|
BLAKE2b-256 | d0decaf6e07f4a9063d97df7a1ea588b405dd20310854047ed9db984238f53e0 |