The Flask Variable Manager is a Flask extension that allows you to manage variables within your Flask application.
It provides an interface to set and get variables, and even render them in Jinja2 templates.
This can be useful when you need to share data across different parts of your application.
To install the Flask Variable Manager, you can use pip:
pip install flask-variable-manager
First, import the VariableManagerExtension
from the flask_variable_manager
package:
Then, create an instance of the VariableManagerExtension
and initialize it with your Flask application:
from flask import Flask
from flask_variable_manager import VariableManagerExtension
vm = VariableManagerExtension()
app = Flask(__name__)
vm.init_app(app)
Now, you can use the VariableManagerExtension
to set and get variables in your Flask routes.
vm._local['my_var'] = 'Hello, World!'
vm._local['my_var']
This route allows you to render a string as a Jinja2 template.
It accepts a POST request at the /vm/render
endpoint.
This route allows you to set a user-defined variable.
It accepts a POST request at the /vm/var
endpoint.
This route allows you to get all user-defined variables.
It accepts a GET request at the /vm/var
endpoint.
(or vm/vars
for the multiple count of the variable)
This route allows you to remove a user-defined variable.
It accepts a DELETE request at the /vm/var
endpoint.
(or vm/vars
for the multiple count of the variable)
This route allows you to run a Python script and return the result.
It accepts a POST request at the /py/runner
endpoint.
import platform
from flask import g
data = additionalProp + "-" + platform.platform()
g.local['saved_user_variable'] = data
return data
This route allows you to check the list of python packages.
It accepts a GET request at the /py/packages
endpoint.
This route allows you to install and uninstall a python package.
It accepts a POST request at the /py/install
, /py/uninstall
endpoint.
This project is licensed under the terms of the MIT license.
Contributions are welcome! Please feel free to submit a Pull Request.