Skip to main content

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

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_app method documentation for specifics on the other params
  • 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 as models_dir, but for views

AuthHelper

Public Properties

None

Public Methods

  • AuthHelper(app=None): Constructor
  • init_app(self, app): Initialize the AuthHelper with a Flask application
    • param app: A Flask application instance. app.config must have AUTH0_AUDIENCE AUTH0_DOMAIN and AUTH0_ALGORITHMS
  • requires_auth(self, f): A decorator for views that require the auth flow. This is most likely what will be used when using this package/class
  • get_rsa_key_from_unverified_token(self, token): Determines the RSA key to use from the token's kid
    • param token: A json web token with appropriate headers
    • return: rsa_key (dict) or None
  • handle_rsa_decode(self, rsa_key, token): decodes the token using rsa
    • param rsa_key: dict representation of an RSA key
    • param token: a json web token with necessary claims
  • requires_scope(self, required_scope): determine if the auth token has the provided required scope
    • param required_scope: string, the desired scope for the resource
    • return: bool
  • static -> get_token_auth_header(): gets the auth header from the request context and formats it properly
    • return: str

CacheClient

Public Properties

  • redis: The redis instance. Allows for direct interation with the python Redis API

Public Methods

  • CacheClient(app=None): Constructor
  • init_app(self, app): Initialize the redis client with application.
    • param app: A Flask application instance. app.config must have REDIS_HOST REDIS_PORT and REDIS_DB. NOTE REDIS_PASSWORD is also used, but this method will not throw without it
  • get: Alias for redis.get
  • set: Alias for redis.set

Metadata

Release files for busie-flask-helper 2.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for busie-flask-helper 2.0.1
File Size Uploaded Provenance Actions
busie-flask-helper-2.0.1.tar.gz 12.1 kB Without provenance Details for busie-flask-helper-2.0.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for busie-flask-helper 2.0.1
File Interpreter ABI Platform Actions
busie_flask_helper-2.0.1-py3-none-any.whl Python 3 none any Details for busie_flask_helper-2.0.1-py3-none-any.whl

Total release size: 28.2 kB

Release files / busie-flask-helper-2.0.1.tar.gz

Download URL busie-flask-helper-2.0.1.tar.gz
Size 12.1 kB
Tags Source
SHA-256 checksum
How to use checksums
f3a83740b9b7dda430a455b77da35c4709874aa1954ee4a138a462bc0ea40a2f
BLAKE2b-256 checksum
How to use checksums
297bc194f920cd7bac6f726b05e38f91885c467626062a02aa3af6e4aaa3f7c0
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-2.0.1-py3-none-any.whl

Download URL busie_flask_helper-2.0.1-py3-none-any.whl
Size 16.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f8f1bf40069499ea8f27ca2f44a4d52ddb4f2ea1e14393aadccedd14b84b5b36
BLAKE2b-256 checksum
How to use checksums
e858e844973e16da6f1dc61f828226856d62aa3cc557cca488e335fda411cabf
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

Security for busie-flask-helper 2.0.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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page