Incremental Module Loader
Proposes a injection pattern for your modules. Each module is simply a callable which takes other named modules as arguments. It is very simple with less than 40 statements of code and allows a great deal of flexibility while still removing frequent boilerplate we had to write on each of our projects.
This module is used by our SpinHub App (https://www.spinhub.ca) which is currently in development. It is the main building block of our module/service based architecture.
Use-Case 1: Modularize a flask app
You have an auth service, a database service and an blueprint creator function. How do you hook all of these together while keeping good separation of concerns and allowing injection of mocked services ? Let's see:
from incremental_module_loader import IncrementalModuleLoader
from flask import request, jsonify
class RequestParsingModule(object):
def get_authorization_header(self):
return request.headers.get('Authorization', None)
class MyAuthModule(object):
def __init__(self, config, request_parser):
self.url = config['AUTH_URL']
self.request_parser = request_parser
def get_user_id_from_token(self):
header = self.request_parser.get_authorization_header()
pass # Extract user id from header token...
class MyDatabaseModule(object):
def __init__(self, config, auth):
self.db_uri = config['SQLALCHEMY_DATABASE_URI']
self.auth = auth
def get_user(self):
user_id = self.auth.get_user_id_from_token()
pass # Retrieve user data from database...
# Note the name of the arguments here:
def route_app(app, config, database):
@app.route('/userinfo')
def userinfo():
# This triggers the auth verification from the header extracted from the request parser
user = database.get_user()
return jsonify(user.dump())
# ...
def create_app():
app = # (...) Standard app creation with config loading
module_loader = IncrementalModuleLoader()
# First init the modules with already created objects:
module_loader.update(
app=app,
config=app.config
)
# Then load in order ("incrementally")
# Make sure to specify a CALLABLE object (function or class)
# The module_loader will call the parameter with the modules it is asking as parameters.
module_loader.load(request_parser=RequestParsingModule)
module_loader.load(auth=MyAuthModule)
module_loader.load(database=MyDatabaseModule)
# Can be loaded anonymously, returns nothing.
module_loader.load(route_app)
# There you have it !
Creators
Created by Tack Verification, a company dedicated to reducing operational costs related to hardware systems verification. https://www.tackv.ca
Metadata
Release files for incremental-module-loader 1.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| incremental_module_loader-1.1.1.tar.gz | 4.1 kB | Without provenance | Details |
Release files / incremental_module_loader-1.1.1.tar.gz
| Download URL | incremental_module_loader-1.1.1.tar.gz |
|---|---|
| Size | 4.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
64eb466e02f9cd407df108136f92b0bd09b2b43ac579c95c5b717421daa7764a
|
|
BLAKE2b-256 checksum How to use checksums |
35f196ff7bddb7fc2ad509bec9cbe2d3a659fbaea3b1a13704679a2d670b6ef7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.4
|
Security for incremental-module-loader 1.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.