{"id":4003,"library":"filesplit","title":"filesplit Python Library","description":"filesplit is a Python module designed for splitting large files into smaller, manageable chunks and subsequently merging them back together. It supports splitting by size, number of chunks, or number of lines, and works with both text and binary files. The current version is 4.1.0, and it maintains an active, somewhat regular release cadence for minor improvements and bug fixes, with major versions introducing breaking changes.","status":"active","version":"4.1.0","language":"en","source_language":"en","source_url":"https://github.com/ram-jayapalan/filesplit","tags":["file-processing","file-split","file-merge","utility"],"install":[{"cmd":"pip install filesplit","lang":"bash","label":"Install stable version"}],"dependencies":[],"imports":[{"note":"The primary class 'Filesplit' is located within the 'filesplit.split' submodule, not directly under 'filesplit'.","wrong":"from filesplit import Filesplit","symbol":"Filesplit","correct":"from filesplit.split import Filesplit"},{"note":"The 'merge_files' function is found in the 'filesplit.merge' submodule, distinct from the 'split' submodule.","wrong":"from filesplit.split import merge_files","symbol":"merge_files","correct":"from filesplit.merge import merge_files"}],"quickstart":{"code":"import os\nfrom filesplit.split import Filesplit\nfrom filesplit.merge import merge_files\n\n# Create a dummy file for splitting\ndummy_content = \"This is a test file for filesplit.\\n\" * 50\ninput_file = \"my_large_file.txt\"\noutput_dir = \"output_chunks\"\nmerged_file = \"my_merged_file.txt\"\n\nwith open(input_file, \"w\") as f:\n    f.write(dummy_content)\n\nprint(f\"Created dummy file: {input_file}\")\n\n# Initialize Filesplit\nfs = Filesplit()\n\n# --- Split the file by size (e.g., 100 bytes per chunk) ---\nos.makedirs(output_dir, exist_ok=True)\nprint(f\"Splitting '{input_file}' into '{output_dir}' by size...\")\nfs.split_by_size(\n    file=input_file,\n    size=100,\n    output_dir=output_dir\n)\nprint(\"Splitting complete.\")\n\n# --- Merge the files back ---\nprint(f\"Merging files from '{output_dir}' back into '{merged_file}'...\")\nmerge_files(\n    input_dir=output_dir,\n    output_file=merged_file\n)\nprint(\"Merging complete.\")\n\n# --- Clean up ---\nimport shutil\nif os.path.exists(input_file): os.remove(input_file)\nif os.path.exists(merged_file): os.remove(merged_file)\nif os.path.exists(output_dir): shutil.rmtree(output_dir)\n\nprint(\"Cleanup complete.\")","lang":"python","description":"This quickstart demonstrates how to create a dummy file, split it into smaller chunks using `Filesplit.split_by_size`, and then merge those chunks back into a single file using `merge_files`. It includes cleanup of all generated files and directories."},"warnings":[{"fix":"Update method calls from generic `split()` or `split_by_encoding()` to `fs.split_by_size()`, `fs.split_by_chunks()`, or `fs.split_by_lines()` depending on your splitting criteria. Refer to the official documentation for the updated method signatures.","message":"Version 4.0.0 introduced significant breaking changes by renaming primary splitting methods. For instance, the generic `split()` method and specific `split_by_encoding()` were replaced with more explicit names like `split_by_size()`, `split_by_chunks()`, and `split_by_lines()`.","severity":"breaking","affected_versions":">=4.0.0"},{"fix":"Ensure you are importing and instantiating `Filesplit` (capital F) instead of `FileSplit`. If using `splitbyencoding()`, refactor to use the `split()` method (for v3.x) or the more specific `split_by_...` methods (for v4.x and above).","message":"Version 3.0.0 changed the primary class name from `FileSplit` to `Filesplit` (case change) and removed the `splitbyencoding()` method, integrating its functionality into the `split()` method (which itself was later refactored in v4.0.0).","severity":"breaking","affected_versions":">=3.0.0, <4.0.0"},{"fix":"Ensure your project is running on Python 3.x. The library supports Python versions 3.0 to 3.11.","message":"The library explicitly requires Python 3. Versions prior to 2.0.0 supported Python 2, but all subsequent versions dropped Python 2 compatibility.","severity":"gotcha","affected_versions":">=2.0.0"},{"fix":"Before calling a split method, use `os.makedirs(output_dir, exist_ok=True)` to ensure the target directory for split files exists.","message":"When splitting files, ensure the `output_dir` provided to `split_by_size`, `split_by_chunks`, or `split_by_lines` either exists or is created by your script. The library does not automatically create the output directory.","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}