{"id":5929,"library":"filehash","title":"Filehash","description":"Python module and command-line tool that wraps around `hashlib` and `zlib` to facilitate generating checksums/hashes of files and directories. It supports various algorithms like MD5, SHA-*, Adler-32, and CRC32, handling large files efficiently by processing them in chunks. The current version is 0.2.dev1 and it appears to be in active development based on the versioning.","status":"active","version":"0.2.dev1","language":"en","source_language":"en","source_url":"https://github.com/leonidessaguisagjr/filehash","tags":["hashing","checksum","file integrity","security","utility","hashlib","zlib"],"install":[{"cmd":"pip install filehash","lang":"bash","label":"Install with pip"}],"dependencies":[],"imports":[{"symbol":"FileHash","correct":"from filehash import FileHash"}],"quickstart":{"code":"import os\nimport tempfile\nfrom filehash import FileHash\n\n# Create a temporary file for demonstration\nwith tempfile.NamedTemporaryFile(mode='w', delete=False, encoding='utf-8') as temp_file:\n    temp_file.write('This is a temporary file for hashing demonstration.')\n    temp_file.write('\\nAnother line of content.')\n    temp_file_path = temp_file.name\n\ntry:\n    # Initialize FileHash with a desired algorithm (defaults to 'sha256')\n    file_hasher = FileHash('sha256')\n\n    # Calculate the hash of the temporary file\n    file_hash = file_hasher.hash_file(temp_file_path)\n    print(f\"SHA256 hash of '{os.path.basename(temp_file_path)}': {file_hash}\")\n\n    # You can also specify other algorithms, e.g., MD5\n    file_hasher_md5 = FileHash('md5')\n    md5_hash = file_hasher_md5.hash_file(temp_file_path)\n    print(f\"MD5 hash of '{os.path.basename(temp_file_path)}': {md5_hash}\")\n\n    # Example of hashing a directory (requires creating dummy directory and files)\n    # For this quickstart, we'll keep it to single file hash.\n\nexcept Exception as e:\n    print(f\"An error occurred: {e}\")\nfinally:\n    # Clean up the temporary file\n    if os.path.exists(temp_file_path):\n        os.remove(temp_file_path)","lang":"python","description":"This quickstart demonstrates how to initialize the `FileHash` class and calculate the hash of a single file using different algorithms like SHA256 and MD5. It creates a temporary file for a runnable example and cleans it up afterwards. The `FileHash` constructor also accepts an optional `chunk_size` parameter for fine-tuning performance with very large files."},"warnings":[{"fix":"Prefer stronger cryptographic hash algorithms like SHA-256, SHA-512, or BLAKE2* for integrity checks in security-sensitive contexts.","message":"MD5 and SHA-1 algorithms are supported by `filehash` but are cryptographically weak and should be avoided for new security-sensitive applications. They are susceptible to collision attacks.","severity":"deprecated","affected_versions":"All versions"},{"fix":"Ensure your Python environment is 3.6 or newer when utilizing BLAKE2* algorithms. Otherwise, select a different hash algorithm compatible with your Python version.","message":"The BLAKE2b and BLAKE2s algorithms are only supported on Python 3.6.x and later. Attempting to use them on older Python versions will result in an error due to underlying `hashlib` limitations.","severity":"gotcha","affected_versions":"<3.6.x"},{"fix":"Adjust `chunk_size` in `FileHash(chunk_size=desired_bytes)` for optimized performance or memory usage, especially with multi-gigabyte files.","message":"The `filehash` library is designed to efficiently handle large files by reading them in chunks. While a default `chunk_size` is used, for extremely large files or specific performance requirements, you might need to manually adjust the `chunk_size` parameter in the `FileHash` constructor.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-14T00:00:00.000Z","next_check":"2026-07-13T00:00:00.000Z"}