{"id":9616,"library":"commoncode","title":"commoncode Utilities","description":"commoncode is a collection of essential utilities for Python, originally split from the ScanCode project. It provides robust tools for file system operations, hashing, system information, command execution, and more. It is actively maintained with frequent minor releases to support new Python versions and address bug fixes. The current version is 32.4.2.","status":"active","version":"32.4.2","language":"en","source_language":"en","source_url":"https://github.com/aboutcode-org/commoncode","tags":["utilities","filesystem","hashing","system-info","cli"],"install":[{"cmd":"pip install commoncode","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Requires Python 3.10 or newer.","package":"python","optional":false}],"imports":[{"note":"Import specific functions directly for clarity and efficiency.","wrong":"import commoncode.fileutils.file_sha1","symbol":"file_sha1","correct":"from commoncode.fileutils import file_sha1"},{"symbol":"get_system_info","correct":"from commoncode.system import get_system_info"},{"symbol":"execute","correct":"from commoncode.command import execute"}],"quickstart":{"code":"import os\nfrom pathlib import Path\nfrom commoncode.fileutils import file_sha1\n\n# Create a dummy file for demonstration\ndummy_file_path = Path('dummy_file.txt')\nwith open(dummy_file_path, 'w') as f:\n    f.write('Hello, commoncode!\\n')\n    f.write('This is a test file.\\n')\n\ntry:\n    # Get SHA1 checksum of the file\n    sha1_checksum = file_sha1(str(dummy_file_path))\n    print(f\"SHA1 of '{dummy_file_path}': {sha1_checksum}\")\n\n    # Get system information\n    from commoncode.system import get_system_info\n    system_info = get_system_info()\n    print(f\"Python Version: {system_info.get('python_version')}\")\n    print(f\"OS Release: {system_info.get('os_release_id')}\")\n\nfinally:\n    # Clean up the dummy file\n    if dummy_file_path.exists():\n        os.remove(dummy_file_path)\n","lang":"python","description":"This quickstart demonstrates how to use `commoncode.fileutils.file_sha1` to compute a file's SHA1 checksum and `commoncode.system.get_system_info` to retrieve basic system details. It creates a temporary file and cleans it up afterward."},"warnings":[{"fix":"Upgrade your Python environment to 3.10 or newer, or pin commoncode to an older version (<32.4.0) if you must use Python 3.9.","message":"commoncode dropped support for Python 3.9 in version 32.4.0. Using commoncode 32.4.0 or newer with Python 3.9 will lead to installation errors or runtime issues.","severity":"breaking","affected_versions":">=32.4.0"},{"fix":"Upgrade commoncode to version 32.3.0 or newer to ensure compatibility with recent 'click' versions. (Fixed in 32.3.0, further fixes in 32.4.0).","message":"Versions of commoncode prior to 32.3.0 had compatibility issues with 'click' version 8.1.3 and newer, potentially causing errors in CLI applications that use commoncode.","severity":"breaking","affected_versions":"<32.3.0"},{"fix":"Upgrade to commoncode 32.4.0 or newer to ensure robust handling of non-UTF-8 paths. For older versions, ensure all paths are UTF-8 compliant.","message":"Paths containing non-UTF-8 bytes were not handled correctly in versions prior to 32.4.0, potentially leading to errors when processing file paths with unusual characters.","severity":"gotcha","affected_versions":"<32.4.0"},{"fix":"Upgrade commoncode to version 32.2.0 or newer to ensure compatibility with `bs4` 4.13+ when using `as_unicode`.","message":"Version 32.2.0 introduced adjustments to the `as_unicode` function due to breaking changes in `bs4` (BeautifulSoup4) version 4.13. If you rely on `as_unicode` and use an older `commoncode` with `bs4>=4.13`, you may encounter errors.","severity":"breaking","affected_versions":"<32.2.0"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"Ensure you are using a commoncode version compatible with Python 3.12+. commoncode 32.4.1 (and newer) includes updates for Python 3.14 (and implicitly 3.12/3.13).","cause":"Using commoncode with Python 3.12 or newer, which removed the `distutils` package.","error":"ModuleNotFoundError: No module named 'distutils.version'"},{"fix":"Upgrade commoncode to version 32.3.0 or higher: `pip install --upgrade commoncode`.","cause":"Using an older commoncode version (<32.3.0) with a newer 'click' library (8.1.3+) due to API changes in 'click'.","error":"TypeError: 'Argument' object is not callable"},{"fix":"Upgrade to commoncode 32.4.0 or newer: `pip install --upgrade commoncode`. This version includes fixes for handling non-UTF-8 byte paths.","cause":"Attempting to process file paths containing characters that cannot be encoded with the default system encoding (or UTF-8) with commoncode versions prior to 32.4.0.","error":"UnicodeEncodeError: 'utf-8' codec can't encode character..."}]}