Flask-Super
"Any sufficiently complicated Python program contains an ad-hoc, informally-specified bug-ridden slow implementation of half of the Zope Component Architecture." (S. Fermigier, December 2023).
Flask patterns and idoms
- Free software: Apache Software License 2.0
Features
- Decorator-based registration system for services (using svcs)
- Powerful inspection CLI command (
flask inspectandflask config). - Flask initialisation helpers.
Status
This is a preview. Expect the API to change.
Sample usage
import svcs
from flask import Flask
from flask_super import register_services
from flask_super.scanner import scan_package
# Assuming you have developped the proper decorators and registration logic
# in app.lib (or any other module)
from app.lib import register_routes, register_components
def create_app():
app = Flask(__name__)
svcs.flask.init_app(app)
scan_package("app.services")
register_services(app)
# Or just scan a package if using a framework like SQLAlchemy which
# automatically registers classes on import
scan_package("app.models")
# You may also scan custom things (e.g. models, routes, components, etc.)
scan_package("app.routes")
register_routes(app)
scan_package("app.components")
register_components(app)
return app
app = create_app()
Currently, flask-super provides the following decorators:
@service: register a service with a per-request lifecycle (on thesvcsregistry)@singleton: register a singleton service (on thesvcsregistry)
A real-life example
Here is the initialisation code of a Flask application using flask-super:
def create_app(config: Any = None) -> Flask:
# When testing
if config:
app = Flask(__name__)
app.config.from_object(config)
# Otherwise
else:
# Not needed when called from CLI, but needed when
# called from a WSGI server
load_dotenv(verbose=True)
app = Flask(__name__)
app.config.from_prefixed_env()
finish_config(app)
init_app(app)
return app
def finish_config(app: Flask):
app.config.from_object("app.config.Config")
def init_app(app: Flask):
# First: Logging & Observability (e.g. sentry)
init_logging(app)
# Scan modules that may provide side effects
scan_package("app.models")
scan_package("app.services")
scan_package("app.controllers")
scan_package("app.cli")
# Scan 3rd-party modules
scan_package("flask_super")
# Extensions, then services
init_extensions(app)
svcs.flask.init_app(app)
register_services(app)
# Web
register_views(app)
register_controllers(app)
# Security
register_rules()
# CLI
register_commands(app)
Credits
This package was created with Cruft and the abilian/cookiecutter-abilian-python project template.
Metadata
Release files for flask-super 0.2.12
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 | Actions |
|---|---|---|---|---|
| flask_super-0.2.12.tar.gz | 6.0 kB | Without provenance | Details for flask_super-0.2.12.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| flask_super-0.2.12-py3-none-any.whl | Python 3 | none | any | Details for flask_super-0.2.12-py3-none-any.whl |
Total release size: 15.4 kB
Release files / flask_super-0.2.12.tar.gz
| Download URL | flask_super-0.2.12.tar.gz |
|---|---|
| Size | 6.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b8423c09c3fb5d68a56dd972c075b0f5c4b20da5d9875ace1435d3f3bf31351a
|
|
BLAKE2b-256 checksum How to use checksums |
09f94c932670f608d262666fc4b71e29a219affc3e4db34c4cd0598d4263f70f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.11
|
Release files / flask_super-0.2.12-py3-none-any.whl
| Download URL | flask_super-0.2.12-py3-none-any.whl |
|---|---|
| Size | 9.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1f2eec3f58762eb18adc7f33d9f59b2a362cc95a8c8308c28e41ec7a0c981c67
|
|
BLAKE2b-256 checksum How to use checksums |
7af8b21f8b521bc7b4595c68e5323b45aacb5d3eaa1abbe532730eb7345ac386
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.11
|
Security for flask-super 0.2.12
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.