{"id":514,"library":"identify","title":"Identify","description":"Identify is a Python library primarily used for file identification. It processes files (or file metadata) and returns a set of standardized tags describing their type, executability, language (from shebangs), and more. Maintained by the pre-commit team, it is actively developed with a focus on robust file analysis heuristics. The current version is 2.6.18, and releases typically align with pre-commit's development cycle or as issues require attention.","status":"active","version":"2.6.18","language":"python","source_language":"en","source_url":"https://github.com/pre-commit/identify","tags":["file identification","pre-commit","file tags","language detection","license detection"],"install":[{"cmd":"pip install identify","lang":"bash","label":"Install with pip"}],"dependencies":[],"imports":[{"symbol":"tags_from_path","correct":"from identify import tags_from_path"}],"quickstart":{"code":"import os\nfrom identify import tags_from_path\n\n# Create a dummy Python file\npython_file_content = \"#!/usr/bin/env python\\nprint('Hello, world!')\\n\"\npython_file_path = \"temp_script.py\"\nwith open(python_file_path, \"w\") as f:\n    f.write(python_file_content)\n\n# Get tags for the dummy Python file\npython_tags = tags_from_path(python_file_path)\nprint(f\"Tags for '{python_file_path}': {python_tags}\")\n\n# Create a dummy text file\ntext_file_content = \"This is a simple text file.\"\ntext_file_path = \"temp_text.txt\"\nwith open(text_file_path, \"w\") as f:\n    f.write(text_file_content)\n\n# Get tags for the dummy text file\ntext_tags = tags_from_path(text_file_path)\nprint(f\"Tags for '{text_file_path}': {text_tags}\")\n\n# Demonstrate with a non-existent path (will return an empty set)\nnon_existent_tags = tags_from_path(\"non_existent_file.xyz\")\nprint(f\"Tags for 'non_existent_file.xyz': {non_existent_tags}\")\n\n# Clean up the dummy files\nos.remove(python_file_path)\nos.remove(text_file_path)\n","lang":"python","description":"This example demonstrates how to use `tags_from_path` to identify a Python script and a plain text file, and also shows the result for a non-existent file path. It creates temporary files and cleans them up."},"warnings":[{"fix":"Understand the library's identification process as documented on its GitHub page. For critical identification, consider complementing `identify` with more specialized tools if needed.","message":"The library identifies files based on a specific heuristic: first by file type, then executable bit, then file extension, then by peeking at file content bytes, and finally by interpreting shebangs. Users should be aware that it might not perform deep content analysis beyond these steps, potentially leading to unexpected tags if relying solely on ambiguous extensions or complex file formats.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Do not treat `identify`'s license tags as legal advice or a substitute for thorough manual review. Use it as an initial indicator, and verify licenses manually, especially for open-source compliance or distribution.","message":"While `identify` includes an API for license determination, its approach (e.g., stripping copyright lines, normalizing whitespace) suggests it is a heuristic-based identification, not a definitive legal or cryptographic analysis. It may have limitations with highly customized licenses, incomplete files, or non-standard formatting.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Review the `identify` library's documentation and changelog to confirm the correct function name and import path for your installed version. Ensure your `identify` version is compatible with the code expecting `tags_from_path`. Consider upgrading `identify` to a version that includes this API, or adjusting your import statement and code to match the available API of your current `identify` installation.","message":"The `identify` library raises an `ImportError` because the name `tags_from_path` cannot be imported. This indicates that the function is not directly available or does not exist in the installed version of the `identify` library, likely due to an API change, a specific version where it's not exposed, or an older version of the library being used.","severity":"breaking","affected_versions":"Versions of `identify` where `tags_from_path` is not directly exposed or does not exist in the top-level module (e.g., older versions before its introduction or specific versions after its removal/renaming)."},{"fix":"Review the `identify` library's documentation and changelog for the installed version to ascertain the correct import path or replacement function for `tags_from_path`. Modify the import statement accordingly or install a compatible version of the library.","message":"The `identify` library raises an `ImportError` for `tags_from_path`. This indicates a significant API change where `tags_from_path` is either not directly exposed from the top-level `identify` package, has been renamed, or removed in the installed version, preventing basic usage.","severity":"breaking","affected_versions":"Specific versions where `tags_from_path` is not available as a direct import from `identify`."}],"env_vars":null,"last_verified":"2026-05-12T14:32:26.315Z","next_check":"2026-06-26T00:00:00.000Z","problems":[{"fix":"Install the library using pip: `pip install identify`","cause":"The `identify` library has not been installed in your Python environment or the Python interpreter cannot locate it in its search paths. [1, 2, 3, 4, 9, 11]","error":"ModuleNotFoundError: No module named 'identify'"},{"fix":"Activate your virtual environment before running git commands, or ensure `pre-commit` is installed globally or accessible in your shell's PATH. If not installed, run `pip install pre-commit` and `pre-commit install` in your repository. [8, 14]","cause":"When using `identify` as a `pre-commit` hook, the `pre-commit` executable itself is not found in the system's PATH, often because a virtual environment where `pre-commit` is installed is not active. [8, 14, 18, 19]","error":"pre-commit: command not found. Did you forget to activate your virtualenv?"},{"fix":"Access the `tags` property (which returns a frozenset of tags) instead of a singular 'tag' attribute: `file_obj.tags`","cause":"You are attempting to access a non-existent attribute named 'tag' on the `File` object returned by `identify_file`. The correct attribute to get all tags is `tags` (a frozenset), not `tag`. [13, 16]","error":"AttributeError: 'File' object has no attribute 'tag'"},{"fix":"Iterate over the `frozenset` of tags and apply string methods to each individual tag: `for tag in file_obj.tags: if tag.startswith('text'): ...`","cause":"After obtaining the `tags` (a frozenset of strings) from a `File` object, you are attempting to call a string method like `startswith()` directly on the frozenset object itself, rather than on individual tags within it. [13, 16]","error":"AttributeError: 'frozenset' object has no attribute 'startswith'"},{"fix":"Provide the path to the file as an argument when calling `identify_file`: `from identify import identify_file; identify_file('your_file.py')`","cause":"The `identify_file` function was called without providing the `path` argument, which is a required parameter for the function to know which file to analyze. [20, 22, 25, 29]","error":"TypeError: identify_file() missing 1 required positional argument: 'path'"}],"ecosystem":"pypi","meta_description":null,"install_score":0,"install_tag":"stale","quickstart_score":0,"quickstart_tag":"stale","pypi_latest":null,"install_checks":{"last_tested":"2026-05-12","tag":"stale","tag_description":"widespread failures or data too old to trust","results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null}]},"quickstart_checks":{"last_tested":"2026-04-23","tag":"stale","tag_description":"widespread failures or data too old to trust","results":[{"runtime":"python:3.10-alpine","exit_code":1},{"runtime":"python:3.10-slim","exit_code":1},{"runtime":"python:3.11-alpine","exit_code":1},{"runtime":"python:3.11-slim","exit_code":1},{"runtime":"python:3.12-alpine","exit_code":1},{"runtime":"python:3.12-slim","exit_code":1},{"runtime":"python:3.13-alpine","exit_code":1},{"runtime":"python:3.13-slim","exit_code":1},{"runtime":"python:3.9-alpine","exit_code":1},{"runtime":"python:3.9-slim","exit_code":1}]}}