{"id":9577,"library":"cfl-common","title":"CFL Common Utilities","description":"cfl-common is a Python library providing a collection of common utilities, models, and helper functions used across various CFL (Cloud First Labs) projects. It aims to standardize common patterns for logging, configuration, data handling, and API interactions. The current version is 8.10.0, with a relatively frequent release cadence, often introducing minor improvements and occasionally breaking changes for better alignment with standard libraries.","status":"active","version":"8.10.0","language":"en","source_language":"en","source_url":"https://github.com/CFL-Team/cfl-common","tags":["utilities","logging","configuration","models","data-management","api-client"],"install":[{"cmd":"pip install cfl-common","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Environment variable loading","package":"python-dotenv"},{"reason":"HTTP client functionality","package":"requests"},{"reason":"Data validation and settings management","package":"pydantic"},{"reason":"JWT token handling","package":"PyJWT"},{"reason":"Rich terminal output and logging formatting","package":"rich"},{"reason":"Cryptographic operations, often for security utilities","package":"cryptography"},{"reason":"Integration with Google Cloud Storage","package":"google-cloud-storage","optional":true},{"reason":"MongoDB database interaction","package":"pymongo","optional":true},{"reason":"SQL database ORM","package":"sqlalchemy","optional":true},{"reason":"PostgreSQL adapter for SQLAlchemy","package":"psycopg2-binary","optional":true}],"imports":[{"note":"The PyPI package is 'cfl-common', but the internal module name is 'cfl'.","wrong":"import cfl_common","symbol":"cfl","correct":"import cfl"},{"symbol":"init_config, get_config_value","correct":"from cfl.config import init_config, get_config_value"},{"symbol":"get_logger","correct":"from cfl.logger import get_logger"},{"symbol":"sanitize_filename","correct":"from cfl.common.utils import sanitize_filename"}],"quickstart":{"code":"import os\nfrom cfl.logger import get_logger\nfrom cfl.config import init_config, get_config_value\nfrom cfl.common.utils import sanitize_filename\n\n# Initialize a logger\nlogger = get_logger(\"my_app\")\nlogger.info(\"Application started.\")\n\n# Initialize configuration (e.g., from .env or a dictionary)\n# For a real application, you might load from a file or environment variables\nconfig_dict = {\n    \"APP_NAME\": \"MyCFLApp\",\n    \"API_KEY\": os.environ.get(\"CFL_API_KEY\", \"default-api-key-for-dev\")\n}\ninit_config(config_dict=config_dict)\n\napp_name = get_config_value(\"APP_NAME\")\napi_key = get_config_value(\"API_KEY\")\n\nlogger.info(f\"App Name from config: {app_name}\")\nlogger.debug(f\"API Key (for debug, not production logs): {api_key[:5]}...\")\nlogger.warning(f\"Sanitized filename example: {sanitize_filename('My File-1.0.txt')}\")\nlogger.info(\"Application finished.\")","lang":"python","description":"This quickstart demonstrates initializing the logger, configuring application settings using a dictionary (which can also be loaded from environment variables or .env files), and using a common utility function. It shows how to access configured values and basic logging practices."},"warnings":[{"fix":"Migrate your code to use Python's built-in `json`, `datetime`, `re`, and `urllib.parse` modules directly. For example, replace `cfl.common.utils.json_load` with `json.loads`.","message":"Several utility functions that duplicated Python's standard library functionality (e.g., `json`, `datetime`, `re`, `urllib.parse`) were removed from `cfl.common.utils`.","severity":"breaking","affected_versions":"7.0.0, 8.0.0 and later"},{"fix":"Always use `import cfl` or `from cfl import ...` instead of `import cfl_common` when importing the library in your Python code.","message":"The PyPI package name is `cfl-common`, but the top-level import name for the library is `cfl`.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"Change your import statements from `import cfl_common` to `import cfl` or `from cfl import ...`.","cause":"Attempting to import the library using its PyPI package name (`cfl_common`) instead of its internal module name (`cfl`).","error":"ModuleNotFoundError: No module named 'cfl_common'"},{"fix":"Replace calls like `cfl.common.utils.json_load(data)` with `json.loads(data)` from the Python standard library's `json` module.","cause":"Using a deprecated JSON utility function (e.g., `json_load`, `json_dump`) that was removed in version 8.0.0 to promote standard library usage.","error":"AttributeError: module 'cfl.common.utils' has no attribute 'json_load'"},{"fix":"Replace calls like `cfl.common.utils.get_current_utc_datetime()` with `datetime.datetime.now(datetime.timezone.utc)` from the Python standard library's `datetime` module.","cause":"Using a deprecated datetime utility function (e.g., `get_current_utc_datetime`) that was removed in version 8.0.0.","error":"AttributeError: module 'cfl.common.utils' has no attribute 'get_current_utc_datetime'"}]}