🔍 Code Extractor

function create_app

Maturity: 36

Factory function that creates and configures a Flask application instance for a controlled document management system.

File:
/tf/active/vicechatdev/CDocs/main_flask.py
Lines:
3884 - 3886
Complexity:
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

  • flask
  • flask-login
  • werkzeug
  • pathlib
  • typing
  • uuid
  • logging
  • argparse
  • json
  • traceback
  • datetime

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

Similar Components

AI-powered semantic similarity - components with related functionality:

  • class ControlledDocumentFlaskApp 73.4% similar

    Main Flask application class for Controlled Document Management System.

    From: /tf/active/vicechatdev/CDocs/main_flask.py
  • function create_training_management 58.5% similar

    Factory function that instantiates and returns a TrainingManagement object with optional parent application and document UID parameters.

    From: /tf/active/vicechatdev/CDocs/ui/training_management.py
  • function create_training_dashboard 58.1% similar

    Factory function that creates and initializes a TrainingDashboard instance with optional user context from a parent application.

    From: /tf/active/vicechatdev/CDocs/ui/training_dashboard.py
  • function create_document_v6 58.1% similar

    Creates a new ComplexDocument instance with a unique UUID, stores it in application state with thread-safe locking, persists it to file, and logs the creation.

    From: /tf/active/vicechatdev/vice_ai/complex_app.py
  • function register_docchat 57.6% similar

    Registers a DocChat Flask blueprint with a Flask application instance, handling path configuration and error logging.

    From: /tf/active/vicechatdev/docchat/integration.py
← Back to Browse