Before you begin the integration process, make sure you have the following:
- API Access Token: To authenticate your Flask application with CommandK, you'll need an API access token. If you haven't obtained one yet, refer to this link for instructions on how to acquire it.
Follow these steps to integrate CommandK with your Flask application:
If you haven't already created a Flask application, you can set up a new project using a preferred method. Here, we'll create a simple Flask application for demonstration:
Create a directory for your Flask application:
mkdir my_flask_app cd my_flask_app
pip install Flask
Create a Python file for your Flask application, e.g.,
app.py, and add a basic Flask app:
from flask import Flask app = Flask(__name__) @app.route('/') def hello_world(): return 'Hello, Flask!' if __name__ == '__main__': app.run()
Inside your Flask application, you can access secrets as environment variables. Open the appropriate file (e.g.,
app.py) and add the following code snippet to access an environment variable:
import os from dotenv import load_dotenv load_dotenv() SECRET_KEY = os.getenv('FLASK_SECRET_KEY')
This code uses the
dotenv library to load environment variables and sets the Flask secret key as an example.
To run your Flask application with the CommandK CLI, you can use the following command:
$ cmdk run <application-name> --environment development -- python app.py
<application-name> with the actual name of your Flask application. This command will execute your Flask application, running it with the Python interpreter.
By following these instructions, you can seamlessly integrate the CommandK CLI with your Flask application, making it easy to manage secrets and run your application securely.
Updated about 2 months ago