Busie Flask Helper
A package to help with common initialization code across Busie Flask projects
Helpful for use with the application factory pattern. Allows for modularization of initialization code, such that factories are not cluttered with boilerplate initialization
Installation
pip install busie-flask-helper
Usage
# in app.py, or wherever application initialization lives
from busie_flask import FlaskHelper
helper = FlaskHelper('abs/path/to/project/')
db = helper.db
auth = helper.auth
cache = helper.cache
# Other Initialization Code omitted
def create_app():
app = Flask(__name__)
# Other App Factory initialization omitted
# this invocation initializes all of the helper objects with the application
# this includes migration commands, models, views, auth, cache client, orm
helper.init_app(app, 'relative/path/to/models', '/relative/path/to/views')
return app
# in some module, maybe an API View
from flask import request
from src.app import auth
class SomeView(MethodView):
def get(self):
decoded_token = auth.handle_auth_header(auth_header=request.headers.get('Authorization'))
# Rest of application api view code
API
FlaskHelper
Public Properties
db<[SQLAlchemy] (https://flask-sqlalchemy.palletsprojects.com/en/2.x/)>auth<[AuthHelper] (#authhelper)>cache<[CacheClient] (#cacheclient)>
Public Methods
FlaskHelper(root_dir, app=None, models_dir=None, views_dir=None)- param
root_dir: The root directory of the project, best practice to pass an abspath here. if your application lives in src/app then your root dir should be src/ - See
init_appmethod documentation for specifics on the other params
- param
init_app(self, app, models_dir, views_dir)- param
app: A Flask application instance - param
models_dir: Relative path to the models directory, with respect to the root_dir that the helper was initialized with - param
views_dir: same asmodels_dir, but for views
- param
AuthHelper
Public Properties
JWTPayload<[JWTPaylaod] (#jwtpayload)>: Custom Payload for JWT with validation and defaultsAuthenticationSignExceptionAuthenticationVerificationException
Public Methods
AuthHelper(app=None): Constructorinit_app(self, app): Initialize the AuthHelper with a Flask application- param
app: A Flask application instance. app.config must haveAUTH_SECRET
- param
JWTPayload
Public Properties
sub: REQUIRED The subject of the jwt, should be astringin most casesrole: REQUIRED The subjects 'role' within the system (i.e superadmin, user, etc.)org: REQUIRED The subject's organizationiat: DEFAULT SUPPLIED POSIX timestamp (seconds) of issue date, defaults to utcnowexp: DEFAULT SUPPLIED POSIX timestamp (seconds) of expiration date (defaults to 15 minutes fromiat)
Public Methods
json(self): JSON-ifies the JWT Payload claims.
CacheClient
Public Properties
redis: The redis instance. Allows for direct interation with the python Redis API
Public Methods
CacheClient(app=None): Constructorinit_app(self, app): Initialize the redis client with application.- param
app: A Flask application instance. app.config must haveREDIS_HOSTREDIS_PORTandREDIS_DB. NOTEREDIS_PASSWORDis also used, but this method will not throw without it
- param
get: Alias for redis.getset: Alias for redis.set
Metadata
Release files for busie-flask-helper 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 | |
|---|---|---|---|
| busie-flask-helper-1.1.1.tar.gz | 10.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| busie_flask_helper-1.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 25.0 kB
Release files / busie-flask-helper-1.1.1.tar.gz
| Download URL | busie-flask-helper-1.1.1.tar.gz |
|---|---|
| Size | 10.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2e05c4dab54bae554116ea226e278a12fd2318600693595d45eba8e6ca158507
|
|
BLAKE2b-256 checksum How to use checksums |
17792e53849566b04f78b158a89d16dae20c1d86035f84787ab3b8a96eb81e6b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.12.1 pkginfo/1.6.0 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.7.9
|
Release files / busie_flask_helper-1.1.1-py3-none-any.whl
| Download URL | busie_flask_helper-1.1.1-py3-none-any.whl |
|---|---|
| Size | 14.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
df10d6d40fd8deea584079b367f1f45799314b9bd461ce7d2416f11715e05583
|
|
BLAKE2b-256 checksum How to use checksums |
2656e88b826d576f40ce266c078f9c95682e38ecea4fdd510281c6e93455a1f0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.12.1 pkginfo/1.6.0 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.7.9
|