Skip to main content

Discover packages and classes in a python project.

Project description

Deescovery

Micro-framework initialization problem

Micro-framework-based projects are clean while they're small. Every micro-framework codebase I've seen, has a mess in the project initialization. With time, create_app() becomes filled with ad-hoc settings, imports-within-functions, and plug-in initializations.

The Application Factory Pattern, proposed, for example, in the official Flask documentation, and the Flask Mega-Tutorial, legitimize this approach.

The nature of create_app() leaves no place for the open-closed principle. We update this module every time we add a new plug-in, a new blueprint, or a new package.

# myproject/__ini__.py
#
# A common Flask application. The code is based on the Flask Mega-Tutorial.

def create_app(config_class=Config):
    app = Flask(__name__)
    app.config.from_object(config_class)

    db.init_app(app)
    migrate.init_app(app, db)
    login.init_app(app)
    mail.init_app(app)
    bootstrap.init_app(app)
    moment.init_app(app)
    babel.init_app(app)

    from myproject.errors import bp as errors_bp
    app.register_blueprint(errors_bp)

    from myproject.auth import bp as auth_bp
    app.register_blueprint(auth_bp, url_prefix='/auth')

    return app

A common Flask application. The code is based on the Flask Mega-Tutorial.

With deescovery, you can make the same code shorter, and remove the dependencies from implementation details.

# file: myproject/app.py
from flask import Flask
from deescovery import discover
from deescovery.flask import get_flask_rules


def create_app():
    flask_app = Flask(__name__)
    flask_app.config.from_object("myproject.config")
    discover("myproject", get_flask_rules("myproject", flask_app))
    return flask_app

Initially designed to solve a specific problem of initializing Flask applications, it was made generic enough to work with any micro-framework or no framework at all.

Read more

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

deescovery-1.0.0.tar.gz (9.4 kB view details)

Uploaded Source

Built Distribution

deescovery-1.0.0-py3-none-any.whl (8.5 kB view details)

Uploaded Python 3

File details

Details for the file deescovery-1.0.0.tar.gz.

File metadata

  • Download URL: deescovery-1.0.0.tar.gz
  • Upload date:
  • Size: 9.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.4

File hashes

Hashes for deescovery-1.0.0.tar.gz
Algorithm Hash digest
SHA256 a56341ed0193fa56b25aaf9cc21e66eb2729a2fe90eb86f2a47d0422361d16fe
MD5 c394151df7280c100ca5eb886285b7e7
BLAKE2b-256 c5f4f7646a8c84897ea24b58829c1364456d35c14b14c899114bcbf5ce2a19b3

See more details on using hashes here.

Provenance

File details

Details for the file deescovery-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: deescovery-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 8.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.4

File hashes

Hashes for deescovery-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c0c20f52fef901a7d1f33e95687b26003944d7a34e231275d83aca05d38a5c07
MD5 22c97273f04b3d5b6bd7b2eaaa354ca5
BLAKE2b-256 abab4728a53509e680b2d415de4428a61aa910cb0e5c475dd8fc0c9553230fb0

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page