function create_app
Factory function that creates and configures a Flask application instance for a controlled document management system.
/tf/active/vicechatdev/CDocs/main_flask.py
3884 - 3886
simple
Purpose
This function serves as the application factory pattern entry point for creating a Flask web application. It instantiates a ControlledDocumentFlaskApp object with an optional configuration path and returns the configured Flask app instance. This pattern allows for flexible application initialization with different configurations (e.g., development, testing, production) and is commonly used as the entry point for WSGI servers like Gunicorn or uWSGI.
Source Code
def create_app(config_path=None):
"""Create and configure the Flask application."""
return ControlledDocumentFlaskApp(config_path).get_app()
Parameters
| Name | Type | Default | Kind |
|---|---|---|---|
config_path |
- | None | positional_or_keyword |
Parameter Details
config_path: Optional path to a configuration file. If None, the application will use default configuration settings. Can be a string path or Path object pointing to a configuration file (likely JSON or Python config file). This allows different configurations for different deployment environments.
Return Value
Returns a configured Flask application instance (Flask object) ready to be run or passed to a WSGI server. The Flask app includes all routes, blueprints, extensions (like Flask-Login), database connections, authentication mechanisms (Azure SSO), and middleware configured by the ControlledDocumentFlaskApp class.
Dependencies
flaskflask-loginwerkzeugpathlibtypinguuidloggingargparsejsontracebackdatetime
Required Imports
from CDocs.app import create_app
Usage Example
# Basic usage with default configuration
from CDocs.app import create_app
app = create_app()
if __name__ == '__main__':
app.run(debug=True, host='0.0.0.0', port=5000)
# Usage with custom configuration
app = create_app(config_path='/path/to/config.json')
# Usage with WSGI server (Gunicorn)
# gunicorn 'CDocs.app:create_app()' --bind 0.0.0.0:8000
# Usage for testing
import pytest
@pytest.fixture
def app():
app = create_app(config_path='tests/test_config.json')
app.config['TESTING'] = True
return app
@pytest.fixture
def client(app):
return app.test_client()
Best Practices
- Use different configuration files for different environments (development, staging, production)
- Never commit sensitive configuration data (passwords, API keys) to version control
- When deploying with WSGI servers, use the factory pattern: gunicorn 'module:create_app()'
- For testing, create separate test configurations with isolated databases
- Ensure all required environment variables and configuration files are present before calling this function
- The function returns a Flask app instance but does not start the server - use app.run() for development or a WSGI server for production
- Consider using environment-specific config files: create_app('config/production.json') vs create_app('config/development.json')
- The ControlledDocumentFlaskApp class handles all the complex setup, so this function should remain simple and focused on instantiation
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
class ControlledDocumentFlaskApp 73.4% similar
-
function create_training_management 58.5% similar
-
function create_training_dashboard 58.1% similar
-
function create_document_v6 58.1% similar
-
function register_docchat 57.6% similar