Flask extension for Pypendency, a dependency injection tool
Project description
Flask pypendency extension
Flask extension for Pypendency. Pypendency is a dependency injection library for python 3.6+.
Installation
To install from source, download the source code, then run this:
python setup.py install
Or install with pip:
pip install Flask-Pypendency
Integration with Flask
Adding the extension to your Flask app is simple:
from flask import Flask
from flask_pypendency import Pypendency
app = Flask(__name__)
Pypendency(app)
Usage
Anywhere in your app, you will be able to access the container using the app
from flask import current_app as app
@app.route('/hello')
def hello():
service = app.container.get('my.service')
return service.say_hello()
Configuration
The Flask App could be configure before the init_app
of Flask-Pypendency, with the following parameteres:
PYPENDENCY_DI_FOLDER_NAME
Specify the name of the folder containing the definitions of services, it should be the same across all the app (if more than one path is defined).
Default:
_dependency_injection
PYPENDENCY_DISCOVER_PATHS
Iterable of absolute paths where to search for definitions of services
Default: Flask's app root path
Examples
The file test/test_flask_pypendency.py
has a end-to-end test that shows how the extension could
be used on a real Flask app.
Contributing / Running project locally
Build the docker image:
docker build . -t flask-pypendency-dev
Run tests:
docker run -v $(pwd)/.:/usr/src/app flask-pypendency-dev bash -c "pipenv run make run-tests"
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for Flask_Pypendency-0.1b0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0b09de7c086bb61deb04400e9532d8a43575ecb330f678ab3fafc574375150f5 |
|
MD5 | fca7d041728071faccf849988fbd6079 |
|
BLAKE2b-256 | 3bb553aba013fc103e83fa62f162ab0d88fc583b2d004c733cbf919550983fb9 |